From 912ade0552accdf10d5899caf1beb70656f6d523 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 24 Apr 2014 16:59:41 +0200 Subject: [PATCH] Register hashchange event more cautiously. Registering a callback for the "hashchange" event should not occur, before the $.deck plugin was used by the consumer. Otherwise it will be executed, even if there are no slides to actually operate on. --- core/deck.core.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/deck.core.js b/core/deck.core.js index a8adefe7..d499d3fc 100644 --- a/core/deck.core.js +++ b/core/deck.core.js @@ -596,6 +596,16 @@ that use the API provided by core. /* jQuery extension */ $.deck = function(method, arg) { + + $window.bind('hashchange.deck', function(event) { + if (event.originalEvent && event.originalEvent.newURL) { + goByHash(event.originalEvent.newURL); + } + else { + goByHash(window.location.hash); + } + }); + var args = Array.prototype.slice.call(arguments, 1); if (methods[method]) { return methods[method].apply(this, args); @@ -731,15 +741,6 @@ that use the API provided by core. $('html').addClass('ready'); }); - $window.bind('hashchange.deck', function(event) { - if (event.originalEvent && event.originalEvent.newURL) { - goByHash(event.originalEvent.newURL); - } - else { - goByHash(window.location.hash); - } - }); - $window.bind('load.deck', function() { if (options.preventFragmentScroll) { $container.scrollLeft(0).scrollTop(0);