From 5ae67306bc6fca2a1c5185c7645e14e214a41bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Karl=20Roland=20W=C3=A4rting?= Date: Sat, 4 Feb 2017 11:38:16 +0100 Subject: [PATCH] Update path.js switched to only use one type of quote, Removed some where it isn't necessary --- path.js | 88 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/path.js b/path.js index d56a2d8..2439fad 100644 --- a/path.js +++ b/path.js @@ -1,50 +1,50 @@ var Path = { - 'version': "0.8.4", - 'map': function (path) { + version: '0.8.4', + map: function (path) { if (Path.routes.defined.hasOwnProperty(path)) { return Path.routes.defined[path]; } else { return new Path.core.route(path); } }, - 'root': function (path) { + root: function (path) { Path.routes.root = path; }, - 'rescue': function (fn) { + rescue: function (fn) { Path.routes.rescue = fn; }, - 'history': { - 'initial':{}, // Empty container for "Initial Popstate" checking variables. - 'pushState': function(state, title, path){ - if(Path.history.supported){ - if(Path.dispatch(path)){ + history: { + initial:{}, // Empty container for "Initial Popstate" checking variables. + pushState: function(state, title, path) { + if (Path.history.supported) { + if (Path.dispatch(path)) { history.pushState(state, title, path); } } else { - if(Path.history.fallback){ - window.location.hash = "#" + path; + if(Path.history.fallback) { + window.location.hash = '#' + path; } } }, - 'popState': function(event){ + popState: function(event) { var initialPop = !Path.history.initial.popped && location.href == Path.history.initial.URL; Path.history.initial.popped = true; if(initialPop) return; Path.dispatch(document.location.pathname); }, - 'listen': function(fallback){ + listen: function(fallback) { Path.history.supported = !!(window.history && window.history.pushState); Path.history.fallback = fallback; - if(Path.history.supported){ + if (Path.history.supported) { Path.history.initial.popped = ('state' in window.history), Path.history.initial.URL = location.href; window.onpopstate = Path.history.popState; } else { - if(Path.history.fallback){ - for(route in Path.routes.defined){ - if(route.charAt(0) != "#"){ - Path.routes.defined["#"+route] = Path.routes.defined[route]; - Path.routes.defined["#"+route].path = "#"+route; + if (Path.history.fallback){ + for (route in Path.routes.defined) { + if (route.charAt(0) != '#') { + Path.routes.defined['#'+route] = Path.routes.defined[route]; + Path.routes.defined['#'+route].path = "#"+route; } } Path.listen(); @@ -52,7 +52,7 @@ var Path = { } } }, - 'match': function (path, parameterize) { + match: function (path, parameterize) { var params = {}, route = null, possible_routes, slice, i, j, compare; for (route in Path.routes.defined) { if (route !== null && route !== undefined) { @@ -62,10 +62,10 @@ var Path = { slice = possible_routes[j]; compare = path; if (slice.search(/:/) > 0) { - for (i = 0; i < slice.split("/").length; i++) { - if ((i < compare.split("/").length) && (slice.split("/")[i].charAt(0) === ":")) { - params[slice.split('/')[i].replace(/:/, '')] = compare.split("/")[i]; - compare = compare.replace(compare.split("/")[i], slice.split("/")[i]); + for (i = 0; i < slice.split('/').length; i++) { + if ((i < compare.split('/').length) && (slice.split('/')[i].charAt(0) === ':')) { + params[slice.split('/')[i].replace(/:/, '')] = compare.split('/')[i]; + compare = compare.replace(compare.split('/')[i], slice.split('/')[i]); } } } @@ -80,7 +80,7 @@ var Path = { } return null; }, - 'dispatch': function (passed_route) { + dispatch: function (passed_route) { var previous_route, matched_route; if (Path.routes.current !== passed_route) { Path.routes.previous = Path.routes.current; @@ -104,10 +104,10 @@ var Path = { } } }, - 'listen': function () { + listen: function () { var fn = function(){ Path.dispatch(location.hash); } - if (location.hash === "") { + if (location.hash === '') { if (Path.routes.root !== null) { location.hash = Path.routes.root; } @@ -115,18 +115,18 @@ var Path = { // The 'document.documentMode' checks below ensure that PathJS fires the right events // even in IE "Quirks Mode". - if ("onhashchange" in window && (!document.documentMode || document.documentMode >= 8)) { + if ('onhashchange' in window && (!document.documentMode || document.documentMode >= 8)) { window.onhashchange = fn; } else { setInterval(fn, 50); } - if(location.hash !== "") { + if (location.hash !== '') { Path.dispatch(location.hash); } }, - 'core': { - 'route': function (path) { + core: { + route: function (path) { this.path = path; this.action = null; this.do_enter = []; @@ -135,20 +135,20 @@ var Path = { Path.routes.defined[path] = this; } }, - 'routes': { - 'current': null, - 'root': null, - 'rescue': null, - 'previous': null, - 'defined': {} + routes: { + current: null, + root: null, + rescue: null, + previous: null, + defined: {} } }; Path.core.route.prototype = { - 'to': function (fn) { + to: function (fn) { this.action = fn; return this; }, - 'enter': function (fns) { + enter: function (fns) { if (fns instanceof Array) { this.do_enter = this.do_enter.concat(fns); } else { @@ -156,11 +156,11 @@ Path.core.route.prototype = { } return this; }, - 'exit': function (fn) { + exit: function (fn) { this.do_exit = fn; return this; }, - 'partition': function () { + partition: function () { var parts = [], options = [], re = /\(([^}]+?)\)/g, text, i; while (text = re.exec(this.path)) { parts.push(text[1]); @@ -171,10 +171,10 @@ Path.core.route.prototype = { } return options; }, - 'run': function () { + run: function () { var halt_execution = false, i, result, previous; - if (Path.routes.defined[this.path].hasOwnProperty("do_enter")) { + if (Path.routes.defined[this.path].hasOwnProperty('do_enter')) { if (Path.routes.defined[this.path].do_enter.length > 0) { for (i = 0; i < Path.routes.defined[this.path].do_enter.length; i++) { result = Path.routes.defined[this.path].do_enter[i].apply(this, null); @@ -189,4 +189,4 @@ Path.core.route.prototype = { Path.routes.defined[this.path].action(); } } -}; \ No newline at end of file +};