/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

//>>built
define("dojo/router/RouterBase",["dojo/_base/declare","dojo/hash","dojo/topic"],function(r,q,t){function u(a,b,f){var d,c;var k=this.callbackQueue;var e=d=!1;b=[{stopImmediatePropagation:function(){d=!0},preventDefault:function(){e=!0},oldPath:b,newPath:f,params:a}];if(a instanceof Array)b=b.concat(a);else for(c in a)b.push(a[c]);a=0;for(c=k.length;a<c;++a)d||k[a].apply(null,b);return!e}var v=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^\s\s*/,"").replace(/\s\s*$/,
"")};return r(null,{_routes:null,_routeIndex:null,_started:!1,_currentPath:"",idMatch:/:(\w[\w\d]*)/g,idReplacement:"([^\\/]+)",globMatch:/\*(\w[\w\d]*)/,globReplacement:"(.+)",constructor:function(a){this._routes=[];this._routeIndex={};for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b])},register:function(a,b){return this._registerRoute(a,b)},registerBefore:function(a,b){return this._registerRoute(a,b,!0)},go:function(a,b){var f;if("string"!==typeof a)return!1;a=v(a);(f=this._handlePathChange(a))&&
q(a,b);return f},startup:function(a){if(!this._started){var b=this,f=q();this._started=!0;this._hashchangeHandle=t.subscribe("/dojo/hashchange",function(){b._handlePathChange.apply(b,arguments)});f?this._handlePathChange(f):this.go(a,!0)}},destroy:function(){this._hashchangeHandle&&this._hashchangeHandle.remove();this._routeIndex=this._routes=null},_handlePathChange:function(a){var b,f,d,c=this._routes,k=this._currentPath;if(!this._started||a===k)return e;var e=!0;var n=0;for(b=c.length;n<b;++n){var g=
c[n];if(d=g.route.exec(a)){if(g.parameterNames){var h=g.parameterNames;var l={};e=0;for(f=h.length;e<f;++e)l[h[e]]=d[e+1]}else l=d.slice(1);e=g.fire(l,k,a)}}e&&(this._currentPath=a);return e},_convertRouteToRegExp:function(a){a=a.replace(this.idMatch,this.idReplacement);a=a.replace(this.globMatch,this.globReplacement);return new RegExp("^"+a+"$")},_getParameterNames:function(a){var b=this.idMatch,f=this.globMatch,d=[],c;for(b.lastIndex=0;null!==(c=b.exec(a));)d.push(c[1]);null!==(c=f.exec(a))&&d.push(c[1]);
return 0<d.length?d:null},_indexRoutes:function(){var a,b=this._routes;var f=this._routeIndex={};var d=0;for(a=b.length;d<a;++d){var c=b[d];f[c.route]=d}},_registerRoute:function(a,b,f){var d,c,k=this,e=this._routes,n=this._routeIndex;var g=this._routeIndex[a];(d="undefined"!==typeof g)&&(c=e[g]);c||(c={route:a,callbackQueue:[],fire:u});var h=c.callbackQueue;"string"==typeof a&&(c.parameterNames=this._getParameterNames(a),c.route=this._convertRouteToRegExp(a));f?h.unshift(b):h.push(b);d||(g=e.length,
n[a]=g,e.push(c));var l=!1;return{remove:function(){var p;if(!l){var m=0;for(p=h.length;m<p;++m)h[m]===b&&h.splice(m,1);0===h.length&&(e.splice(g,1),k._indexRoutes());l=!0}},register:function(p,m){return k.register(a,p,m)}}}})});