diff --git a/dist/jsRoute.js b/dist/jsRoute.js index 18a4531..88b40f4 100644 --- a/dist/jsRoute.js +++ b/dist/jsRoute.js @@ -467,12 +467,8 @@ define("../node_modules/almond/almond", function(){}); function noop() { } exports.noop = noop; function setView(selector) { - if (selector) { - rootView = document.querySelector(selector); - } - else { - rootView = document.querySelector('.jsroute-view'); - } + selector = selector || '.jsroute-view'; + rootView = document.querySelector(selector); } exports.setView = setView; function getView() { @@ -480,12 +476,8 @@ define("../node_modules/almond/almond", function(){}); } exports.getView = getView; function setRoot(selector) { - if (selector) { - rootElement = document.querySelector(selector); - } - else { - rootElement = document.querySelector('.jsroute-app'); - } + selector = selector || '.jsroute-app'; + rootElement = document.querySelector(selector); } exports.setRoot = setRoot; function getRoot() { diff --git a/dist/jsRoute.min.js b/dist/jsRoute.min.js index 63b1e56..8088e74 100644 --- a/dist/jsRoute.min.js +++ b/dist/jsRoute.min.js @@ -1 +1 @@ -!function(a){var b,c,d;!function(a){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=s.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if(e=p[o.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(b){if(e(r,b)){var c=r[b];delete r[b],t[b]=!0,m.apply(a,c)}if(!e(q,b)&&!e(t,b))throw new Error("No "+b);return q[b]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(b,c,d,f){var h,k,l,m,n,s,u=[],v=typeof d;if(f=f||b,"undefined"===v||"function"===v){for(c=!c.length&&d.length?["require","exports","module"]:c,n=0;nc;c++)if(l[c].matchRoute(a.pathname))return b(l[c]);return b()}function f(a){l.push(a)}function g(a){m=window.location.origin+a}function h(){c(),k.monitorBrowserNavigation()}var i=a("../utils/utils"),j=a("../http/http"),k=a("../history/history"),l=[],m="/";b.addRoute=f,b.addFallback=g,b.start=h}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){var c=this;c.path=a,c.options=b}return a.prototype.matchRoute=function(a){var b=this,c=a.split("/"),d=b.path.split("/");if("/"===a&&a===b.path)return!0;if(d.length!==c.length)return!1;for(var e=1,f=d.length;f>e;e++){var g=c[e]+"|\\:\\w+",h=new RegExp(g);if(!h.test(d[e]))return!1}return!0},a.prototype.getParams=function(a){for(var b=this,c=a.split("/"),d=b.path.split("/"),e={},f=1,g=d.length;g>f;f++){var h=/:\w+/;if(h.test(d[f])){var i=d[f].replace(":","");e[i]=c[f]}}return e},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("index",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}),a.JSRoute=a.JSRoute||c("index")["default"]}(window); \ No newline at end of file +!function(a){var b,c,d;!function(a){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=s.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if(e=p[o.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(b){if(e(r,b)){var c=r[b];delete r[b],t[b]=!0,m.apply(a,c)}if(!e(q,b)&&!e(t,b))throw new Error("No "+b);return q[b]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(b,c,d,f){var h,k,l,m,n,s,u=[],v=typeof d;if(f=f||b,"undefined"===v||"function"===v){for(c=!c.length&&d.length?["require","exports","module"]:c,n=0;nc;c++)if(l[c].matchRoute(a.pathname))return b(l[c]);return b()}function f(a){l.push(a)}function g(a){m=window.location.origin+a}function h(){c(),k.monitorBrowserNavigation()}var i=a("../utils/utils"),j=a("../http/http"),k=a("../history/history"),l=[],m="/";b.addRoute=f,b.addFallback=g,b.start=h}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){var c=this;c.path=a,c.options=b}return a.prototype.matchRoute=function(a){var b=this,c=a.split("/"),d=b.path.split("/");if("/"===a&&a===b.path)return!0;if(d.length!==c.length)return!1;for(var e=1,f=d.length;f>e;e++){var g=c[e]+"|\\:\\w+",h=new RegExp(g);if(!h.test(d[e]))return!1}return!0},a.prototype.getParams=function(a){for(var b=this,c=a.split("/"),d=b.path.split("/"),e={},f=1,g=d.length;g>f;f++){var h=/:\w+/;if(h.test(d[f])){var i=d[f].replace(":","");e[i]=c[f]}}return e},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("index",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}),a.JSRoute=a.JSRoute||c("index")["default"]}(window); \ No newline at end of file diff --git a/dist/jsRoute.noamd.js b/dist/jsRoute.noamd.js index 6fee01a..9dca1cb 100644 --- a/dist/jsRoute.noamd.js +++ b/dist/jsRoute.noamd.js @@ -37,12 +37,8 @@ function noop() { } exports.noop = noop; function setView(selector) { - if (selector) { - rootView = document.querySelector(selector); - } - else { - rootView = document.querySelector('.jsroute-view'); - } + selector = selector || '.jsroute-view'; + rootView = document.querySelector(selector); } exports.setView = setView; function getView() { @@ -50,12 +46,8 @@ } exports.getView = getView; function setRoot(selector) { - if (selector) { - rootElement = document.querySelector(selector); - } - else { - rootElement = document.querySelector('.jsroute-app'); - } + selector = selector || '.jsroute-app'; + rootElement = document.querySelector(selector); } exports.setRoot = setRoot; function getRoot() { diff --git a/dist/jsRoute.noamd.min.js b/dist/jsRoute.noamd.min.js index eb0f058..6bfa3bb 100644 --- a/dist/jsRoute.noamd.min.js +++ b/dist/jsRoute.noamd.min.js @@ -1 +1 @@ -!function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("events/eventHandler",["require","exports"],a)}(function(a,b){"use strict";function c(a,b,c){var d;[].slice.call(arguments);c.cancelable=!0,d=new CustomEvent(a,c),b.dispatchEvent(d)}b.broadcastEvent=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("utils/utils",["require","exports"],a)}(function(a,b){"use strict";function c(){}function d(a){l=a?document.querySelector(a):document.querySelector(".jsroute-view")}function e(){return l}function f(a){k=a?document.querySelector(a):document.querySelector(".jsroute-app")}function g(){return k}var h=/\w+\:\/\//;b.protocolRegex=h;var i=/\w+\.\w{1,4}\//;b.hostRegex=i;var j=/\/w+|d+$|\//;b.pathRegex=j;var k,l;b.noop=c,b.setView=d,b.getView=e,b.setRoot=f,b.getRoot=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("location/location.model",["require","exports","../utils/utils","../router/router.events"],a)}(function(a,b){"use strict";function c(a){var b=window.location,c=new f(a);return{next:c,prev:b}}var d=a("../utils/utils"),e=a("../router/router.events"),f=function(){function a(a){this.params={},this.hash=a.match(/^#*\?|$/)||"","object"==typeof this.hash&&(this.hash=this.hash[0]),this.host=a.match(d.hostRegex)||window.location.host,"object"==typeof this.host&&(this.host=this.host[0]),this.hostname=this.host.match(/\w+/)[0],this.protocol=a.match(d.protocolRegex)||window.location.protocol,"object"==typeof this.protocol&&(this.protocol=this.protocol[0],this.protocol=this.protocol.replace("//","")),this.origin=this.protocol+"//"+this.host,this.pathname=a.replace(this.protocol+"//","").replace(this.host,""),this.search=a.match(/^\?*$/)||"",this.href=""+this.origin+this.pathname,this.matchingPath=""}return a.prototype.path=function(a){e.startRouteChange(c(a))},a}();b.$Location=f,b.constructRoute=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router.events",["require","exports","../events/eventHandler","../location/location.model","../utils/utils"],a)}(function(a,b){"use strict";function c(){d(h.constructRoute(window.location.origin+window.location.pathname))}function d(a){var b=i.getRoot();g.broadcastEvent("routeChange",b,{detail:a})}function e(){var a=i.getRoot();a.addEventListener("click",function(a){"A"===a.target.nodeName&&(a.preventDefault(),d(h.constructRoute(a.target.href)))})}function f(){e()}var g=a("../events/eventHandler"),h=a("../location/location.model"),i=a("../utils/utils");b.onRun=c,b.startRouteChange=d,b.register=f}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("http/http",["require","exports","../utils/utils"],a)}(function(a,b){"use strict";var c=a("../utils/utils"),d={get:function(a,b){function d(){f.readyState===XMLHttpRequest.DONE&&(200===f.status?e(null,f.responseText):e(f.status))}var e=b||c.noop,f=new XMLHttpRequest;f.onreadystatechange=d,f.open("GET",a),f.send()}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("history/history",["require","exports","../router/router.events","../location/location.model"],a)}(function(a,b){"use strict";function c(a,b){var c=a.options.templateUrl.split("/"),d=c.pop();j||(g.push(b),i=g.length-1,h.pushState({path:b},d,b)),j=!1}function d(){window.addEventListener("popstate",function(a){a.preventDefault(),j=!0,e.startRouteChange(f.constructRoute(a.state.path))})}var e=a("../router/router.events"),f=a("../location/location.model"),g=[],h=window.history,i=-1,j=!1;b.push=c,b.monitorBrowserNavigation=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.observer",["require","exports","../utils/utils","../http/http","../history/history"],a)}(function(a,b){"use strict";function c(){var a=i.getRoot();a.addEventListener("routeChange",d,!1)}function d(a){if(!a.defaultPrevented){var b=a.detail.next,c=a.detail.prev;b.host!==c.host&&window.location.assign(b.href),e(b,function(a){return a?(k.push(a,b.pathname),b.matchingPath=a.path,void j["default"].get(a.options.templateUrl,function(c,d){var e=i.getView();b.params=a.getParams(b.pathname),e.innerHTML=d,a.options.onLoad&&a.options.onLoad(i.getRoot(),b)})):b.path(m)})}}function e(a,b){for(var c=0,d=l.length;d>c;c++)if(l[c].matchRoute(a.pathname))return b(l[c]);return b()}function f(a){l.push(a)}function g(a){m=window.location.origin+a}function h(){c(),k.monitorBrowserNavigation()}var i=a("../utils/utils"),j=a("../http/http"),k=a("../history/history"),l=[],m="/";b.addRoute=f,b.addFallback=g,b.start=h}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){var c=this;c.path=a,c.options=b}return a.prototype.matchRoute=function(a){var b=this,c=a.split("/"),d=b.path.split("/");if("/"===a&&a===b.path)return!0;if(d.length!==c.length)return!1;for(var e=1,f=d.length;f>e;e++){var g=c[e]+"|\\:\\w+",h=new RegExp(g);if(!h.test(d[e]))return!1}return!0},a.prototype.getParams=function(a){for(var b=this,c=a.split("/"),d=b.path.split("/"),e={},f=1,g=d.length;g>f;f++){var h=/:\w+/;if(h.test(d[f])){var i=d[f].replace(":","");e[i]=c[f]}}return e},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("JSRoute",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}); \ No newline at end of file +!function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("events/eventHandler",["require","exports"],a)}(function(a,b){"use strict";function c(a,b,c){var d;[].slice.call(arguments);c.cancelable=!0,d=new CustomEvent(a,c),b.dispatchEvent(d)}b.broadcastEvent=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("utils/utils",["require","exports"],a)}(function(a,b){"use strict";function c(){}function d(a){a=a||".jsroute-view",l=document.querySelector(a)}function e(){return l}function f(a){a=a||".jsroute-app",k=document.querySelector(a)}function g(){return k}var h=/\w+\:\/\//;b.protocolRegex=h;var i=/\w+\.\w{1,4}\//;b.hostRegex=i;var j=/\/w+|d+$|\//;b.pathRegex=j;var k,l;b.noop=c,b.setView=d,b.getView=e,b.setRoot=f,b.getRoot=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("location/location.model",["require","exports","../utils/utils","../router/router.events"],a)}(function(a,b){"use strict";function c(a){var b=window.location,c=new f(a);return{next:c,prev:b}}var d=a("../utils/utils"),e=a("../router/router.events"),f=function(){function a(a){this.params={},this.hash=a.match(/^#*\?|$/)||"","object"==typeof this.hash&&(this.hash=this.hash[0]),this.host=a.match(d.hostRegex)||window.location.host,"object"==typeof this.host&&(this.host=this.host[0]),this.hostname=this.host.match(/\w+/)[0],this.protocol=a.match(d.protocolRegex)||window.location.protocol,"object"==typeof this.protocol&&(this.protocol=this.protocol[0],this.protocol=this.protocol.replace("//","")),this.origin=this.protocol+"//"+this.host,this.pathname=a.replace(this.protocol+"//","").replace(this.host,""),this.search=a.match(/^\?*$/)||"",this.href=""+this.origin+this.pathname,this.matchingPath=""}return a.prototype.path=function(a){e.startRouteChange(c(a))},a}();b.$Location=f,b.constructRoute=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router.events",["require","exports","../events/eventHandler","../location/location.model","../utils/utils"],a)}(function(a,b){"use strict";function c(){d(h.constructRoute(window.location.origin+window.location.pathname))}function d(a){var b=i.getRoot();g.broadcastEvent("routeChange",b,{detail:a})}function e(){var a=i.getRoot();a.addEventListener("click",function(a){"A"===a.target.nodeName&&(a.preventDefault(),d(h.constructRoute(a.target.href)))})}function f(){e()}var g=a("../events/eventHandler"),h=a("../location/location.model"),i=a("../utils/utils");b.onRun=c,b.startRouteChange=d,b.register=f}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("http/http",["require","exports","../utils/utils"],a)}(function(a,b){"use strict";var c=a("../utils/utils"),d={get:function(a,b){function d(){f.readyState===XMLHttpRequest.DONE&&(200===f.status?e(null,f.responseText):e(f.status))}var e=b||c.noop,f=new XMLHttpRequest;f.onreadystatechange=d,f.open("GET",a),f.send()}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("history/history",["require","exports","../router/router.events","../location/location.model"],a)}(function(a,b){"use strict";function c(a,b){var c=a.options.templateUrl.split("/"),d=c.pop();j||(g.push(b),i=g.length-1,h.pushState({path:b},d,b)),j=!1}function d(){window.addEventListener("popstate",function(a){a.preventDefault(),j=!0,e.startRouteChange(f.constructRoute(a.state.path))})}var e=a("../router/router.events"),f=a("../location/location.model"),g=[],h=window.history,i=-1,j=!1;b.push=c,b.monitorBrowserNavigation=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.observer",["require","exports","../utils/utils","../http/http","../history/history"],a)}(function(a,b){"use strict";function c(){var a=i.getRoot();a.addEventListener("routeChange",d,!1)}function d(a){if(!a.defaultPrevented){var b=a.detail.next,c=a.detail.prev;b.host!==c.host&&window.location.assign(b.href),e(b,function(a){return a?(k.push(a,b.pathname),b.matchingPath=a.path,void j["default"].get(a.options.templateUrl,function(c,d){var e=i.getView();b.params=a.getParams(b.pathname),e.innerHTML=d,a.options.onLoad&&a.options.onLoad(i.getRoot(),b)})):b.path(m)})}}function e(a,b){for(var c=0,d=l.length;d>c;c++)if(l[c].matchRoute(a.pathname))return b(l[c]);return b()}function f(a){l.push(a)}function g(a){m=window.location.origin+a}function h(){c(),k.monitorBrowserNavigation()}var i=a("../utils/utils"),j=a("../http/http"),k=a("../history/history"),l=[],m="/";b.addRoute=f,b.addFallback=g,b.start=h}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){var c=this;c.path=a,c.options=b}return a.prototype.matchRoute=function(a){var b=this,c=a.split("/"),d=b.path.split("/");if("/"===a&&a===b.path)return!0;if(d.length!==c.length)return!1;for(var e=1,f=d.length;f>e;e++){var g=c[e]+"|\\:\\w+",h=new RegExp(g);if(!h.test(d[e]))return!1}return!0},a.prototype.getParams=function(a){for(var b=this,c=a.split("/"),d=b.path.split("/"),e={},f=1,g=d.length;g>f;f++){var h=/:\w+/;if(h.test(d[f])){var i=d[f].replace(":","");e[i]=c[f]}}return e},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("JSRoute",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}); \ No newline at end of file diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 10d9b80..a6a8241 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -10,11 +10,8 @@ var rootView; function noop() {} function setView(selector): void { - if(selector) { - rootView = document.querySelector(selector); - } else { - rootView = document.querySelector('.jsroute-view'); - } + selector = selector || '.jsroute-view'; + rootView = document.querySelector(selector); } function getView() { @@ -22,11 +19,8 @@ function getView() { } function setRoot(selector): void { - if(selector) { - rootElement = document.querySelector(selector); - } else { - rootElement = document.querySelector('.jsroute-app'); - } + selector = selector || '.jsroute-app'; + rootElement = document.querySelector(selector); } function getRoot() {