From fd9cb2eaf7fce53ffdfd70433f0e9929d9c97380 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 22 Apr 2013 22:19:16 +0000 Subject: [PATCH] ajaxify.go(relative_url); - use this to navigate to a page manually --- public/config.default.json | 6 ------ public/src/ajaxify.js | 37 ++++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 public/config.default.json diff --git a/public/config.default.json b/public/config.default.json deleted file mode 100644 index b81885cda2..0000000000 --- a/public/config.default.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "socket" : { - "address" : "localhost", - "port" : "4567" - } -} \ No newline at end of file diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 5e41e6a518..364748e83c 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -1,3 +1,6 @@ +var ajaxify = {}; + + (function($) { var rootUrl = document.location.protocol + '//' + (document.location.hostname || document.location.host) + (document.location.port ? ':'+document.location.port : ''), @@ -5,7 +8,26 @@ var current_state = ''; - + ajaxify.go = function(url) { + var tpl_url = (url === '') ? 'home' : url; + + if (templates[tpl_url]) { + if (current_state != url) { + current_state = url; + + window.history.pushState({}, url, "/" + url); + content.innerHTML = templates[tpl_url]; + exec_body_scripts(content); + + + } + + return true; + } + + return false; + } + $('document').ready(function() { if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers @@ -14,19 +36,8 @@ $('a').unbind('click').bind('click', function(ev) { var url = this.href.replace(rootUrl +'/', ''); - var tpl_url = (url === '') ? 'home' : url; - if (templates[tpl_url]) { - if (current_state != url) { - current_state = url; - - window.history.pushState({}, url, "/" + url); - content.innerHTML = templates[tpl_url]; - exec_body_scripts(content); - - - } - + if (ajaxify.go(url)) { ev.preventDefault(); return false; }