!function(){"use strict";var a,b,c,d=function(a,b){return function(){return a.apply(b,arguments)}};a={},a.version="1.1.17","undefined"!=typeof module&&null!==module?(module.exports=a,a.KiRouter=a):("undefined"!=typeof define&&null!==define&&null!=define.amd&&define([],function(){return a}),this.KiRouter=a),a.router=function(){return new b},b=function(){function a(){this.addListener=d(this.addListener,this),this.fixTargetPort=d(this.fixTargetPort,this),this.fixUsername=d(this.fixUsername,this),this.targetHostSame=d(this.targetHostSame,this),this.targetAttributeIsCurrentWindow=d(this.targetAttributeIsCurrentWindow,this),this.metakeyPressed=d(this.metakeyPressed,this),this.findATag=d(this.findATag,this),this.leftMouseButton=d(this.leftMouseButton,this),this.blog=d(this.blog,this),this.disableEventDefault=d(this.disableEventDefault,this),this.checkIfOkToRender=d(this.checkIfOkToRender,this),this.checkIfHashBaseUrlRedirectNeeded=d(this.checkIfHashBaseUrlRedirectNeeded,this),this.updateUrl=d(this.updateUrl,this),this.hashBang=d(this.hashBang,this),this.renderUrlOrRedirect=d(this.renderUrlOrRedirect,this),this.nValue=d(this.nValue,this),this.attachClickListener=d(this.attachClickListener,this),this.renderUrl=d(this.renderUrl,this),this.getHashUrl=d(this.getHashUrl,this),this.attachLocationChangeListener=d(this.attachLocationChangeListener,this),this.renderInitialView=d(this.renderInitialView,this),this.hashbangRouting=d(this.hashbangRouting,this),this.transparentRouting=d(this.transparentRouting,this),this.historyApiRouting=d(this.historyApiRouting,this),this.addExceptionListener=d(this.addExceptionListener,this),this.addPostExecutionListener=d(this.addPostExecutionListener,this),this.find=d(this.find,this),this.exec=d(this.exec,this),this.add=d(this.add,this),this.log=d(this.log,this)}return a.prototype.routes=[],a.prototype.postExecutionListeners=[],a.prototype.exceptionListeners=[],a.prototype.debug=!1,a.prototype.previous=!1,a.prototype.paramVerifier=!1,a.prototype.renderCount=0,a.prototype.serverSupportsEscapedFragment=!1,a.prototype.log=function(){this.debug&&window.console&&console&&console.log&&(JSON.stringify?console.log("ki-router: "+JSON.stringify(arguments)):console.log(arguments))},a.prototype.add=function(a,b,d){return this.routes.push({route:new c(a),fn:b,urlPattern:a,metadata:d})},a.prototype.exec=function(a){var b,c,d,e,f,g,h,i,j,k;if(e=this.find(a)){this.log("Found route for",a," Calling function with params ",e.params),this.renderCount+=1;try{for(e.result=e.fn(e.params),j=this.postExecutionListeners,f=0,h=j.length;h>f;f++)d=j[f],d(e,this.previous)}catch(l){for(b=l,e.error=b,k=this.exceptionListeners,g=0,i=k.length;i>g;g++)c=k[g],c(e,this.previous);throw b}return this.previous=e,e}},a.prototype.find=function(a){var b,c,d,e,f;for(f=this.routes,d=0,e=f.length;e>d;d++)if(b=f[d],c=b.route.parse(a,this.paramVerifier))return{params:c,route:b.matchedRoute,fn:b.fn,urlPattern:b.urlPattern,path:a,metadata:b.metadata}},a.prototype.addPostExecutionListener=function(a){return this.postExecutionListeners.push(a)},a.prototype.addExceptionListener=function(a){return this.exceptionListeners.push(a)},a.prototype.pushStateSupport=history&&history.pushState,a.prototype.hashchangeSupport="onhashchange"in window,a.prototype.hashBaseUrl=!1,a.prototype.disableUrlUpdate=!1,a.prototype.fallbackRoute=!1,a.prototype.init=!1,a.prototype.initDone=!1,a.prototype.updateCount=0,a.prototype.historyApiRouting=function(){this.hashchangeSupport=!1,this.transparentRouting()},a.prototype.transparentRouting=function(){this.init=!0;try{this.attachClickListener(),this.attachLocationChangeListener(),this.renderInitialView()}finally{this.init=!1,this.initDone=!0}},a.prototype.hashbangRouting=function(){if(this.pushStateSupport=!1,!this.hashchangeSupport)throw new Error("No hashchange support!");this.transparentRouting()},a.prototype.renderInitialView=function(){var a,b;b=window.location.pathname,a=this.getHashUrl(),this.pushStateSupport?a&&this.find(a)&&(b=a):this.hashchangeSupport&&a&&(b=a),this.log("Rendering initial page"),this.renderUrl(b)},a.prototype.attachLocationChangeListener=function(){this.pushStateSupport?this.addListener(window,"popstate",function(a){return function(){var b;a.updateCount>0&&(b=window.location.pathname,a.log("Rendering popstate",b),a.renderUrl(b))}}(this)):this.hashchangeSupport&&this.addListener(window,"hashchange",function(a){return function(){var b;b=a.getHashUrl(),b&&(a.log("Rendering hashchange",b),a.renderUrl(b))}}(this))},a.prototype.getHashUrl=function(){return"#!"===window.location.hash.substring(0,2)?window.location.hash.substring(2):"#"===window.location.hash.substring(0,1)?window.location.hash.substring(1):void 0},a.prototype.renderUrl=function(a){var b;return(b=this.exec(a))?b:this.fallbackRoute?this.fallbackRoute(a):this.log("Could not resolve route for",a)},a.prototype.attachClickListener=function(){(this.pushStateSupport||this.hashchangeSupport)&&this.addListener(document,"click",function(a){return function(b){var c,d,e;b=b||window.event,e=b.target||b.srcElement,e&&(a.log("Checking if click event should be rendered"),c=a.findATag(e),a.checkIfOkToRender(b,c)&&(d=a.nValue(c.attributes.href),a.log("Click event passed all checks"),a.renderUrlOrRedirect(d,b)))}}(this))},a.prototype.nValue=function(a){return null!=a.value?a.value:a.nodeValue},a.prototype.renderUrlOrRedirect=function(a,b){this.checkIfHashBaseUrlRedirectNeeded()?(this.log("Using hashbang change to trigger rendering for",a),this.disableEventDefault(b),window.location.href=this.hashBaseUrl+"#"+this.hashBang()+a):this.exec(a)?(this.log("Rendered",a),this.disableEventDefault(b),this.updateUrl(a)):this.log("Letting browser render url because no matching route",a)},a.prototype.hashBang=function(){return this.serverSupportsEscapedFragment?"!":""},a.prototype.updateUrl=function(a){this.updateCount+=1,this.disableUrlUpdate||(this.pushStateSupport?history.pushState({},document.title,a):this.hashchangeSupport&&(window.location.hash=this.hashBang()+a))},a.prototype.checkIfHashBaseUrlRedirectNeeded=function(){return!this.pushStateSupport&&this.hashchangeSupport&&this.hashBaseUrl&&this.hashBaseUrl!==window.location.pathname},a.prototype.checkIfOkToRender=function(a,b){return this.blog("- A tag",b)&&this.blog("- Left mouse button click",this.leftMouseButton(a))&&this.blog("- Not meta keys pressed",!this.metakeyPressed(a))&&this.blog("- Target attribute is current window",this.targetAttributeIsCurrentWindow(b))&&this.blog("- Link host same as current window",this.targetHostSame(b))},a.prototype.disableEventDefault=function(a){a&&(a.preventDefault?a.preventDefault():a.returnValue=!1)},a.prototype.blog=function(a,b){return this.log(a+", result: "+b),b},a.prototype.leftMouseButton=function(a){return null!=a.which&&1===a.which||0===a.button},a.prototype.findATag=function(a){for(;a;){if("A"===a.tagName)return a;a=a.parentElement}return!1},a.prototype.metakeyPressed=function(a){return a.shiftKey||a.ctrlKey||a.altKey||a.metaKey},a.prototype.targetAttributeIsCurrentWindow=function(a){var b;return a.attributes.target?(b=this.nValue(a.attributes.target),-1!==["_blank","_parent"].indexOf(b)?!1:"_self"===b?!0:"_top"===b?window.self===window.top:b===window.name):!0},a.prototype.targetHostSame=function(a){var b,c;return b=window.location,c=this.fixTargetPort(a.port,a.protocol),a.hostname===b.hostname&&c===b.port&&a.protocol===b.protocol&&this.fixUsername(a.username)===this.fixUsername(b.username)&&a.password===a.password},a.prototype.fixUsername=function(a){return""===a?void 0:a},a.prototype.fixTargetPort=function(a,b){var c;return c={"http:":"80","https:":"443"},""!==a&&a===c[b]?"":a},a.prototype.addListener=function(a,b,c){if(a.addEventListener)return a.addEventListener(b,c,!1);if(a.attachEvent)return a.attachEvent("on"+b,c);throw new Error("addListener can not attach listeners!")},a}(),c=function(){function a(a){this.parse=d(this.parse,this);var b,c,e,f,g,h,i,j;for(this.keys=[],a=a.substring(1),h=[],f=a.split("/"),i=0,j=f.length;j>i;i++)g=f[i],c=g.match(/((:\w+)|\*)/),c?(b=c[0],"*"===b?(this.keys.push("splat"),g="(.*)"):(this.keys.push(b.substring(1)),g="([^/?#]+)")):g=g.replace(".","\\."),h.push(g);e="^/"+h.join("/")+"$",this.pattern=new RegExp(e)}return a.prototype.parse=function(a,b){var c,d,e,f,g,h,i,j;if(f=a.match(this.pattern)){for(c=0,g={},j=f.slice(1),h=0,i=j.length;i>h;h++){if(e=j[h],b&&!b(e))return!1;d=this.keys[c],c+=1,this.append(g,d,e)}return g}},a.prototype.append=function(a,b,c){var d;return(d=a[b])?(this.typeIsArray(d)||(a[b]=[d]),a[b].push(c)):a[b]=c},a.prototype.typeIsArray=function(a){return a&&"object"==typeof a&&a instanceof Array&&"number"==typeof a.length&&"function"==typeof a.splice&&!a.propertyIsEnumerable("length")},a}()}.call(this);