mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Update vendors.
Former-commit-id: ad3284b1e77cfb0b17af99e0ddaf00618e4485b7
This commit is contained in:
32
vendor/backbone/backbone.js
vendored
32
vendor/backbone/backbone.js
vendored
@@ -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.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow;
|
||||
@@ -1040,13 +1048,13 @@
|
||||
// opened by a non-pushState browser.
|
||||
this.fragment = fragment;
|
||||
var loc = this.location;
|
||||
var atRoot = (loc.pathname.replace(/[^/]$/, '$&/') === this.options.root) && !loc.search;
|
||||
var atRoot = (loc.pathname.replace(/[^/]$/, '$&/') === this.root) && !loc.search;
|
||||
|
||||
// If we've started off with a route from a `pushState`-enabled browser,
|
||||
// but we're currently in a browser that doesn't support it...
|
||||
if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) {
|
||||
this.fragment = this.getFragment(null, true);
|
||||
this.location.replace(this.options.root + this.location.search + '#' + this.fragment);
|
||||
this.location.replace(this.root + this.location.search + '#' + this.fragment);
|
||||
// Return immediately as browser will do redirect to new url
|
||||
return true;
|
||||
|
||||
@@ -1054,7 +1062,7 @@
|
||||
// in a browser where it could be `pushState`-based instead...
|
||||
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
|
||||
this.fragment = this.getHash().replace(routeStripper, '');
|
||||
this.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
|
||||
this.history.replaceState({}, document.title, this.root + this.fragment);
|
||||
}
|
||||
|
||||
if (!this.options.silent) return this.loadUrl();
|
||||
@@ -1113,7 +1121,7 @@
|
||||
var frag = (fragment || '').replace(routeStripper, '');
|
||||
if (this.fragment === frag) return;
|
||||
this.fragment = frag;
|
||||
var url = (frag.indexOf(this.options.root) !== 0 ? this.options.root : '') + frag;
|
||||
var url = (frag.indexOf(this.root) !== 0 ? this.root : '') + frag;
|
||||
|
||||
// If pushState is available, we use it to set the fragment as a real URL.
|
||||
if (this._hasPushState) {
|
||||
@@ -1434,7 +1442,7 @@
|
||||
return child;
|
||||
};
|
||||
|
||||
// Set up inheritance for the model, collection, and view.
|
||||
// Set up inheritance for the model, collection, router, and view.
|
||||
Model.extend = Collection.extend = Router.extend = View.extend = extend;
|
||||
|
||||
// Throw an error when a URL is needed, and none is supplied.
|
||||
|
||||
86
vendor/backbone/test/router.js
vendored
86
vendor/backbone/test/router.js
vendored
@@ -344,7 +344,7 @@ $(document).ready(function() {
|
||||
history: {
|
||||
pushState: function(state, title, url) {},
|
||||
replaceState: function(state, title, url) {
|
||||
strictEqual(url, 'http://example.com/root/fragment');
|
||||
strictEqual(url, '/root/fragment');
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -365,4 +365,88 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
test("Normalize root - leading slash.", 1, function() {
|
||||
Backbone.history.stop();
|
||||
location.replace('http://example.com/root');
|
||||
Backbone.history = new Backbone.History({
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: 'root'});
|
||||
strictEqual(Backbone.history.root, '/root/');
|
||||
});
|
||||
|
||||
test("Transition from hashChange to pushState.", 1, function() {
|
||||
Backbone.history.stop();
|
||||
location.replace('http://example.com/root#x/y');
|
||||
Backbone.history = new Backbone.History({
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(state, title, url){
|
||||
strictEqual(url, '/root/x/y');
|
||||
}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({
|
||||
root: 'root',
|
||||
pushState: true
|
||||
});
|
||||
});
|
||||
|
||||
test("#1619: Router: Normalize empty root", 1, function() {
|
||||
Backbone.history.stop();
|
||||
location.replace('http://example.com/');
|
||||
Backbone.history = new Backbone.History({
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(){},
|
||||
replaceState: function(){}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({root: ''});
|
||||
strictEqual(Backbone.history.root, '/');
|
||||
});
|
||||
|
||||
test("#1619: Router: nagivate with empty root", 1, function() {
|
||||
Backbone.history.stop();
|
||||
location.replace('http://example.com/');
|
||||
Backbone.history = new Backbone.History({
|
||||
location: location,
|
||||
history: {
|
||||
pushState: function(state, title, url) {
|
||||
strictEqual(url, '/fragment');
|
||||
}
|
||||
}
|
||||
});
|
||||
Backbone.history.start({
|
||||
pushState: true,
|
||||
root: '',
|
||||
hashChange: false
|
||||
});
|
||||
Backbone.history.navigate('fragment');
|
||||
});
|
||||
|
||||
test("Transition from pushState to hashChange.", 1, function() {
|
||||
Backbone.history.stop();
|
||||
location.replace('http://example.com/root/x/y?a=b');
|
||||
location.replace = function(url) {
|
||||
strictEqual(url, '/root/?a=b#x/y');
|
||||
};
|
||||
Backbone.history = new Backbone.History({
|
||||
location: location,
|
||||
history: {
|
||||
pushState: null,
|
||||
replaceState: null
|
||||
}
|
||||
});
|
||||
Backbone.history.start({
|
||||
root: 'root',
|
||||
pushState: true
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user