1 !function(t,e){function i(t,i,r){var n=e.createEvent("CustomEvent");return n.ini
tCustomEvent(t,!1,!0,i),r.dispatchEvent(n)}e.registerElement("app-route",{protot
ype:Object.create(HTMLElement.prototype)}),e.registerElement("active-route",{pro
totype:Object.create(HTMLElement.prototype)});var r=Object.create(HTMLElement.pr
ototype),n={},a="ActiveXObject"in t;r.attachedCallback=function(){"manual"!==thi
s.getAttribute("init")&&this.init()},r.init=function(){this.isInitialized||(this
.isInitialized=!0,this.activeRoute=e.createElement("app-route"),this.stateChange
Handler=this.go.bind(this),t.addEventListener("popstate",this.stateChangeHandler
,!1),a&&t.addEventListener("hashchange",this.stateChangeHandler,!1),this.activeR
outeContent=e.createElement("active-route"),this.appendChild(this.activeRouteCon
tent),this.hasAttribute("shadow")&&(this.activeRouteContent=this.activeRouteCont
ent.createShadowRoot()),this.go())},r.detachedCallback=function(){t.removeEventL
istener("popstate",this.stateChangeHandler,!1),a&&t.removeEventListener("hashcha
nge",this.stateChangeHandler,!1)},r.go=function(){var e=this.parseUrlPath(t.loca
tion.href),r={path:e};if(i("state-change",r,this)){for(var n=this.querySelectorA
ll("app-route"),a=0;a<n.length;a++)if(this.testRoute(n[a].getAttribute("path"),e
,this.getAttribute("trailingSlash"),n[a].hasAttribute("regex")))return void this
.activateRoute(n[a],e);i("not-found",r,this)}},r.activateRoute=function(t,e){var
r={path:e,route:t,oldRoute:this.activeRoute};if(i("activate-route-start",r,this
)&&i("activate-route-start",r,t)){this.activeRoute.removeAttribute("active"),t.s
etAttribute("active","active"),this.activeRoute=t;var n=t.getAttribute("import")
,a=t.getAttribute("path"),s=t.hasAttribute("regex"),o=t.getAttribute("element"),
c=t.hasAttribute("template"),l=!c;l&&n?this.importAndActivateCustomElement(n,o,a
,e,s,r):l&&!n&&o?this.activateCustomElement(o,a,e,s,r):c&&n?this.importAndActiva
teTemplate(n,t,r):c&&!n&&this.activateTemplate(t,r)}},r.importAndActivateCustomE
lement=function(t,i,r,a,s,o){if(!n.hasOwnProperty(t)){n[t]=!0;var c=e.createElem
ent("link");c.setAttribute("rel","import"),c.setAttribute("href",t),e.head.appen
dChild(c)}this.activateCustomElement(i||t.split("/").slice(-1)[0].replace(".html
",""),r,a,s,o)},r.activateCustomElement=function(i,r,n,a,s){var o=e.createElemen
t(i),c=this.routeArguments(r,n,t.location.href,a);for(var l in c)c.hasOwnPropert
y(l)&&(o[l]=c[l]);this.activeElement(o,s)},r.importAndActivateTemplate=function(
t,i,r){if(n.hasOwnProperty(t)){var a=e.querySelector('link[href="'+t+'"]');a.imp
ort?this.activeElement(e.importNode(a.import.querySelector("template").content,!
0),r):a.onload=function(){i.hasAttribute("active")&&this.activeElement(e.importN
ode(a.import.querySelector("template").content,!0),r)}.bind(this)}else{n[t]=!0;v
ar s=e.createElement("link");s.setAttribute("rel","import"),s.setAttribute("href
",t),s.onload=function(){i.hasAttribute("active")&&this.activeElement(e.importNo
de(s.import.querySelector("template").content,!0),r)}.bind(this),e.head.appendCh
ild(s)}},r.activateTemplate=function(t,i){var r=e.importNode(t.querySelector("te
mplate").content,!0);this.activeElement(r,i)},r.activeElement=function(t,e){for(
;this.activeRouteContent.firstChild;)this.activeRouteContent.removeChild(this.ac
tiveRouteContent.firstChild);this.activeRouteContent.appendChild(t),i("activate-
route-end",e,this),i("activate-route-end",e,e.route)},r.parseUrlPath=function(t)
{var e=t.split("/"),i="/"+e.splice(3,e.length-3).join("/"),r=i.split(/[\?#]/)[0]
,n=i.indexOf("#");if(-1!==n){var a=i.substring(n).split("?")[0];"#/"===a.substri
ng(0,2)?r=a.substring(1):"#!/"===a.substring(0,3)&&(r=a.substring(2))}return r},
r.testRoute=function(t,e,i,r){if("ignore"===i&&("/"===e.slice(-1)&&(e=e.slice(0,
-1)),"/"!==t.slice(-1)||r||(t=t.slice(0,-1))),r){if("/"!==t.charAt(0))return!1;t
=t.slice(1);var n="";if("/"===t.slice(-1))t=t.slice(0,-1);else{if("/i"!==t.slice
(-2))return!1;t=t.slice(0,-2),n="i"}return new RegExp(t,n).test(e)}if(t===e||"*"
===t)return!0;if(-1===t.indexOf("*")&&-1===t.indexOf(":"))return!1;var a=e.split
("/"),s=t.split("/");if(a.length!==s.length)return!1;for(var o=0;o<s.length;o++)
{var c=s[o];if(c!==a[o]&&"*"!==c&&":"!==c.charAt(0))return!1}return!0},r.routeAr
guments=function(t,e,i,r){var n={},a=e.split("/");if(!r)for(var s=t.split("/"),o
=0;o<s.length;o++){var c=s[o];":"===c.charAt(0)&&(n[c.substring(1)]=a[o])}var l=
i.indexOf("?"),h="";if(-1!==l){h=i.substring(l);var u=h.indexOf("#");-1!==u&&(h=
h.substring(0,u))}var v=i.indexOf("#/"),p=i.indexOf("#!/");if(-1!==v||-1!==p){va
r m="";m=i.substring(-1!==v?v:p),l=m.indexOf("?"),-1!==l&&(h=m.substring(l))}var
d=h.substring(1).split("&");1===d.length&&""===d[0]&&(d=[]);for(var f=0;f<d.len
gth;f++){var g=d[f],b=g.split("=");n[b[0]]=b.splice(1,b.length-1).join("=")}for(
var A in n){var E=n[A];n[A]="true"===E?!0:"false"===E?!1:isNaN(E)||""===E?decode
URIComponent(E):+E}return n},e.registerElement("app-router",{prototype:r})}(wind
ow,document); | |