forked from ebsco/backbone-query-parameters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backbone.queryparams-1.1-shim.js
64 lines (55 loc) · 2.47 KB
/
backbone.queryparams-1.1-shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Works around issue introduced in Backbone 1.1 by https://github.com/jashkenas/backbone/pull/2766
//
// This file is unnecessary under Backbone 1.0 and earlier.
//
// Note that https://github.com/jashkenas/backbone/pull/2890 should hopefully make this irrevelant
//
(function (root, factory) {
if (typeof exports === 'object' && root.require) {
module.exports = factory(require("underscore"), require("backbone"));
} else if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["underscore", "backbone"], function (_, Backbone) {
// Use global variables if the locals are undefined.
return factory(_ || root._, Backbone || root.Backbone);
});
} else {
// RequireJS isn't being used. Assume underscore and backbone are loaded in <script> tags
factory(_, Backbone);
}
}(this, function (_, Backbone) {
Backbone.History.prototype.navigate = function (fragment, options) {
/*jshint curly:false */
if (!Backbone.History.started) return false;
if (!options || options === true) options = { trigger: !!options };
var url = this.root + (fragment = this.getFragment(fragment || ''));
// Removed from the upstream impl:
// Strip the fragment of the query and hash for matching.
// fragment = fragment.replace(pathStripper, '');
if (this.fragment === fragment) return;
this.fragment = fragment;
// Don't include a trailing slash on the root.
if (fragment === '' && url !== '/') url = url.slice(0, -1);
// If pushState is available, we use it to set the fragment as a real URL.
if (this._hasPushState) {
this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
// If hash changes haven't been explicitly disabled, update the hash
// fragment to store history.
} else if (this._wantsHashChange) {
this._updateHash(this.location, fragment, options.replace);
if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) {
// Opening and closing the iframe tricks IE7 and earlier to push a
// history entry on hash-tag change. When replace is true, we don't
// want this.
if (!options.replace) this.iframe.document.open().close();
this._updateHash(this.iframe.location, fragment, options.replace);
}
// If you've told us that you explicitly don't want fallback hashchange-
// based history, then `navigate` becomes a page refresh.
} else {
return this.location.assign(url);
}
if (options.trigger) return this.loadUrl(fragment);
};
}));