/* YUI 3.17.2 (build 9c3c78e) Copyright 2014 Yahoo! Inc. All rights reserved. Licensed under the BSD License. http://yuilibrary.com/license/ */ YUI.add("router",function(e,t){function c(){c.superclass.constructor.apply(this,arguments)}var n=e.HistoryHash,r=e.QueryString,i=e.Array,s=e.Lang,o=e.Object,u=e.config.win,a=[],f=[],l="ready";e.Router=e.extend(c,e.Base,{_regexURL:/^((?:[^\/#?:]+:\/\/|\/\/)[^\/]*)?([^?#]*)(\?[^#]*)?(#.*)?$/,_regexPathParam:/([:*])([\w\-]+)?/g,_regexUrlQuery:/\?([^#]*).*$/,_regexUrlOrigin:/^(?:[^\/#?:]+:\/\/|\/\/)[^\/]*/,initializer:function(t){var n=this;n._html5=n.get("html5"),n._params={},n._routes=[],n._url=n._getURL(),n._setRoutes(t&&t.routes?t.routes:n.get("routes")),n._html5?(n._history=new e.HistoryHTML5({force:!0}),n._historyEvents=e.after("history:change",n._afterHistoryChange,n)):n._historyEvents=e.on("hashchange",n._afterHistoryChange,u,n),n.publish(l,{defaultFn:n._defReadyFn,fireOnce:!0,preventable:!1}),n.once("initializedChange",function(){e.once("load",function(){setTimeout(function(){n.fire(l,{dispatched:!!n._dispatched})},20)})}),a.push(this)},destructor:function(){var e=i.indexOf(a,this);e>-1&&a.splice(e,1),this._historyEvents&&this._historyEvents.detach()},dispatch:function(){return this.once(l,function(){var e,t;this._ready=!0,this.upgrade()||(e=this._getRequest("dispatch"),t=this._getResponse(e),this._dispatch(e,t))}),this},getPath:function(){return this._getPath()},hasRoute:function(e){var t,n,r;return this._hasSameOrigin(e)?(this._html5||(e=this._upgradeURL(e)),t=this.removeQuery(e.replace(this._regexUrlOrigin,"")),r=this.match(t),r.length?(n=this.removeRoot(t),!!i.filter(r,function(e){return this._getParamValues(e,n)},this).length):!1):!1},match:function(e){var t=this.get("root");if(t){if(!this._pathHasRoot(t,e))return[];e=this.removeRoot(e)}return i.filter(this._routes,function(t){return e.search(t.regex)>-1})},param:function(e,t){return this._params[e]=t,this},removeRoot:function(e){var t=this.get("root"),n;e=e.replace(this._regexUrlOrigin,"");if(!t)return e;n=this.removeQuery(e);if(n===t||this._pathHasRoot(t,n))e=e.substring(t.length);return e.charAt(0)==="/"?e:"/"+e},removeQuery:function(e){return e.replace(/\?.*$/,"")},replace:function(e){return this._queue(e,!0)},route:function(t,n){n=i(arguments,1,!0);var r,o;return typeof t=="string"||s.isRegExp(t)?(n=i.flatten(n),r=[],o=this._getRegex(t,r),t={callbacks:n,keys:r,path:t,regex:o}):(n=i.flatten([t.callbacks||t.callback||[]].concat(n)),r=t.keys,o=t.regex||t.regexp,o||(r=[],o=this._getRegex(t.path,r)),t=e.merge(t,{callbacks:n,keys:r,path:t.path||o,regex:o})),this._routes.push(t),this},save:function(e){return this._queue(e)},upgrade:function(){if(!this._html5)return!1;var e=this._getHashPath();return e?(this.once(l,function(){this.replace(e)}),!0):!1},_decode:function(e){return decodeURIComponent(e.replace(/\+/g," "))},_dequeue:function(){var t=this,n;return YUI.Env.windowLoaded?(n=f.shift(),n?n():this):(e.once("load",function(){t._dequeue()}),this)},_dispatch:function(t,n){function a(f){var l,c,h;if(f)f==="route"?(s=[],a()):e.error(f);else if(l=s.shift())typeof l=="string"&&(c=l,l=r[c],l||e.error("Router: Callback not found: "+c,null,"router")),t.pendingCallbacks=s.length,l.call(r,t,n,a);else if(h=i.shift()){u=r._getParamValues(h,o);if(!u){a("route");return}t.params=u,t.route=h,t.pendingRoutes=i.length,s=h.callbacks.concat(),a()}}var r=this,i=r.match(t.path),s=[],o,u;return r._dispatching=r._dispatched=!0,!i||!i.length?(r._dispatching=!1,r):(o=r.removeRoot(t.path),a(),r._dispatching=!1,r._dequeue())},_getHashPath:function(e){return e||(e=n.getHash()),e&&e.charAt(0)==="/"?this._joinURL(e):""},_getOrigin:function(){var t=e.getLocation();return t.origin||t.protocol+"//"+t.host},_getParams:function(){return e.merge(this._params)},_getParamValues:function(e,t){var n,r,o;return n=i.map(e.regex.exec(t)||[],function(e){return e&&this._decode(e)||""},this),n.length-1!==e.keys.length?n:(o=i.hash(e.keys,n.slice(1)),r=i.every(e.keys,function(e){var t=this._params[e],n=o[e];return t&&n&&typeof n=="string"?(n=s.isRegExp(t)?t.exec(n):t.call(this,n,e),n!==!1&&s.isValue(n)?(o[e]=n,!0):!1):!0},this),r?o:!1)},_getPath:function(){var t=!this._html5&&this._getHashPath()||e.getLocation().pathname;return this.removeQuery(t)},_getPathRoot:function(){var t="/",n=e.getLocation().pathname,r;return n.charAt(n.length-1)===t?n:(r=n.split(t),r.pop(),r.join(t)+t)},_getQuery:function(){var t=e.getLocation(),r,i;return this._html5?t.search.substring(1):(r=n.getHash(),i=r.match(this._regexUrlQuery),r&&i?i[1]:t.search.substring(1))},_getRegex:function(e,t){return s.isRegExp(e)?e:e==="*"?/.*/:(e=e.replace(this._regexPathParam,function(e,n,r){return r?(t.push(r),n==="*"?"(.*?)":"([^/#?]+)"):n==="*"?".*":e}),new RegExp("^"+e+"$"))},_getRequest:function(e){return{path:this._getPath(),query:this._parseQuery(this._getQuery()),url:this._getURL(),router:this,src:e}},_getResponse:function(e){return{req:e}},_getRoutes:function(){return this._routes.concat()},_getURL:function(){var t=e.getLocation().toString();return this._html5||(t=this._upgradeURL(t)),t},_hasSameOrigin:function(t){var n=(t&&t.match(this._regexUrlOrigin)||[])[0];return n&&n.indexOf("//")===0&&(n=e.getLocation().protocol+n),!n||n===this._getOrigin()},_joinURL:function(e){var t=this.get("root");return e=this.removeRoot(e),e.charAt(0)==="/"&&(e=e.substring(1)),t&&t.charAt(t.length-1)==="/"?t+e:t+"/"+e},_normalizePath:function(e){var t="..",n="/",r,i,s,o,u,a;if(!e||e===n)return n;o=e.split(n),a=[];for(r=0,i=o.length;r=3),_instances:a,dispatch:function(){var e,t,n,r,i;for(e=0,t=a.length;e