Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../js
File: backbone.js
};
[1500] Fix | Delete
case 2: return function(value) {
[1501] Fix | Delete
return base[method](this[attribute], value);
[1502] Fix | Delete
};
[1503] Fix | Delete
case 3: return function(iteratee, context) {
[1504] Fix | Delete
return base[method](this[attribute], cb(iteratee, this), context);
[1505] Fix | Delete
};
[1506] Fix | Delete
case 4: return function(iteratee, defaultVal, context) {
[1507] Fix | Delete
return base[method](this[attribute], cb(iteratee, this), defaultVal, context);
[1508] Fix | Delete
};
[1509] Fix | Delete
default: return function() {
[1510] Fix | Delete
var args = slice.call(arguments);
[1511] Fix | Delete
args.unshift(this[attribute]);
[1512] Fix | Delete
return base[method].apply(base, args);
[1513] Fix | Delete
};
[1514] Fix | Delete
}
[1515] Fix | Delete
};
[1516] Fix | Delete
[1517] Fix | Delete
var addUnderscoreMethods = function(Class, base, methods, attribute) {
[1518] Fix | Delete
_.each(methods, function(length, method) {
[1519] Fix | Delete
if (base[method]) Class.prototype[method] = addMethod(base, length, method, attribute);
[1520] Fix | Delete
});
[1521] Fix | Delete
};
[1522] Fix | Delete
[1523] Fix | Delete
// Support `collection.sortBy('attr')` and `collection.findWhere({id: 1})`.
[1524] Fix | Delete
var cb = function(iteratee, instance) {
[1525] Fix | Delete
if (_.isFunction(iteratee)) return iteratee;
[1526] Fix | Delete
if (_.isObject(iteratee) && !instance._isModel(iteratee)) return modelMatcher(iteratee);
[1527] Fix | Delete
if (_.isString(iteratee)) return function(model) { return model.get(iteratee); };
[1528] Fix | Delete
return iteratee;
[1529] Fix | Delete
};
[1530] Fix | Delete
var modelMatcher = function(attrs) {
[1531] Fix | Delete
var matcher = _.matches(attrs);
[1532] Fix | Delete
return function(model) {
[1533] Fix | Delete
return matcher(model.attributes);
[1534] Fix | Delete
};
[1535] Fix | Delete
};
[1536] Fix | Delete
[1537] Fix | Delete
// Underscore methods that we want to implement on the Collection.
[1538] Fix | Delete
// 90% of the core usefulness of Backbone Collections is actually implemented
[1539] Fix | Delete
// right here:
[1540] Fix | Delete
var collectionMethods = {forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
[1541] Fix | Delete
foldl: 0, inject: 0, reduceRight: 0, foldr: 0, find: 3, detect: 3, filter: 3,
[1542] Fix | Delete
select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
[1543] Fix | Delete
contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
[1544] Fix | Delete
head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
[1545] Fix | Delete
without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
[1546] Fix | Delete
isEmpty: 1, chain: 1, sample: 3, partition: 3, groupBy: 3, countBy: 3,
[1547] Fix | Delete
sortBy: 3, indexBy: 3, findIndex: 3, findLastIndex: 3};
[1548] Fix | Delete
[1549] Fix | Delete
[1550] Fix | Delete
// Underscore methods that we want to implement on the Model, mapped to the
[1551] Fix | Delete
// number of arguments they take.
[1552] Fix | Delete
var modelMethods = {keys: 1, values: 1, pairs: 1, invert: 1, pick: 0,
[1553] Fix | Delete
omit: 0, chain: 1, isEmpty: 1};
[1554] Fix | Delete
[1555] Fix | Delete
// Mix in each Underscore method as a proxy to `Collection#models`.
[1556] Fix | Delete
[1557] Fix | Delete
_.each([
[1558] Fix | Delete
[Collection, collectionMethods, 'models'],
[1559] Fix | Delete
[Model, modelMethods, 'attributes']
[1560] Fix | Delete
], function(config) {
[1561] Fix | Delete
var Base = config[0],
[1562] Fix | Delete
methods = config[1],
[1563] Fix | Delete
attribute = config[2];
[1564] Fix | Delete
[1565] Fix | Delete
Base.mixin = function(obj) {
[1566] Fix | Delete
var mappings = _.reduce(_.functions(obj), function(memo, name) {
[1567] Fix | Delete
memo[name] = 0;
[1568] Fix | Delete
return memo;
[1569] Fix | Delete
}, {});
[1570] Fix | Delete
addUnderscoreMethods(Base, obj, mappings, attribute);
[1571] Fix | Delete
};
[1572] Fix | Delete
[1573] Fix | Delete
addUnderscoreMethods(Base, _, methods, attribute);
[1574] Fix | Delete
});
[1575] Fix | Delete
[1576] Fix | Delete
// Backbone.sync
[1577] Fix | Delete
// -------------
[1578] Fix | Delete
[1579] Fix | Delete
// Override this function to change the manner in which Backbone persists
[1580] Fix | Delete
// models to the server. You will be passed the type of request, and the
[1581] Fix | Delete
// model in question. By default, makes a RESTful Ajax request
[1582] Fix | Delete
// to the model's `url()`. Some possible customizations could be:
[1583] Fix | Delete
//
[1584] Fix | Delete
// * Use `setTimeout` to batch rapid-fire updates into a single request.
[1585] Fix | Delete
// * Send up the models as XML instead of JSON.
[1586] Fix | Delete
// * Persist models via WebSockets instead of Ajax.
[1587] Fix | Delete
//
[1588] Fix | Delete
// Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
[1589] Fix | Delete
// as `POST`, with a `_method` parameter containing the true HTTP method,
[1590] Fix | Delete
// as well as all requests with the body as `application/x-www-form-urlencoded`
[1591] Fix | Delete
// instead of `application/json` with the model in a param named `model`.
[1592] Fix | Delete
// Useful when interfacing with server-side languages like **PHP** that make
[1593] Fix | Delete
// it difficult to read the body of `PUT` requests.
[1594] Fix | Delete
Backbone.sync = function(method, model, options) {
[1595] Fix | Delete
var type = methodMap[method];
[1596] Fix | Delete
[1597] Fix | Delete
// Default options, unless specified.
[1598] Fix | Delete
_.defaults(options || (options = {}), {
[1599] Fix | Delete
emulateHTTP: Backbone.emulateHTTP,
[1600] Fix | Delete
emulateJSON: Backbone.emulateJSON
[1601] Fix | Delete
});
[1602] Fix | Delete
[1603] Fix | Delete
// Default JSON-request options.
[1604] Fix | Delete
var params = {type: type, dataType: 'json'};
[1605] Fix | Delete
[1606] Fix | Delete
// Ensure that we have a URL.
[1607] Fix | Delete
if (!options.url) {
[1608] Fix | Delete
params.url = _.result(model, 'url') || urlError();
[1609] Fix | Delete
}
[1610] Fix | Delete
[1611] Fix | Delete
// Ensure that we have the appropriate request data.
[1612] Fix | Delete
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
[1613] Fix | Delete
params.contentType = 'application/json';
[1614] Fix | Delete
params.data = JSON.stringify(options.attrs || model.toJSON(options));
[1615] Fix | Delete
}
[1616] Fix | Delete
[1617] Fix | Delete
// For older servers, emulate JSON by encoding the request into an HTML-form.
[1618] Fix | Delete
if (options.emulateJSON) {
[1619] Fix | Delete
params.contentType = 'application/x-www-form-urlencoded';
[1620] Fix | Delete
params.data = params.data ? {model: params.data} : {};
[1621] Fix | Delete
}
[1622] Fix | Delete
[1623] Fix | Delete
// For older servers, emulate HTTP by mimicking the HTTP method with `_method`
[1624] Fix | Delete
// And an `X-HTTP-Method-Override` header.
[1625] Fix | Delete
if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
[1626] Fix | Delete
params.type = 'POST';
[1627] Fix | Delete
if (options.emulateJSON) params.data._method = type;
[1628] Fix | Delete
var beforeSend = options.beforeSend;
[1629] Fix | Delete
options.beforeSend = function(xhr) {
[1630] Fix | Delete
xhr.setRequestHeader('X-HTTP-Method-Override', type);
[1631] Fix | Delete
if (beforeSend) return beforeSend.apply(this, arguments);
[1632] Fix | Delete
};
[1633] Fix | Delete
}
[1634] Fix | Delete
[1635] Fix | Delete
// Don't process data on a non-GET request.
[1636] Fix | Delete
if (params.type !== 'GET' && !options.emulateJSON) {
[1637] Fix | Delete
params.processData = false;
[1638] Fix | Delete
}
[1639] Fix | Delete
[1640] Fix | Delete
// Pass along `textStatus` and `errorThrown` from jQuery.
[1641] Fix | Delete
var error = options.error;
[1642] Fix | Delete
options.error = function(xhr, textStatus, errorThrown) {
[1643] Fix | Delete
options.textStatus = textStatus;
[1644] Fix | Delete
options.errorThrown = errorThrown;
[1645] Fix | Delete
if (error) error.call(options.context, xhr, textStatus, errorThrown);
[1646] Fix | Delete
};
[1647] Fix | Delete
[1648] Fix | Delete
// Make the request, allowing the user to override any Ajax options.
[1649] Fix | Delete
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
[1650] Fix | Delete
model.trigger('request', model, xhr, options);
[1651] Fix | Delete
return xhr;
[1652] Fix | Delete
};
[1653] Fix | Delete
[1654] Fix | Delete
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
[1655] Fix | Delete
var methodMap = {
[1656] Fix | Delete
'create': 'POST',
[1657] Fix | Delete
'update': 'PUT',
[1658] Fix | Delete
'patch': 'PATCH',
[1659] Fix | Delete
'delete': 'DELETE',
[1660] Fix | Delete
'read': 'GET'
[1661] Fix | Delete
};
[1662] Fix | Delete
[1663] Fix | Delete
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
[1664] Fix | Delete
// Override this if you'd like to use a different library.
[1665] Fix | Delete
Backbone.ajax = function() {
[1666] Fix | Delete
return Backbone.$.ajax.apply(Backbone.$, arguments);
[1667] Fix | Delete
};
[1668] Fix | Delete
[1669] Fix | Delete
// Backbone.Router
[1670] Fix | Delete
// ---------------
[1671] Fix | Delete
[1672] Fix | Delete
// Routers map faux-URLs to actions, and fire events when routes are
[1673] Fix | Delete
// matched. Creating a new one sets its `routes` hash, if not set statically.
[1674] Fix | Delete
var Router = Backbone.Router = function(options) {
[1675] Fix | Delete
options || (options = {});
[1676] Fix | Delete
this.preinitialize.apply(this, arguments);
[1677] Fix | Delete
if (options.routes) this.routes = options.routes;
[1678] Fix | Delete
this._bindRoutes();
[1679] Fix | Delete
this.initialize.apply(this, arguments);
[1680] Fix | Delete
};
[1681] Fix | Delete
[1682] Fix | Delete
// Cached regular expressions for matching named param parts and splatted
[1683] Fix | Delete
// parts of route strings.
[1684] Fix | Delete
var optionalParam = /\((.*?)\)/g;
[1685] Fix | Delete
var namedParam = /(\(\?)?:\w+/g;
[1686] Fix | Delete
var splatParam = /\*\w+/g;
[1687] Fix | Delete
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
[1688] Fix | Delete
[1689] Fix | Delete
// Set up all inheritable **Backbone.Router** properties and methods.
[1690] Fix | Delete
_.extend(Router.prototype, Events, {
[1691] Fix | Delete
[1692] Fix | Delete
// preinitialize is an empty function by default. You can override it with a function
[1693] Fix | Delete
// or object. preinitialize will run before any instantiation logic is run in the Router.
[1694] Fix | Delete
preinitialize: function(){},
[1695] Fix | Delete
[1696] Fix | Delete
// Initialize is an empty function by default. Override it with your own
[1697] Fix | Delete
// initialization logic.
[1698] Fix | Delete
initialize: function(){},
[1699] Fix | Delete
[1700] Fix | Delete
// Manually bind a single named route to a callback. For example:
[1701] Fix | Delete
//
[1702] Fix | Delete
// this.route('search/:query/p:num', 'search', function(query, num) {
[1703] Fix | Delete
// ...
[1704] Fix | Delete
// });
[1705] Fix | Delete
//
[1706] Fix | Delete
route: function(route, name, callback) {
[1707] Fix | Delete
if (!_.isRegExp(route)) route = this._routeToRegExp(route);
[1708] Fix | Delete
if (_.isFunction(name)) {
[1709] Fix | Delete
callback = name;
[1710] Fix | Delete
name = '';
[1711] Fix | Delete
}
[1712] Fix | Delete
if (!callback) callback = this[name];
[1713] Fix | Delete
var router = this;
[1714] Fix | Delete
Backbone.history.route(route, function(fragment) {
[1715] Fix | Delete
var args = router._extractParameters(route, fragment);
[1716] Fix | Delete
if (router.execute(callback, args, name) !== false) {
[1717] Fix | Delete
router.trigger.apply(router, ['route:' + name].concat(args));
[1718] Fix | Delete
router.trigger('route', name, args);
[1719] Fix | Delete
Backbone.history.trigger('route', router, name, args);
[1720] Fix | Delete
}
[1721] Fix | Delete
});
[1722] Fix | Delete
return this;
[1723] Fix | Delete
},
[1724] Fix | Delete
[1725] Fix | Delete
// Execute a route handler with the provided parameters. This is an
[1726] Fix | Delete
// excellent place to do pre-route setup or post-route cleanup.
[1727] Fix | Delete
execute: function(callback, args, name) {
[1728] Fix | Delete
if (callback) callback.apply(this, args);
[1729] Fix | Delete
},
[1730] Fix | Delete
[1731] Fix | Delete
// Simple proxy to `Backbone.history` to save a fragment into the history.
[1732] Fix | Delete
navigate: function(fragment, options) {
[1733] Fix | Delete
Backbone.history.navigate(fragment, options);
[1734] Fix | Delete
return this;
[1735] Fix | Delete
},
[1736] Fix | Delete
[1737] Fix | Delete
// Bind all defined routes to `Backbone.history`. We have to reverse the
[1738] Fix | Delete
// order of the routes here to support behavior where the most general
[1739] Fix | Delete
// routes can be defined at the bottom of the route map.
[1740] Fix | Delete
_bindRoutes: function() {
[1741] Fix | Delete
if (!this.routes) return;
[1742] Fix | Delete
this.routes = _.result(this, 'routes');
[1743] Fix | Delete
var route, routes = _.keys(this.routes);
[1744] Fix | Delete
while ((route = routes.pop()) != null) {
[1745] Fix | Delete
this.route(route, this.routes[route]);
[1746] Fix | Delete
}
[1747] Fix | Delete
},
[1748] Fix | Delete
[1749] Fix | Delete
// Convert a route string into a regular expression, suitable for matching
[1750] Fix | Delete
// against the current location hash.
[1751] Fix | Delete
_routeToRegExp: function(route) {
[1752] Fix | Delete
route = route.replace(escapeRegExp, '\\$&')
[1753] Fix | Delete
.replace(optionalParam, '(?:$1)?')
[1754] Fix | Delete
.replace(namedParam, function(match, optional) {
[1755] Fix | Delete
return optional ? match : '([^/?]+)';
[1756] Fix | Delete
})
[1757] Fix | Delete
.replace(splatParam, '([^?]*?)');
[1758] Fix | Delete
return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$');
[1759] Fix | Delete
},
[1760] Fix | Delete
[1761] Fix | Delete
// Given a route, and a URL fragment that it matches, return the array of
[1762] Fix | Delete
// extracted decoded parameters. Empty or unmatched parameters will be
[1763] Fix | Delete
// treated as `null` to normalize cross-browser behavior.
[1764] Fix | Delete
_extractParameters: function(route, fragment) {
[1765] Fix | Delete
var params = route.exec(fragment).slice(1);
[1766] Fix | Delete
return _.map(params, function(param, i) {
[1767] Fix | Delete
// Don't decode the search params.
[1768] Fix | Delete
if (i === params.length - 1) return param || null;
[1769] Fix | Delete
return param ? decodeURIComponent(param) : null;
[1770] Fix | Delete
});
[1771] Fix | Delete
}
[1772] Fix | Delete
[1773] Fix | Delete
});
[1774] Fix | Delete
[1775] Fix | Delete
// Backbone.History
[1776] Fix | Delete
// ----------------
[1777] Fix | Delete
[1778] Fix | Delete
// Handles cross-browser history management, based on either
[1779] Fix | Delete
// [pushState](http://diveintohtml5.info/history.html) and real URLs, or
[1780] Fix | Delete
// [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
[1781] Fix | Delete
// and URL fragments. If the browser supports neither (old IE, natch),
[1782] Fix | Delete
// falls back to polling.
[1783] Fix | Delete
var History = Backbone.History = function() {
[1784] Fix | Delete
this.handlers = [];
[1785] Fix | Delete
this.checkUrl = this.checkUrl.bind(this);
[1786] Fix | Delete
[1787] Fix | Delete
// Ensure that `History` can be used outside of the browser.
[1788] Fix | Delete
if (typeof window !== 'undefined') {
[1789] Fix | Delete
this.location = window.location;
[1790] Fix | Delete
this.history = window.history;
[1791] Fix | Delete
}
[1792] Fix | Delete
};
[1793] Fix | Delete
[1794] Fix | Delete
// Cached regex for stripping a leading hash/slash and trailing space.
[1795] Fix | Delete
var routeStripper = /^[#\/]|\s+$/g;
[1796] Fix | Delete
[1797] Fix | Delete
// Cached regex for stripping leading and trailing slashes.
[1798] Fix | Delete
var rootStripper = /^\/+|\/+$/g;
[1799] Fix | Delete
[1800] Fix | Delete
// Cached regex for stripping urls of hash.
[1801] Fix | Delete
var pathStripper = /#.*$/;
[1802] Fix | Delete
[1803] Fix | Delete
// Has the history handling already been started?
[1804] Fix | Delete
History.started = false;
[1805] Fix | Delete
[1806] Fix | Delete
// Set up all inheritable **Backbone.History** properties and methods.
[1807] Fix | Delete
_.extend(History.prototype, Events, {
[1808] Fix | Delete
[1809] Fix | Delete
// The default interval to poll for hash changes, if necessary, is
[1810] Fix | Delete
// twenty times a second.
[1811] Fix | Delete
interval: 50,
[1812] Fix | Delete
[1813] Fix | Delete
// Are we at the app root?
[1814] Fix | Delete
atRoot: function() {
[1815] Fix | Delete
var path = this.location.pathname.replace(/[^\/]$/, '$&/');
[1816] Fix | Delete
return path === this.root && !this.getSearch();
[1817] Fix | Delete
},
[1818] Fix | Delete
[1819] Fix | Delete
// Does the pathname match the root?
[1820] Fix | Delete
matchRoot: function() {
[1821] Fix | Delete
var path = this.decodeFragment(this.location.pathname);
[1822] Fix | Delete
var rootPath = path.slice(0, this.root.length - 1) + '/';
[1823] Fix | Delete
return rootPath === this.root;
[1824] Fix | Delete
},
[1825] Fix | Delete
[1826] Fix | Delete
// Unicode characters in `location.pathname` are percent encoded so they're
[1827] Fix | Delete
// decoded for comparison. `%25` should not be decoded since it may be part
[1828] Fix | Delete
// of an encoded parameter.
[1829] Fix | Delete
decodeFragment: function(fragment) {
[1830] Fix | Delete
return decodeURI(fragment.replace(/%25/g, '%2525'));
[1831] Fix | Delete
},
[1832] Fix | Delete
[1833] Fix | Delete
// In IE6, the hash fragment and search params are incorrect if the
[1834] Fix | Delete
// fragment contains `?`.
[1835] Fix | Delete
getSearch: function() {
[1836] Fix | Delete
var match = this.location.href.replace(/#.*/, '').match(/\?.+/);
[1837] Fix | Delete
return match ? match[0] : '';
[1838] Fix | Delete
},
[1839] Fix | Delete
[1840] Fix | Delete
// Gets the true hash value. Cannot use location.hash directly due to bug
[1841] Fix | Delete
// in Firefox where location.hash will always be decoded.
[1842] Fix | Delete
getHash: function(window) {
[1843] Fix | Delete
var match = (window || this).location.href.match(/#(.*)$/);
[1844] Fix | Delete
return match ? match[1] : '';
[1845] Fix | Delete
},
[1846] Fix | Delete
[1847] Fix | Delete
// Get the pathname and search params, without the root.
[1848] Fix | Delete
getPath: function() {
[1849] Fix | Delete
var path = this.decodeFragment(
[1850] Fix | Delete
this.location.pathname + this.getSearch()
[1851] Fix | Delete
).slice(this.root.length - 1);
[1852] Fix | Delete
return path.charAt(0) === '/' ? path.slice(1) : path;
[1853] Fix | Delete
},
[1854] Fix | Delete
[1855] Fix | Delete
// Get the cross-browser normalized URL fragment from the path or hash.
[1856] Fix | Delete
getFragment: function(fragment) {
[1857] Fix | Delete
if (fragment == null) {
[1858] Fix | Delete
if (this._usePushState || !this._wantsHashChange) {
[1859] Fix | Delete
fragment = this.getPath();
[1860] Fix | Delete
} else {
[1861] Fix | Delete
fragment = this.getHash();
[1862] Fix | Delete
}
[1863] Fix | Delete
}
[1864] Fix | Delete
return fragment.replace(routeStripper, '');
[1865] Fix | Delete
},
[1866] Fix | Delete
[1867] Fix | Delete
// Start the hash change handling, returning `true` if the current URL matches
[1868] Fix | Delete
// an existing route, and `false` otherwise.
[1869] Fix | Delete
start: function(options) {
[1870] Fix | Delete
if (History.started) throw new Error('Backbone.history has already been started');
[1871] Fix | Delete
History.started = true;
[1872] Fix | Delete
[1873] Fix | Delete
// Figure out the initial configuration. Do we need an iframe?
[1874] Fix | Delete
// Is pushState desired ... is it available?
[1875] Fix | Delete
this.options = _.extend({root: '/'}, this.options, options);
[1876] Fix | Delete
this.root = this.options.root;
[1877] Fix | Delete
this._trailingSlash = this.options.trailingSlash;
[1878] Fix | Delete
this._wantsHashChange = this.options.hashChange !== false;
[1879] Fix | Delete
this._hasHashChange = 'onhashchange' in window && (document.documentMode === void 0 || document.documentMode > 7);
[1880] Fix | Delete
this._useHashChange = this._wantsHashChange && this._hasHashChange;
[1881] Fix | Delete
this._wantsPushState = !!this.options.pushState;
[1882] Fix | Delete
this._hasPushState = !!(this.history && this.history.pushState);
[1883] Fix | Delete
this._usePushState = this._wantsPushState && this._hasPushState;
[1884] Fix | Delete
this.fragment = this.getFragment();
[1885] Fix | Delete
[1886] Fix | Delete
// Normalize root to always include a leading and trailing slash.
[1887] Fix | Delete
this.root = ('/' + this.root + '/').replace(rootStripper, '/');
[1888] Fix | Delete
[1889] Fix | Delete
// Transition from hashChange to pushState or vice versa if both are
[1890] Fix | Delete
// requested.
[1891] Fix | Delete
if (this._wantsHashChange && this._wantsPushState) {
[1892] Fix | Delete
[1893] Fix | Delete
// If we've started off with a route from a `pushState`-enabled
[1894] Fix | Delete
// browser, but we're currently in a browser that doesn't support it...
[1895] Fix | Delete
if (!this._hasPushState && !this.atRoot()) {
[1896] Fix | Delete
var rootPath = this.root.slice(0, -1) || '/';
[1897] Fix | Delete
this.location.replace(rootPath + '#' + this.getPath());
[1898] Fix | Delete
// Return immediately as browser will do redirect to new url
[1899] Fix | Delete
return true;
[1900] Fix | Delete
[1901] Fix | Delete
// Or if we've started out with a hash-based route, but we're currently
[1902] Fix | Delete
// in a browser where it could be `pushState`-based instead...
[1903] Fix | Delete
} else if (this._hasPushState && this.atRoot()) {
[1904] Fix | Delete
this.navigate(this.getHash(), {replace: true});
[1905] Fix | Delete
}
[1906] Fix | Delete
[1907] Fix | Delete
}
[1908] Fix | Delete
[1909] Fix | Delete
// Proxy an iframe to handle location events if the browser doesn't
[1910] Fix | Delete
// support the `hashchange` event, HTML5 history, or the user wants
[1911] Fix | Delete
// `hashChange` but not `pushState`.
[1912] Fix | Delete
if (!this._hasHashChange && this._wantsHashChange && !this._usePushState) {
[1913] Fix | Delete
this.iframe = document.createElement('iframe');
[1914] Fix | Delete
this.iframe.src = 'javascript:0';
[1915] Fix | Delete
this.iframe.style.display = 'none';
[1916] Fix | Delete
this.iframe.tabIndex = -1;
[1917] Fix | Delete
var body = document.body;
[1918] Fix | Delete
// Using `appendChild` will throw on IE < 9 if the document is not ready.
[1919] Fix | Delete
var iWindow = body.insertBefore(this.iframe, body.firstChild).contentWindow;
[1920] Fix | Delete
iWindow.document.open();
[1921] Fix | Delete
iWindow.document.close();
[1922] Fix | Delete
iWindow.location.hash = '#' + this.fragment;
[1923] Fix | Delete
}
[1924] Fix | Delete
[1925] Fix | Delete
// Add a cross-platform `addEventListener` shim for older browsers.
[1926] Fix | Delete
var addEventListener = window.addEventListener || function(eventName, listener) {
[1927] Fix | Delete
return attachEvent('on' + eventName, listener);
[1928] Fix | Delete
};
[1929] Fix | Delete
[1930] Fix | Delete
// Depending on whether we're using pushState or hashes, and whether
[1931] Fix | Delete
// 'onhashchange' is supported, determine how we check the URL state.
[1932] Fix | Delete
if (this._usePushState) {
[1933] Fix | Delete
addEventListener('popstate', this.checkUrl, false);
[1934] Fix | Delete
} else if (this._useHashChange && !this.iframe) {
[1935] Fix | Delete
addEventListener('hashchange', this.checkUrl, false);
[1936] Fix | Delete
} else if (this._wantsHashChange) {
[1937] Fix | Delete
this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
[1938] Fix | Delete
}
[1939] Fix | Delete
[1940] Fix | Delete
if (!this.options.silent) return this.loadUrl();
[1941] Fix | Delete
},
[1942] Fix | Delete
[1943] Fix | Delete
// Disable Backbone.history, perhaps temporarily. Not useful in a real app,
[1944] Fix | Delete
// but possibly useful for unit testing Routers.
[1945] Fix | Delete
stop: function() {
[1946] Fix | Delete
// Add a cross-platform `removeEventListener` shim for older browsers.
[1947] Fix | Delete
var removeEventListener = window.removeEventListener || function(eventName, listener) {
[1948] Fix | Delete
return detachEvent('on' + eventName, listener);
[1949] Fix | Delete
};
[1950] Fix | Delete
[1951] Fix | Delete
// Remove window listeners.
[1952] Fix | Delete
if (this._usePushState) {
[1953] Fix | Delete
removeEventListener('popstate', this.checkUrl, false);
[1954] Fix | Delete
} else if (this._useHashChange && !this.iframe) {
[1955] Fix | Delete
removeEventListener('hashchange', this.checkUrl, false);
[1956] Fix | Delete
}
[1957] Fix | Delete
[1958] Fix | Delete
// Clean up the iframe if necessary.
[1959] Fix | Delete
if (this.iframe) {
[1960] Fix | Delete
document.body.removeChild(this.iframe);
[1961] Fix | Delete
this.iframe = null;
[1962] Fix | Delete
}
[1963] Fix | Delete
[1964] Fix | Delete
// Some environments will throw when clearing an undefined interval.
[1965] Fix | Delete
if (this._checkUrlInterval) clearInterval(this._checkUrlInterval);
[1966] Fix | Delete
History.started = false;
[1967] Fix | Delete
},
[1968] Fix | Delete
[1969] Fix | Delete
// Add a route to be tested when the fragment changes. Routes added later
[1970] Fix | Delete
// may override previous routes.
[1971] Fix | Delete
route: function(route, callback) {
[1972] Fix | Delete
this.handlers.unshift({route: route, callback: callback});
[1973] Fix | Delete
},
[1974] Fix | Delete
[1975] Fix | Delete
// Checks the current URL to see if it has changed, and if it has,
[1976] Fix | Delete
// calls `loadUrl`, normalizing across the hidden iframe.
[1977] Fix | Delete
checkUrl: function(e) {
[1978] Fix | Delete
var current = this.getFragment();
[1979] Fix | Delete
[1980] Fix | Delete
// If the user pressed the back button, the iframe's hash will have
[1981] Fix | Delete
// changed and we should use that for comparison.
[1982] Fix | Delete
if (current === this.fragment && this.iframe) {
[1983] Fix | Delete
current = this.getHash(this.iframe.contentWindow);
[1984] Fix | Delete
}
[1985] Fix | Delete
[1986] Fix | Delete
if (current === this.fragment) return false;
[1987] Fix | Delete
if (this.iframe) this.navigate(current);
[1988] Fix | Delete
this.loadUrl();
[1989] Fix | Delete
},
[1990] Fix | Delete
[1991] Fix | Delete
// Attempt to load the current URL fragment. If a route succeeds with a
[1992] Fix | Delete
// match, returns `true`. If no defined routes matches the fragment,
[1993] Fix | Delete
// returns `false`.
[1994] Fix | Delete
loadUrl: function(fragment) {
[1995] Fix | Delete
// If the root doesn't match, no routes can match either.
[1996] Fix | Delete
if (!this.matchRoot()) return false;
[1997] Fix | Delete
fragment = this.fragment = this.getFragment(fragment);
[1998] Fix | Delete
return _.some(this.handlers, function(handler) {
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function