[Pkg-javascript-commits] [backbone] 182/281: Fixes #803, allows you to opt-out of hashchange, while opting-in to push state, using full-page refreshes for old browsers.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:10 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9.0
in repository backbone.

commit 328cb666381536eeedd5753a630d97967d138bae
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Thu Jan 12 17:44:45 2012 -0500

    Fixes #803, allows you to opt-out of hashchange, while opting-in to push state, using full-page refreshes for old browsers.
---
 backbone.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/backbone.js b/backbone.js
index f2d2161..5728749 100644
--- a/backbone.js
+++ b/backbone.js
@@ -745,6 +745,7 @@
       // Is pushState desired ... is it available?
       if (historyStarted) throw new Error("Backbone.history has already been started");
       this.options          = _.extend({}, {root: '/'}, this.options, options);
+      this._wantsHashChange = this.options.hashChange !== false;
       this._wantsPushState  = !!this.options.pushState;
       this._hasPushState    = !!(this.options.pushState && window.history && window.history.pushState);
       var fragment          = this.getFragment();
@@ -759,9 +760,9 @@
       // 'onhashchange' is supported, determine how we check the URL state.
       if (this._hasPushState) {
         $(window).bind('popstate', this.checkUrl);
-      } else if ('onhashchange' in window && !oldIE) {
+      } else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) {
         $(window).bind('hashchange', this.checkUrl);
-      } else {
+      } else if (this._wantsHashChange) {
         setInterval(this.checkUrl, this.interval);
       }
 
@@ -771,7 +772,7 @@
       historyStarted = true;
       var loc = window.location;
       var atRoot  = loc.pathname == this.options.root;
-      if (this._wantsPushState && !this._hasPushState && !atRoot) {
+      if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) {
         this.fragment = this.getFragment(null, true);
         window.location.replace(this.options.root + '#' + this.fragment);
         // Return immediately as browser will do redirect to new url
@@ -831,7 +832,7 @@
         if (frag.indexOf(this.options.root) != 0) frag = this.options.root + frag;
         this.fragment = frag;
         window.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, frag);
-      } else {
+      } else if (this._wantsHashChange) {
         this.fragment = frag;
         this._updateHash(window.location, frag, options.replace);
         if (this.iframe && (frag != this.getFragment(this.iframe.location.hash))) {
@@ -840,6 +841,8 @@
           if(!options.replace) this.iframe.document.open().close();
           this._updateHash(this.iframe.location, frag, options.replace);
         }
+      } else {
+        window.location.assign(this.options.root + fragment);
       }
       if (options.trigger) this.loadUrl(fragment);
     },

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list