diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index cfa836155..9796cc04f 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -18,8 +18,10 @@ // restored later on, if `noConflict` is used. var previousBackbone = root.Backbone; - // Create a local reference to splice. - var splice = Array.prototype.splice; + // Create a local reference to array methods. + var ArrayProto = Array.prototype; + var slice = ArrayProto.slice; + var splice = ArrayProto.splice; // The top-level namespace. All public Backbone classes and modules will // be attached to this. Exported for both CommonJS and the browser. @@ -866,7 +868,9 @@ // Mix in each Underscore method as a proxy to `Collection#models`. _.each(methods, function(method) { Collection.prototype[method] = function() { - return _[method].apply(_, [this.models].concat(_.toArray(arguments))); + var args = slice.call(arguments); + args.unshift(this.models); + return _[method].apply(_, args); }; }); @@ -961,9 +965,12 @@ this.history = options && options.history || root.history; }; - // Cached regex for cleaning leading hashes and slashes . + // Cached regex for cleaning leading hashes and slashes. var routeStripper = /^[#\/]/; + // Cached regex for stripping leading and trailing slashes. + var rootStripper = /^\/+|\/+$/g; + // Cached regex for detecting MSIE. var isExplorer = /msie [\w.]+/; @@ -993,7 +1000,7 @@ if (fragment == null) { if (this._hasPushState || !this._wantsHashChange || forcePushState) { fragment = this.location.pathname; - var root = this.options.root.replace(trailingSlash, ''); + var root = this.root.replace(trailingSlash, ''); if (!fragment.indexOf(root)) fragment = fragment.substr(root.length); } else { fragment = this.getHash(); @@ -1011,6 +1018,7 @@ // Figure out the initial configuration. Do we need an iframe? // Is pushState desired ... is it available? this.options = _.extend({}, {root: '/'}, this.options, options); + this.root = this.options.root; this._wantsHashChange = this.options.hashChange !== false; this._wantsPushState = !!this.options.pushState; this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState); @@ -1018,8 +1026,8 @@ var docMode = document.documentMode; var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7)); - // Normalize root to always include trailing slash - if (!trailingSlash.test(this.options.root)) this.options.root += '/'; + // Normalize root to always include a leading and trailing slash. + this.root = ('/' + this.root + '/').replace(rootStripper, '/'); if (oldIE && this._wantsHashChange) { this.iframe = Backbone.$('