From 489ebb70401d826419e33ab0d87f3eef74c6af15 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 23 May 2011 10:28:42 -0400 Subject: [PATCH] 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 7ec5d484e..aa11ddf78 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 = $('