From d413d3b29ae7e5722a492e23c2f1b10a3fef65e2 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 5 Jul 2013 10:59:15 -0400 Subject: [PATCH] closed #40 by removing jquery call that repetitvely bound and unbound anchors --- public/src/ajaxify.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 5e25ce5c78..060373230f 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -52,7 +52,6 @@ var ajaxify = {}; templates.load_template(function() { exec_body_scripts(content); - ajaxify.enable(); if (callback) { callback(); } @@ -67,21 +66,8 @@ var ajaxify = {}; return false; } - ajaxify.enable = function() { - $('a').unbind('click', ajaxify.onclick).bind('click', ajaxify.onclick); - } - ajaxify.onclick = function(ev) { - if (this.href == window.location.href + "#") return; - var url = this.href.replace(rootUrl +'/', ''); - if (this.target !== '') return; - - if (!ev.ctrlKey && ev.which === 1) { - if (ajaxify.go(url)) { - ev.preventDefault(); - } - } } $('document').ready(function() { @@ -89,7 +75,19 @@ var ajaxify = {}; content = content || document.getElementById('content'); - ajaxify.enable(); + // Enhancing all anchors to ajaxify... + $(document.body).on('click', 'a', function(e) { + if (this.href == window.location.href + "#") return; + var url = this.href.replace(rootUrl +'/', ''); + + if (this.target !== '') return; + + if (!e.ctrlKey && e.which === 1) { + if (ajaxify.go(url)) { + e.preventDefault(); + } + } + }); });