[Pkg-javascript-commits] [backbone] 146/211: Issue #228 ... IE7 hash should look correct after initial load.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:00:16 UTC 2014


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

js pushed a commit to tag 0.5.0
in repository backbone.

commit 489ebb70401d826419e33ab0d87f3eef74c6af15
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon May 23 10:28:42 2011 -0400

    Issue #228 ... IE7 hash should look correct after initial load.
---
 backbone.js | 52 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/backbone.js b/backbone.js
index 7ec5d48..aa11ddf 100644
--- a/backbone.js
+++ b/backbone.js
@@ -674,8 +674,8 @@
     route : function(route, name, callback) {
       Backbone.history || (Backbone.history = new Backbone.History);
       if (!_.isRegExp(route)) route = this._routeToRegExp(route);
-      Backbone.history.route(route, _.bind(function(fragment) {
-        var args = this._extractParameters(route, fragment);
+      Backbone.history.route(route, _.bind(function(hash) {
+        var args = this._extractParameters(route, hash);
         callback.apply(this, args);
         this.trigger.apply(this, ['route:' + name].concat(args));
       }, this));
@@ -683,8 +683,8 @@
 
     // Simple proxy to `Backbone.history` to save a fragment into the history,
     // without triggering routes.
-    saveLocation : function(fragment) {
-      Backbone.history.saveLocation(fragment);
+    saveLocation : function(hash) {
+      Backbone.history.saveLocation(hash);
     },
 
     // Bind all defined routes to `Backbone.history`. We have to reverse the
@@ -702,7 +702,7 @@
     },
 
     // Convert a route string into a regular expression, suitable for matching
-    // against the current location fragment.
+    // against the current location hash.
     _routeToRegExp : function(route) {
       route = route.replace(escapeRegExp, "\\$&")
                    .replace(namedParam, "([^\/]*)")
@@ -712,8 +712,8 @@
 
     // Given a route, and a URL fragment that it matches, return the array of
     // extracted parameters.
-    _extractParameters : function(route, fragment) {
-      return route.exec(fragment).slice(1);
+    _extractParameters : function(route, hash) {
+      return route.exec(hash).slice(1);
     }
 
   });
@@ -725,7 +725,6 @@
   // browser does not support `onhashchange`, falls back to polling.
   Backbone.History = function() {
     this.handlers = [];
-    this.fragment = this.getFragment();
     _.bindAll(this, 'checkUrl');
   };
 
@@ -746,7 +745,7 @@
     interval: 50,
 
     // Get the cross-browser normalized URL fragment.
-    getFragment : function(loc) {
+    getHash : function(loc) {
       return (loc || window.location).hash.replace(hashStrip, '');
     },
 
@@ -754,16 +753,19 @@
     // an existing route, and `false` otherwise.
     start : function() {
       if (historyStarted) throw new Error("Backbone.history has already been started");
+      var hash = this.getHash();
       var docMode = document.documentMode;
       var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7));
       if (oldIE) {
         this.iframe = $('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow;
+        this.saveLocation(hash);
       }
       if ('onhashchange' in window && !oldIE) {
         $(window).bind('hashchange', this.checkUrl);
       } else {
         setInterval(this.checkUrl, this.interval);
       }
+      this.hash = hash;
       historyStarted = true;
       return this.loadUrl();
     },
@@ -777,15 +779,11 @@
     // Checks the current URL to see if it has changed, and if it has,
     // calls `loadUrl`, normalizing across the hidden iframe.
     checkUrl : function() {
-      var current = this.getFragment();
-      if (current == this.fragment && this.iframe) {
-        current = this.getFragment(this.iframe.location);
-      }
-      if (current == this.fragment ||
-          current == decodeURIComponent(this.fragment)) return false;
-      if (this.iframe) {
-        window.location.hash = this.iframe.location.hash = current;
-      }
+      var hash = this.getHash();
+      if (hash == this.hash && this.iframe) hash = this.getHash(this.iframe.location);
+      if (hash == this.hash || hash == decodeURIComponent(this.hash)) return false;
+      if (this.iframe) this.saveLocation(hash);
+      this.hash = hash;
       this.loadUrl();
     },
 
@@ -793,10 +791,10 @@
     // match, returns `true`. If no defined routes matches the fragment,
     // returns `false`.
     loadUrl : function() {
-      var fragment = this.fragment = this.getFragment();
+      var hash = this.hash;
       var matched = _.any(this.handlers, function(handler) {
-        if (handler.route.test(fragment)) {
-          handler.callback(fragment);
+        if (handler.route.test(hash)) {
+          handler.callback(hash);
           return true;
         }
       });
@@ -806,13 +804,13 @@
     // Save a fragment into the hash history. You are responsible for properly
     // URL-encoding the fragment in advance. This does not trigger
     // a `hashchange` event.
-    saveLocation : function(fragment) {
-      fragment = (fragment || '').replace(hashStrip, '');
-      if (this.fragment == fragment) return;
-      window.location.hash = this.fragment = fragment;
-      if (this.iframe && (fragment != this.getFragment(this.iframe.location))) {
+    saveLocation : function(hash) {
+      hash = (hash || '').replace(hashStrip, '');
+      if (this.hash == hash) return;
+      window.location.hash = this.hash = hash;
+      if (this.iframe && (hash != this.getHash(this.iframe.location))) {
         this.iframe.document.open().close();
-        this.iframe.location.hash = fragment;
+        this.iframe.location.hash = hash;
       }
     }
 

-- 
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