From 69a8fce64a2900aae0543b181241a5ba34171518 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Mon, 5 Dec 2011 11:22:32 +0800 Subject: [PATCH] Fix double loading bug On an html load, the page was reload by the js "popstate" --- app/assets/javascripts/side_bar_history.js | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/side_bar_history.js b/app/assets/javascripts/side_bar_history.js index 64c82458..5ac212a8 100644 --- a/app/assets/javascripts/side_bar_history.js +++ b/app/assets/javascripts/side_bar_history.js @@ -1,26 +1,31 @@ -$(function () { +$(function () { $('#panel_sidebar a, #panel_main a.nav').live('click', function () { $.getScript(this.href); - history.pushState(null, document.title, this.href); - return false; + history.pushState(null, document.title, this.href); + history_edited = true; + return false; } ); - $('#panel_main a.reload').live('click', - function () { + $('#panel_main a.reload').live('click', + function () { $.getScript(this.href); - history.replaceState(null, document.title, this.href); - return false; - } + history.replaceState(null, document.title, this.href); + history_edited = true; + return false; + } ); $('.form').live('submit', function () { - $.post(this.action, $(this).serialize(), null, 'script'); - return false; + $.post(this.action, $(this).serialize(), null, 'script'); + history_edited = true; + return false; }); - $(window).bind("popstate", function () { - $.getScript(location.href); + $(window).bind("popstate", function () { + if (history_edited) { + $.getScript(location.href); + } }); }); \ No newline at end of file