12 lines
5.6 KiB
JavaScript
Executable File
12 lines
5.6 KiB
JavaScript
Executable File
(function(g){var f=window.AmazonUIPageJS||window.P,r=f._namespace||f.attributeErrors,e=r?r("AmazonRushRouter",""):f;e.guardFatal?e.guardFatal(g)(e,window):e.execute(function(){g(e,window)})})(function(g,f,r){g.when("A").register("rush-routable-application-base",function(e){return e.createClass({init:function(c){this.applicationName=c},name:function(){return this.applicationName},unload:function(){return{}},load:function(){return!0}})});"use strict";g.when("A").register("rush-router-html5-history-support",
|
|
function(e){var c=e.$.extend,n=/OS ([0-9]+)(?:_([0-9]+))?/,g=/Android ([0-9]+)(?:\.([0-9]+))?/,h=/iPhone|iPad|iPod/;return function(e){function b(a,b,d){b=d.match(b);return{major:a&&b&&b[1]?parseInt(b[1],10):-1,minor:a&&b&&b[2]?parseInt(b[2],10):-1}}function p(a){if(!a||!a.url&&!a.state)return!1;d.replaceState(c({},d.state(),a.state),d.title(),a.url);return!0}var d=e||{userAgent:f.navigator.userAgent,pushState:function(a,b,d){f.history.pushState(a,b,d)},replaceState:function(a,b,d){f.history.replaceState(a,
|
|
b,d)},title:function(){return document.title},state:function(){return f.history.state},addStateChangeHandler:function(a){f.addEventListener("popstate",a,!1)},removeStateChangeHandler:function(a){f.removeEventListener("popstate",a)},hasNativeHistorySupport:function(){return f.history&&f.history.replaceState}};return{isSupportedBrowser:function(){var a=d.userAgent;return d.hasNativeHistorySupport()?h.test(a)?(a=b(!0,n,a),5<=a.major):-1!==a.indexOf("Android")?(a=b(!0,g,a),4<a.major||4===a.major&&2<=
|
|
a.minor):!0:!1},to:function(a){if(!a||!a.url&&!a.state)return!1;d.pushState(c({},a.state||{}),d.title(),a.url);return!0},replace:p,back:function(){d.history.back()},state:function(a){a&&p({state:a});return d.state()||{}},addStateChangeHandler:d.addStateChangeHandler,removeStateChangeHandler:d.removeStateChangeHandler}}});"use strict";g.when("A").register("rush-router-pattern-parser",function(e){function c(b,c){return c?(e.isArray(c)||(c=[c]),c.concat(e.isArray(b)?b:[b])):b}function f(b){return decodeURIComponent((b||
|
|
"").replace(/\+/g," "))}function g(b,e){var d={},a=!1,f=e.match(b),g=null,p=(b.toString().match(q)||[]).length,n=1,h=0;if(f)for(a=!0,b=f[0],(g=e.substr(b.length))&&"/"===b.charAt(b.length-1)&&(g="/"+g);h<p;h++)d.wildcard=c(f[n],d.wildcard),n++;return{isMatch:a,remainingPathname:g,params:d}}function h(b){var e={},d;if(!b)return e;"?"===b[0]&&(b=b.slice(1));b=b.split("\x26");for(d=0;d<b.length;d++){var a=b[d].split("\x3d");var g=f(a.shift());a=a.length?f(a.join("\x3d")):null;g&&(e[g]=c(a,e[g]))}return e}
|
|
var q=/\(\.\*\)/g;return{matchPathname:g,parseQueryString:h,matchLocation:function(b,f){var d=g(b,f.pathname);if(!1===d.isMatch||d.remainingPathname)return d.isMatch=!1,d;b=h(f.search);e.each(b,function(a,b){d.params[b]=c(a,d.params[b])});return d}}});"use strict";g.register("rush-route",function(){return{create:function(e,c){return{pattern:function(){return e},handler:function(){return c}}}}});"use strict";g.when("a-util","rush-router-pattern-parser","rush-route","rush-router-html5-history-support",
|
|
"rush-routable-application-base","rush-router-url-parser").register("R",function(e,c,n,t,h,q){function b(a){a=q.parse(a.href);return a.protocol+"//"+a.host}function p(){return document.location}function d(d,e){function h(a){l().href===a?l().reload(!0):l().href=a}function t(a,b,d,e,c,g,f){function m(a){return!1===a?(!1!==c&&h(d.href),!1):!0}if(f)a.handler().call(d,b,d,g,function(a){f(m(a))});else return m(a.handler().call(d,b,d,g))}function k(a,b,d,e,g){if(!a)return!1;a:{var m;for(m=0;m<u.length;m++){var f=
|
|
u[m];var w=c.matchLocation(f.pattern(),a);if(w.isMatch){f={route:f,params:w.params};break a}}f=void 0}if(f)return!!t(f.route,f.params,a,d,b,e,g);!1!==b&&h(a.href);g&&g(!1);return!1}function x(a){k(l(),r,a)}function y(a){var e;if(!(1!==a.which||a.metaKey||a.ctrlKey||a.shiftKey||a.defaultPrevented)){var c=a.target;for(e=l().href;c&&"A"!==c.nodeName;)c=c.parentNode;!c||"A"!==c.nodeName||!c.hasAttribute("href")||c.hasAttribute("download")||"off"===c.getAttribute("data-routing")||c.target&&"_self"!==c.target||
|
|
z!==b(c)||c.href===e||c.href.split("#")[0]===e.split("#")[0]||!0!==k(c,!1)||(d.to({url:c.href,state:null}),a.preventDefault())}}var l=e||p,u=[],z=b(l()),v=!1;return{addRoute:function(a,b){a=n.create(a,b);u.push(a)},removeRoute:function(){throw Error('the "rush-router R:removeRoute" method has been deprecated');},route:x,to:function(b,c){b=a({url:l().href,state:{},history:!0},b);var e=q.parse(b.url);k(e,!0,!1,c,function(a){!0===a&&!1!==b.history&&d.to({url:b.url,state:b.state})})},replace:function(){throw Error('the "rush-router R:replace" method has been deprecated');
|
|
},back:d.back,state:d.state,switchApp:function(){throw Error('the "rush-router R:switchApp" method has been deprecated');},start:function(a){v||(v=!0,g.when("load").execute("routerBindStateChangeHandler",function(){v&&d.addStateChangeHandler(x)}),f.addEventListener("click",y,!1),a=a?q.parse(a):l(),k(a,!1))},stop:function(){throw Error('the "rush-router R:stop" method has been deprecated');},pause:function(){throw Error('the "rush-router R:pause" method has been deprecated');},unpause:function(){throw Error('the "rush-router R:unpause" method has been deprecated');
|
|
}}}var a=e.extend;e=e.mixin;var k={};e(k,d(new t));k.createRouter=d;k.ApplicationBase=h;return k});"use strict";g.register("rush-router-url-parser",function(){var e="protocol hostname host pathname port search hash href".split(" ");return{parse:function(c){var f=document.createElement("a"),g={};f.href=c;f.href=f.href;for(c=0;c<e.length;c++)"pathname"===e[c]?g.pathname=f.pathname.replace(/(^\/?)/,"/"):g[e[c]]=f[e[c]];return g},toUrl:function(c){if(c)return c.protocol+"//"+c.host+c.pathname+c.search+
|
|
c.hash}}})}); |