-
Notifications
You must be signed in to change notification settings - Fork 8
/
navigator-js.min.js
24 lines (21 loc) · 33.8 KB
/
navigator-js.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
! navigator-js - v0.4.3 - 2013-11-09
* Copyright (c) 2013 Bigger Boat;
*/
this.navigatorjs=this.navigatorjs||{},function(){var t=function(){this._responders=[]};t.prototype={getLength:function(){return this._responders.length},isBusy:function(){return this.getLength()>0},hasResponder:function(t){return-1!=this._responders.indexOf(t)},addResponder:function(t){this._responders.push(t)},addResponders:function(t){t&&t instanceof Array&&t.length&&(this._responders=this._responders.concat(t))},takeOutResponder:function(t){var a=this._responders.indexOf(t);return-1!=a?(this._responders.splice(a,1),!0):!1},reset:function(){this._responders.length>0&&console.warn("Resetting too early? Still have responders marked for asynchronous tasks"),this._responders=[]}},navigatorjs.AsynchResponders=t}(),this.navigatorjs=this.navigatorjs||{},function(){var t=function(t){navigatorjs.utils.AutoBind(this,this),this._initialize(t)};t.MAX_HISTORY_LENGTH=100,t.DIRECTION_BACK=-1,t.DIRECTION_NORMAL=0,t.DIRECTION_FORWARD=1,t.prototype={_navigator:null,_history:null,_historyPosition:0,_navigationDirection:t.DIRECTION_NORMAL,maxLength:t.MAX_HISTORY_LENGTH,_initialize:function(t,a){a&&(this.maxLength=a.maxLength||this.maxLength),this._history=[],this._navigator=t,this._navigator.on(navigatorjs.NavigatorEvent.STATE_CHANGED,this._handleStateChange)},back:function(a){return this._historyPosition==this._history.length-1?!1:(a=a||1,this._historyPosition=Math.min(this._history.length-1,this._historyPosition+a),this._navigationDirection=t.DIRECTION_BACK,this._navigateToCurrentHistoryPosition(),!0)},forward:function(a){return 0===this._historyPosition?!1:(a=a||1,this._historyPosition=Math.max(0,this._historyPosition-a),this._navigationDirection=t.DIRECTION_FORWARD,this._navigateToCurrentHistoryPosition(),!0)},getPreviousState:function(t){if(0===this._history.length||this._historyPosition==Math.max(0,this._history.length-1))return null;t=t||1;var a=Math.min(this._history.length-1,Math.max(0,this._historyPosition+t));return this._history[a]},getNextState:function(t){if(0===this._history.length||0===this._historyPosition)return null;t=t||1;var a=Math.max(0,this._historyPosition-t);return this._history[a]},getCurrentState:function(){return this._history[this._historyPosition]||null},clearHistory:function(){this._history=[],this._historyPosition=1},all:function(){return this._history},getStateByPosition:function(t){return 0>t||t>this._history.length-1?null:this._history[t]},getPositionByState:function(t){return this.getPositionByPath(t.getPath())},getPositionByPath:function(t){for(var a=this.getLength(),i=0;a>i;i++)if(this._history[i].getPath()==t)return i;return!1},getLength:function(){return this._history.length},_navigateToCurrentHistoryPosition:function(){var t=this._history[this._historyPosition];this._navigator.request(t)},_handleStateChange:function(a,i){var n=i.state;switch(this._navigationDirection){case t.DIRECTION_BACK:this._navigationDirection=t.DIRECTION_NORMAL;break;case t.DIRECTION_NORMAL:this._history.splice(0,this._historyPosition),this._history.unshift(n),this._historyPosition=0,this._history.length=Math.min(this._history.length,this.maxLength);break;case t.DIRECTION_FORWARD:this._navigationDirection=t.DIRECTION_NORMAL}}},navigatorjs.History=t}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.NavigationBehaviors={},this.navigatorjs.NavigationBehaviors.SHOW="show",this.navigatorjs.NavigationBehaviors.HIDE="hide",this.navigatorjs.NavigationBehaviors.UPDATE="update",this.navigatorjs.NavigationBehaviors.SWAP="swap",this.navigatorjs.NavigationBehaviors.VALIDATE="validate",this.navigatorjs.NavigationBehaviors.AUTO="auto",this.navigatorjs.NavigationBehaviors.ALL_AUTO=["show","update","swap","validate"],this.navigatorjs=this.navigatorjs||{},this.navigatorjs.NavigationResponderBehaviors={},this.navigatorjs.NavigationResponderBehaviors.IHasStateInitialization={name:"IHasStateInitialization",methods:["initializeByNavigator"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateValidation={name:"IHasStateValidation",methods:["validate"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateValidationAsync={name:"IHasStateValidationAsync","extends":["IHasStateValidation"],methods:["prepareValidation"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateValidationOptional={name:"IHasStateValidationOptional","extends":["IHasStateValidation"],methods:["willValidate"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateValidationOptionalAsync={name:"IHasStateValidationOptionalAsync","extends":["IHasStateValidationAsync","IHasStateValidationOptional"],methods:[]},this.navigatorjs.NavigationResponderBehaviors.IHasStateRedirection={name:"IHasStateRedirection","extends":["IHasStateValidation"],methods:["redirect"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateSwap={name:"IHasStateSwap",methods:["willSwapToState","swapOut","swapIn"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateTransition={name:"IHasStateTransition",methods:["transitionIn","transitionOut"]},this.navigatorjs.NavigationResponderBehaviors.IHasStateUpdate={name:"IHasStateUpdate",methods:["updateState"]},this.navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface=function(t,a){if(void 0==t.navigatorBehaviors||!t.navigatorBehaviors instanceof Array)return!1;var i,n,e=navigatorjs.NavigationResponderBehaviors.getInterfaceInheritanceChain(a),s=navigatorjs.NavigationResponderBehaviors.getInterfaceMethods(e),r=s.length;for(i=0;r>i;i++)if(n=s[i],void 0==t[n]||"function"!=typeof t[n])return!1;return!0},this.navigatorjs.NavigationResponderBehaviors.getInterfaceInheritanceChain=function(t,a){var i,n,e,s,r=a||[],o=navigatorjs.NavigationResponderBehaviors[t];if(void 0==o||"object"!=typeof o)return r;if(r.push(t),i=o["extends"],void 0==i)return r;for(s=i.length,e=0;s>e;e++)n=i[e],-1==r.indexOf(n)&&navigatorjs.NavigationResponderBehaviors.getInterfaceInheritanceChain(n,r);return r},this.navigatorjs.NavigationResponderBehaviors.getInterfaceMethods=function(t){if(void 0==t||!t instanceof Array)return[];var a,i,n,e,s,r,o,h=[],g=t.length,v=[];for(i=0;g>i;i++)a=t[i],navigatorjs.NavigationResponderBehaviors.getInterfaceInheritanceChain(a,h);for(g=h.length,i=0;g>i;i++)if(a=h[i],n=navigatorjs.NavigationResponderBehaviors[a],e=n.methods,void 0!=n&&"object"==typeof n&&void 0!=e&&e instanceof Array)for(r=e.length,s=0;r>s;s++)o=e[s],-1==v.indexOf(o)&&v.push(o);return v},this.navigatorjs=this.navigatorjs||{},function(){var t=function(t){this._path="",t instanceof Array?this.setSegments(t):this.setPath(t||"")};t.make=function(t){return t instanceof navigatorjs.NavigationState?t:new navigatorjs.NavigationState(t)},t.prototype={setPath:function(t){return this._path="/"+t.toLowerCase()+"/",this._path=this._path.replace(RegExp("[^-_/A-Za-z0-9* ]","g"),""),this._path=this._path.replace(RegExp("/+","g"),"/"),this._path=this._path.replace(/\s+/g,"-"),this},getPath:function(){return this._path},getPathRegex:function(){var t,a,i=this.getSegments(),n="/",e=i.length;for(a=0;e>a;a++)t=i[a],"**"==t?n+="(.*)":"*"==t?n+="([^/]*)/":n=n+"("+t+"|\\*|\\*\\*)/";return RegExp(n)},setSegments:function(t){this.setPath(t.join("/"))},getSegments:function(){var t=this._path.split("/");return t.pop(),t.shift(),t},getSegment:function(t){return this.getSegments()[t]},getFirstSegment:function(){return this.getSegment(0)},getLastSegment:function(){var t=this.getSegments();return this.getSegment(t.length-1)},contains:function(a){if(a instanceof Array)return this._containsStateInArray(a);var i=a,n=t.make(i),e=n.getSegments(),s=this.getSegments(),r=this.getPath().match(n.getPathRegex()),o=n.getPath().match(this.getPathRegex()),h=r&&0==r.index?!0:!1,g=o&&0==o.index?!0:!1,v=n.getPath().match(/\*\*/g),u=v?v.length:0,l=e.length>s.length+u,c=s.length>e.length;return(h||g&&c)&&!l},_containsStateInArray:function(t){var a,i,n=t.length;for(a=0;n>a;a++)if(i=t[a],this.contains(i))return!0;return!1},equals:function(a){if(a instanceof Array)return this._equalsStateInArray(a);var i=a,n=t.make(i),e=this.subtract(n)||n.subtract(this);return null===e?!1:0===e.getSegments().length},_equalsStateInArray:function(t){var a,i,n=t.length;for(a=0;n>a;a++)if(i=t[a],this.equals(i))return!0;return!1},subtract:function(a){var i,n=t.make(a);return this.contains(n)?(i=this.getPath().replace(n.getPathRegex(),""),new navigatorjs.NavigationState(i)):null},append:function(a){var i=a;return a instanceof t&&(i=a.getPath()),this.setPath(this._path+i)},prepend:function(a){var i=a;return a instanceof t&&(i=a.getPath()),this.setPath(i+this._path)},hasWildcard:function(){return-1!=this.getPath().indexOf("/*/")},mask:function(a){var i,n=t.make(a),e=this.getSegments(),s=n.getSegments(),r=Math.min(e.length,s.length);for(i=0;r>i;i++)"*"===e[i]&&(e[i]=s[i]);return new navigatorjs.NavigationState(e)},clone:function(){return new navigatorjs.NavigationState(this._path)}},navigatorjs.NavigationState=t}(),this.navigatorjs=this.navigatorjs||{},function(){var t=null,a={},i={},n={},e={},s=null,r=null,o=null,h=!1,g=null,v=null,u=null,l=null,c=null,d=null,f=null,p=null,S=null,_=null,I=!1,j=!1,N=!1,m=0,y=function(a,i,n,e){if(!w(a,i,n,e)){var s,r,o=navigatorjs.NavigationState.make(n).getPath();switch(e){case navigatorjs.NavigationBehaviors.SHOW:r="IHasStateTransition",s=g.showByPath[o]=g.showByPath[o]||[];break;case navigatorjs.NavigationBehaviors.HIDE:r="IHasStateTransition",s=g.hideByPath[o]=g.hideByPath[o]||[];break;case navigatorjs.NavigationBehaviors.VALIDATE:r="IHasStateValidation",s=g.validateByPath[o]=g.validateByPath[o]||[];break;case navigatorjs.NavigationBehaviors.UPDATE:r="IHasStateUpdate",s=g.updateByPath[o]=g.updateByPath[o]||[];break;case navigatorjs.NavigationBehaviors.SWAP:r="IHasStateSwap",s=g.swapByPath[o]=g.swapByPath[o]||[];break;default:throw Error("Unknown behavior: "+e)}if(!navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(i,r))throw Error("Responder "+i+" should implement "+r+" to respond to "+e);if(a){if(!(0>s.indexOf(i)))return;s.push(i),void 0==i.__navigatorjs&&(m++,i.__navigatorjs={id:m},v[i.__navigatorjs.id]=i),u[i.__navigatorjs.id]=u[i.__navigatorjs.id]||navigatorjs.transition.TransitionStatus.UNINITIALIZED}else{var h=s.indexOf(i);if(!(h>=0))return;s.splice(h,1),delete u[i.__navigatorjs.id],delete v[i.__navigatorjs.id],"IHasStateSwap"==r&&g.swappedBefore[i]&&delete g.swappedBefore[i]}t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,{statusByResponderID:u,respondersByID:v})}},w=function(t,a,i,n){if(!a)throw Error("add: responder is null");var e,s;if(i instanceof Array){for(s=i.length,e=0;s>e;e++)y(t,a,i[e],n);return!0}if(n=n||navigatorjs.NavigationBehaviors.AUTO,n==navigatorjs.NavigationBehaviors.AUTO){for(s=navigatorjs.NavigationBehaviors.ALL_AUTO.length,e=0;s>e;e++)try{y(t,a,i,navigatorjs.NavigationBehaviors.ALL_AUTO[e])}catch(r){}return!0}return!1},T=function(t,a){var i,n,e,s,r,o,h,v=g.all.length;for(i=0;v>i;i++){r=g.all[i];for(h in r)if(t.equals(h)){if(!a)return!0;for(o=r[h],e=o.length,n=0;e>n;n++)if(s=o[n],navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(s,a))return!0;return!0}}return!1},A=function(a){if(null!=a){var i,n,e,r;if(i=navigatorjs.NavigationState.make(a),i.hasWildcard()&&(i=i.mask(s||o)),!s||s.getPath()!=i.getPath()){if(l)for(n in l)if(e=new navigatorjs.NavigationState(n),e.equals(i))return r=navigatorjs.NavigationState.make(l[n]),A(r),void 0;t.trigger(navigatorjs.NavigatorEvent.STATE_REQUESTED,{state:i}),_=null,P(i)}}},P=function(t,a){if(!o)throw Error("No default state set. Call start() before the first request!");if(t.getPath()!=o.getPath()||o.hasWildcard())if(N&&j&&!I)B(t);else if(D(t,!0,a))B(t);else if(p&&p.isBusy());else if(a&&N);else if(_)A(_);else if(s)R(s);else{if(t.hasWildcard())throw Error("Check wildcard masking: "+t.getPath());if(!o)throw Error("First request is invalid: "+t.getPath());B(o)}else B(o)},B=function(t){I=!1,j=!1,r=s,s=t,R(s),a.startTransition()},R=function(a){a!=r&&t.trigger(navigatorjs.NavigatorEvent.STATE_CHANGED,{statusByResponderID:u,respondersByID:v,state:s})};a.startTransition=function(){h=!0,t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STARTED),c=new navigatorjs.AsynchResponders,c.addResponders(a.transitionOut()),c.isBusy()||a.performUpdates()},a.transitionOut=function(){var a,n,e,s=O(),r=[];H(s);for(a in u)n=v[a],-1==s.indexOf(n)&&navigatorjs.transition.TransitionStatus.HIDDEN<u[a]&&u[a]<navigatorjs.transition.TransitionStatus.DISAPPEARING&&navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(n,"IHasStateTransition")&&(u[a]=navigatorjs.transition.TransitionStatus.DISAPPEARING,r.push(n),n.transitionOut(new navigatorjs.transition.TransitionCompleteDelegate(n,navigatorjs.transition.TransitionStatus.HIDDEN,navigatorjs.NavigationBehaviors.HIDE,this,i).call));for(e=r.length;--e>=0;)u[r[e].__navigatorjs.id]==navigatorjs.transition.TransitionStatus.HIDDEN&&r.splice(e,1);return r.length>0&&t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,{statusByResponderID:u,respondersByID:v}),r},a.performUpdates=function(){c.reset();var t,i,n,e,r;for(t in g.updateByPath)if(i=new navigatorjs.NavigationState(t),s.contains(i))for(n=g.updateByPath[t],H(n),e=0;n.length>e;e++)r=n[e],r.updateState(s.subtract(i),s);a.startTransitionIn()},a.startTransitionIn=function(){d=new navigatorjs.AsynchResponders,d.addResponders(a.transitionIn()),d.isBusy()||a.startSwapOut()},a.transitionIn=function(){var a,n,e,s=O(),r=[];for(H(s),e=0;s.length>e;e++)a=s[e],n=u[a.__navigatorjs.id],(navigatorjs.transition.TransitionStatus.APPEARING>n||n>navigatorjs.transition.TransitionStatus.SHOWN)&&(u[a.__navigatorjs.id]=navigatorjs.transition.TransitionStatus.APPEARING,r.push(a),a.transitionIn(new navigatorjs.transition.TransitionCompleteDelegate(a,navigatorjs.transition.TransitionStatus.SHOWN,navigatorjs.NavigationBehaviors.SHOW,this,i).call));for(e=r.length;--e>=0;)u[r[e].__navigatorjs.id]==navigatorjs.transition.TransitionStatus.SHOWN&&r.splice(e,1);return r.length>0&&t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,{statusByResponderID:u,respondersByID:v}),r},a.startSwapOut=function(){f=new navigatorjs.AsynchResponders,f.addResponders(a.swapOut()),f.isBusy()||a.swapIn()},a.swapOut=function(){d.reset();var a,n,e,r,o,h,l=[];for(a in g.swapByPath)if(n=new navigatorjs.NavigationState(a),s.contains(n))for(e=g.swapByPath[a],H(e),o=0;e.length>o;o++)r=e[o],g.swappedBefore[r]&&(h=s.subtract(n),r.willSwapToState(h,s)&&(u[r.__navigatorjs.id]=navigatorjs.transition.TransitionStatus.SWAPPING,l.push(r),r.swapOut(new navigatorjs.transition.TransitionCompleteDelegate(r,navigatorjs.transition.TransitionStatus.SHOWN,navigatorjs.NavigationBehaviors.SWAP,this,i).call)));for(o=l.length;--o>=0;)u[l[o].__navigatorjs.id]==navigatorjs.transition.TransitionStatus.SHOWN&&l.splice(o,1);return l.length>0&&t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,{statusByResponderID:u,respondersByID:v}),l},a.swapIn=function(){f.reset();var t,i,n,e,r,o;for(t in g.swapByPath)if(i=new navigatorjs.NavigationState(t),s.contains(i))for(n=g.swapByPath[t],H(n),o=0;n.length>o;o++)e=n[o],r=s.subtract(i),e.willSwapToState(r,s)&&(g.swappedBefore[e]=!0,e.swapIn(r,s));a.finishTransition()},a.finishTransition=function(){h=!1,t.trigger(navigatorjs.NavigatorEvent.TRANSITION_FINISHED)},i.notifyComplete=function(i,n,e){u[i.__navigatorjs.id]&&(u[i.__navigatorjs.id]=n,t.trigger(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,{statusByResponderID:u,respondersByID:v}));var s,r;switch(e){case navigatorjs.NavigationBehaviors.HIDE:s=c,r=a.performUpdates;break;case navigatorjs.NavigationBehaviors.SHOW:s=d,r=a.startSwapOut;break;case navigatorjs.NavigationBehaviors.SWAP:s=f,r=a.swapIn;break;default:throw Error("Don't know how to handle notification of behavior "+e)}s.isBusy()&&(s.takeOutResponder(i),s.isBusy()||r())},e.hasResponder=function(t){if(u[t.__navigatorjs.id])return!0;var a,i,n,e;for(n=0;g.all.length>n;n++)for(a=g.all[n],e=0;a.length>e;e++)if(i=a[e],i.indexOf(t)>=0)return!0;return!1},e.getStatusByResponderID=function(){return u},e.getRespondersByID=function(){return v},e.getStatus=function(t){return u[t.__navigatorjs.id]},e.getKnownPaths=function(){var t,a={},i=[];a[o.getPath()]=!0;for(t in g.showByPath)a[new navigatorjs.NavigationState(t).getPath()]=!0;for(t in a)i.push(t);return i.sort(),i},n.notifyValidationPrepared=function(t,a,i){p.takeOutResponder(t)&&(t.validate(a,i)?j=!0:(I=!0,navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(t,"IHasStateRedirection")&&(_=t.redirect(a,i))),I||!p.isBusy()?(p.reset(),S=[],P(i,!1)):E())};var E=function(){if(0==S.length)return!1;var t=S.shift();return t.responder.prepareValidation(t.remainderState,t.unvalidatedState,t.callOnPrepared),!0},D=function(t,a,i){var e,s,r,h,v,u,l,a=void 0==a?!0:a,i=void 0==i?!0:i,c=t,d=null,f=!1,m=!1;if(c.hasWildcard())return!1;if(c.equals(o))return!0;i&&(N=!1,I=!1,j=!1,p=new navigatorjs.AsynchResponders,S=[]),e=C(c);for(s in g.validateByPath)if(r=new navigatorjs.NavigationState(s),c.contains(r)){if(h=c.subtract(r),v=g.validateByPath[s],H(v),i&&T(t))for(u=0;v.length>u;u++)l=v[u],(!navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(l,"IHasStateValidationOptionalAsync")||l.willValidate(h,c))&&navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(l,"IHasStateValidationAsync")&&(N=!0,d=new navigatorjs.transition.ValidationPreparedDelegate(l,h,c,this,n).call,p.addResponder(l),S.push({responder:l,remainderState:h,unvalidatedState:c,callOnPrepared:d}));for(u=0;v.length>u;u++)if(l=v[u],!navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(l,"IHasStateValidationAsync")&&(!navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(l,"IHasStateValidationOptional")||l.willValidate(h,c))){if(!l.validate(h,c)||!T(c))return f=!0,a&&navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(l,"IHasStateRedirection")&&(_=l.redirect(h,c)),!1;m=!0}}return N&&E()?!1:p.isBusy()?!1:f||I?!1:m||j?!0:e},C=function(t){var a;for(a in g.showByPath)if(new navigatorjs.NavigationState(a).equals(t))return!0;return!1},O=function(){var t,a,i,n=U(g.showByPath,s),e=U(g.hideByPath,s);for(t=0;e.length>t;t++)a=e[t],i=n.indexOf(a),i>=0&&n.splice(i,1);return n},H=function(t){var a,i;for(a=0;t.length>a;a++)i=t[a],u[i.__navigatorjs.id]==navigatorjs.transition.TransitionStatus.UNINITIALIZED&&navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(i,"IHasStateInitialization")&&(i.initializeByNavigator(),u[i.__navigatorjs.id]=navigatorjs.transition.TransitionStatus.INITIALIZED)},U=function(t,a){var i,n=[];for(i in t)a.contains(new navigatorjs.NavigationState(i))&&(n=n.concat(t[i]));return n},k=function(){navigatorjs.utils.AutoBind(this,this),t=$({}),s=null,g=new navigatorjs.ResponderLists,v={},u={},l=null,m=0};k.prototype={add:function(t,a,i){y(!0,t,a,i)},remove:function(t,a,i){y(!1,t,a,i)},registerRedirect:function(t,a){l=l||{},l[navigatorjs.NavigationState.make(t).getPath()]=navigatorjs.NavigationState.make(a)},start:function(t,a){o=navigatorjs.NavigationState.make(t||""),this.request(a||o)},request:function(t){A(t)},getCurrentState:function(){return s?s.clone():o?o.clone():null},isTransitioning:function(){return h},on:function(a,i){return t.on(a,i),this},off:function(a,i){return t.off(a,i),this},logResponders:function(){}},navigatorjs.Navigator=k}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.NavigatorEvent={},this.navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED="TRANSITION_STATUS_UPDATED",this.navigatorjs.NavigatorEvent.STATE_REQUESTED="STATE_REQUESTED",this.navigatorjs.NavigatorEvent.STATE_CHANGED="STATE_CHANGED",this.navigatorjs.NavigatorEvent.TRANSITION_STARTED="TRANSITION_STARTED",this.navigatorjs.NavigatorEvent.TRANSITION_FINISHED="TRANSITION_FINISHED",this.navigatorjs=this.navigatorjs||{},function(){var t=function(){this.validateByPath={},this.updateByPath={},this.swapByPath={},this.showByPath={},this.hideByPath={},this.swappedBefore={},this.all=[this.validateByPath,this.updateByPath,this.swapByPath,this.showByPath,this.hideByPath,this.swappedBefore]};t.prototype={validateByPath:null,updateByPath:null,swapByPath:null,showByPath:null,hideByPath:null,swappedBefore:null,all:null,toString:function(){var t,a,i,n,e="ResponderLists [";for(t in this)if(a=this[t],this.all.indexOf(a)>-1){i=[];for(n in a)i.push("["+n+" = "+a[n]+"]");e+="\n ["+t+": "+i.join(", ")+"], "}return e+="]"}},navigatorjs.ResponderLists=t}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.features=this.navigatorjs.features||{},function(){var t=null,a='<div class="debugConsole">Path: <input type="text" class="path" /><div class="pathRenderer"></div><div class="responders"><div class="names"></div><div class="status"></div></div></div>',i=!0,n=RegExp("[-_/A-Za-z0-9]"),e=null,s=null,r=null,o=null,h=null,g=null,v=null,u=null,l=function(a){switch(a.which){case 13:return a.preventDefault(),t.request(s.val()),void 0;case 8:case 0:return}var i=String.fromCharCode(a.which);n.test(i)||a.preventDefault(),f()},c=function(t){switch(String.fromCharCode(t.which)){case"~":case"$":case"`":i=!i,e.css({display:i?"":"none"})}},d=function(t){var a=$(t.target).data("responder-id");console.log("Responder",v[a])},f=function(){r.text(s.val()),s.css({width:r.width()})},p=function(t,a){v=a.respondersByID,u=a.statusByResponderID,S()},S=function(){var a,i,n,e,r=t.getCurrentState(),o="",l="";if(r){s.val(r.getPath()),f();for(a in v)i=v[a],n=u[a],(navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(i,"IHasStateTransition")||navigatorjs.NavigationResponderBehaviors.implementsBehaviorInterface(i,"IHasStateInitialization"))&&(o+='<span data-responder-id="'+a+'">'+_(i)+"</span><br />",e=I(n),l+='<span style=" color:'+e+'; font-weight:bold;" data-responder-id="'+a+'">'+navigatorjs.transition.TransitionStatus.toString(n)+"</span><br />");h.html(o),g.html(l)}},_=function(t){var a=""+t;if("[object Object]"==a&&t.$el){var i=t.$el.prop("tagName").toLowerCase(),n=t.$el.attr("class").split(" ").join(".");a=i+"."+n}return a},I=function(t){var a="";switch(t){case navigatorjs.transition.TransitionStatus.UNINITIALIZED:a="#AAAAAA";break;case navigatorjs.transition.TransitionStatus.INITIALIZED:a="#FFFFFF";break;case navigatorjs.transition.TransitionStatus.HIDDEN:a="#FF0000";break;case navigatorjs.transition.TransitionStatus.APPEARING:case navigatorjs.transition.TransitionStatus.DISAPPEARING:a="#FFFF00";break;case navigatorjs.transition.TransitionStatus.SHOWN:a="#00FF00"}return a},j=function(i){t=i,e=$(a),s=e.find(".path"),r=e.find(".pathRenderer"),o=e.find(".responders"),h=o.find(".names"),g=o.find(".status"),e.css({backgroundColor:"#000000",color:"#AAAAAA",fontFamily:"Arial",fontSize:12,padding:5}),s.css({color:"#00FF00",backgroundColor:"transparent",fontFamily:"Arial",fontSize:12,minWidth:200,border:0}),r.attr("style",s.attr("style")),r.css({position:"absolute",height:0,overflowY:"hidden"}),h.css({display:"inline-block",color:"#FF9900",marginRight:15}),g.css({display:"inline-block"}),s.on("keypress",l),$(window).on("keypress",c),h.on("click",d),g.on("click",d),t.on(navigatorjs.NavigatorEvent.STATE_CHANGED,p),t.on(navigatorjs.NavigatorEvent.TRANSITION_STATUS_UPDATED,p)};j.prototype={get$El:function(){return e}},navigatorjs.features.DebugConsole=j}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.integration=this.navigatorjs.integration||{},function(){var t=function(t,a){this._navigator=t,this._injector=a,this._commandsByState={},this._verifiedCommandClasses={},this.initialize()};t.prototype={navigatorBehaviors:["IHasStateValidationOptional","IHasStateUpdate"],_navigator:null,_injector:null,_commandsByState:null,_verifiedCommandClasses:null,initialize:function(){},mapCommand:function(t,a,i,n){var e=void 0==i?!1:i,s=void 0==n?!1:n,r=navigatorjs.NavigationState.make(t),o=this._commandsByState[r.getPath()]||[];if(this._commandsByState[r.getPath()]=o,this._navigator.add(this,r),this._hasCommand(o,a))throw Error("Already mapped "+a+" to state "+r.getPath());this._verifyCommandClass(a),o.push({CommandClass:a,state:r,exactMatch:e,oneShot:s})},unmapCommand:function(t,a){var i,n,e=navigatorjs.NavigationState.make(t),s=this._commandsByState[e.getPath()]||[];for(this._commandsByState[e.getPath()]=s,this._navigator.remove(this,e),i=s.length;--i>=0;)if(n=s[i],n.CommandClass==a)return s.splice(i,1),void 0},willValidate:function(t,a){return this.validate(t,a)},validate:function(t,a){var i,n,e,s,r,o;for(i in this._commandsByState)if(n=navigatorjs.NavigationState.make(i),a.contains(n))for(e=this._commandsByState[i],s=a.equals(n),r=e.length;--r>=0;)if(o=e[r],s||!o.exactMatch)return!0;return!1},updateState:function(t,a){var i,n,e,s,r,o,h;for(i in this._commandsByState)if(n=navigatorjs.NavigationState.make(i),a.contains(n))for(e=this._commandsByState[i],s=a.equals(n),r=e.length;--r>=0;)o=e[r],(s||!o.exactMatch)&&(this._injector.map("fullState").toValue(a),this._injector.map("truncatedState").toValue(a.subtract(o.state)),h=new o.CommandClass({injector:this._injector}),h.execute(),this._injector.unmap("fullState"),this._injector.unmap("truncatedState"),o.oneShot&&this.unmapCommand(o.state,o.CommandClass))},_hasCommand:function(t,a){var i,n,e=t.length;for(i=0;e>i;i++)if(n=t[i],n.CommandClass==a)return!0;return!1},_verifyCommandClass:function(t){if(!this._verifiedCommandClasses[t]){if(void 0===t.prototype.execute)throw Error("Command doesn't implement an execute method - "+t);this._verifiedCommandClasses[t]=!0}}},navigatorjs.integration.StateCommandMap=t}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.integration=this.navigatorjs.integration||{},function(){var t,a,i,n,e=function(e){navigatorjs.utils.AutoBind(this,this),t=!1,a="/",i=e,n=!1};e.prototype={supportsPushState:!!(window&&window.history&&window.history.pushState),usePushState:function(i){if(n)throw Error("Cannot switch to using push states after start was called");t=this.supportsPushState,a=i||a,this._redirectPushStateOrHashOnDeeplink()},isUsingPushState:function(){return t},_redirectPushStateOrHashOnDeeplink:function(){var t=this.parsePushStateUrl(window.location.pathname),i=this.parseHashUrl(window.location.hash);this.supportsPushState&&""==t&&""!=i?window.history.replaceState(null,"",new navigatorjs.NavigationState(a+i).getPath()):this.supportsPushState||""==t||(window.location.href=a+"#/"+t)},start:function(){if(n)throw Error("Already started");n=!0,this._addListeners()},_addListeners:function(){t?$(window).on("popstate",this._onUrlChange):$(window).on("hashchange",this._onUrlChange);var a=navigatorjs.NavigatorEvent.STATE_CHANGED;i.on(a,this._onStateChanged)},_removeListeners:function(){$(window).off("popstate",this._onUrlChange),$(window).off("hashchange",this._onUrlChange)},setUrl:function(i){var n,e=this.getUrlState();t?(n=new navigatorjs.NavigationState(a+i),n.equals(e)?window.history.replaceState(null,"",n.getPath()):window.history.pushState(null,"",n.getPath())):(n=new navigatorjs.NavigationState(i),n.equals(e)||(window.location.hash=n.getPath()))},getRawUrl:function(){return t?this.parsePushStateUrl(window.location.pathname):this.parseHashUrl(window.location.hash)},getUrlState:function(){return new navigatorjs.NavigationState(this.getRawUrl())},_onStateChanged:function(){this.setUrl(i.getCurrentState().getPath())},_onUrlChange:function(){i.request(this.getUrlState())},resetUrl:function(){this.setUrl("")},parseHashUrl:function(t){return t.replace(/^#|$/g,"")},parsePushStateUrl:function(t){return t.replace(a,"")},dispose:function(){this._removeListeners()}},navigatorjs.integration.StateUrlSyncer=e}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.integration=this.navigatorjs.integration||{},function(){function t(t){var a,i=new navigatorjs.integration.ViewRecipe,n=t.length;for(a=0;n>a;a++)i.addState(navigatorjs.NavigationState.make(t[a]));return e.push(i),i}function a(t,a){var s,r,o,h,g,v,u,l=a.state,c=e.length;for(s=0;c>s;s++)for(r=e[s],o=r.getStates(),v=o.length,h=0;v>h;h++)g=o[h],l.contains(g)&&(u=r.getViewInstance(),u.navigatorBehaviors instanceof Array&&(i(r),n.add(u,g)))}function i(t){if(!t.isInstantiated()||!$.contains(document.documentElement,t.getViewInstance().$el)){var a,n=t.getParentRecipe(),r=s,o=t.getInsideSelector();n&&(n.isInstantiated()||i(n),r=n.getViewInstance().$el),null!=o&&(a=r.find(o),r=a.length>0?a.first():r);var h,g=e.indexOf(t)+1,v=e.length;for(g;v>g;g++)if(h=e[g],h.isInstantiated()&&h.getViewInstance().$el.parent()[0]==r[0])return h.getViewInstance().$el.before(t.getViewInstance().$el),void 0;r.append(t.getViewInstance().$el)}}var n=null,e=null,s=null,r=function(t,i){n=t,e=[],s=i||$("body"),n.on(navigatorjs.NavigatorEvent.STATE_REQUESTED,a)};r.prototype={mapState:function(){var a=[];return a=a.concat.apply(a,arguments),t(a)},get$Root:function(){return s}},navigatorjs.integration.StateViewMap=r}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.integration=this.navigatorjs.integration||{},function(){var t=function(){this._states=[],this._viewClass=null,this._viewArguments=[],this._viewInstance=null,this._insideSelector=null,this._parentRecipe=null};t.prototype={addState:function(t){var a,i,n=this._states.length;for(a=0;n>a;a++)if(i=this._states[a],i.getPath()==t.getPath())return;return this._states.push(t),this},getStates:function(){return this._states},toView:function(t){return this._viewClass=t,this},getViewClass:function(){return this._viewClass},getViewInstance:function(){if(!this.isInstantiated()){var t=this._viewArguments;switch(t.length){default:case 0:this._viewInstance=new this._viewClass;break;case 1:this._viewInstance=new this._viewClass(t[0]);break;case 2:this._viewInstance=new this._viewClass(t[0],t[1]);break;case 3:this._viewInstance=new this._viewClass(t[0],t[1],t[2]);break;case 4:this._viewInstance=new this._viewClass(t[0],t[1],t[2],t[3]);break;case 5:this._viewInstance=new this._viewClass(t[0],t[1],t[2],t[3],t[4])}}return this._viewInstance},isInstantiated:function(){return null!=this._viewInstance},withArguments:function(){if(arguments.length>5)throw Error("Uncle Bob says you want to use too many arguments");return this._viewArguments=arguments,this},inside:function(t){return this._insideSelector=t,this},getInsideSelector:function(){return this._insideSelector},withParent:function(t){return this._parentRecipe=t,this},getParentRecipe:function(){return this._parentRecipe}},navigatorjs.integration.ViewRecipe=t}(),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var a=this.length,i=Number(arguments[1])||0;for(i=0>i?Math.ceil(i):Math.floor(i),0>i&&(i+=a);a>i;i++)if(i in this&&this[i]===t)return i;return-1}),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.transition=this.navigatorjs.transition||{},function(){var t=function(t,a,i,n,e){this._responder=t,this._status=a,this._behavior=i,this._navigator=n,this._transitionNamespace=e,this._called=!1,navigatorjs.utils.AutoBind(this,this)};t.prototype={call:function(){if(this._called)throw Error("Illegal second call to transition complete. This instance is already prepared for garbage collection!");this._called=!0,this._transitionNamespace.notifyComplete(this._responder,this._status,this._behavior),this._responder=null,this._navigator=null,this._transitionNamespace=null}},navigatorjs.transition.TransitionCompleteDelegate=t}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.transition=this.navigatorjs.transition||{},this.navigatorjs.transition.TransitionStatus={},this.navigatorjs.transition.TransitionStatus.UNINITIALIZED=-2,this.navigatorjs.transition.TransitionStatus.INITIALIZED=-1,this.navigatorjs.transition.TransitionStatus.HIDDEN=1,this.navigatorjs.transition.TransitionStatus.APPEARING=2,this.navigatorjs.transition.TransitionStatus.SHOWN=3,this.navigatorjs.transition.TransitionStatus.SWAPPING=4,this.navigatorjs.transition.TransitionStatus.DISAPPEARING=5,this.navigatorjs.transition.TransitionStatus.toString=function(t){switch(t){case navigatorjs.transition.TransitionStatus.UNINITIALIZED:return"UNINITIALIZED";case navigatorjs.transition.TransitionStatus.INITIALIZED:return"INITIALIZED";
case navigatorjs.transition.TransitionStatus.HIDDEN:return"HIDDEN";case navigatorjs.transition.TransitionStatus.APPEARING:return"APPEARING";case navigatorjs.transition.TransitionStatus.SHOWN:return"SHOWN";case navigatorjs.transition.TransitionStatus.SWAPPING:return"SWAPPING";case navigatorjs.transition.TransitionStatus.DISAPPEARING:return"DISAPPEARING"}return"UNKNOWN"},this.navigatorjs=this.navigatorjs||{},this.navigatorjs.transition=this.navigatorjs.transition||{},function(){var t=function(t,a,i,n,e){this._validatorResponder=t,this._truncatedState=a,this._fullState=i,this._navigator=n,this._validationNamespace=e,navigatorjs.utils.AutoBind(this,this)};t.prototype={call:function(){this._validationNamespace.notifyValidationPrepared(this._validatorResponder,this._truncatedState,this._fullState),this._validatorResponder=null,this._truncatedState=null,this._fullState=null,this._navigator=null,this._validationNamespace=null}},navigatorjs.transition.ValidationPreparedDelegate=t}(),this.navigatorjs=this.navigatorjs||{},this.navigatorjs.utils=this.navigatorjs.utils||{},this.navigatorjs.utils.AutoBind=function(t,a){var i,n;for(i in t)n=t[i],"function"==typeof n&&(t[i]=$.proxy(t[i],a))},this.navigatorjs=this.navigatorjs||{},this.navigatorjs.utils=this.navigatorjs.utils||{},this.navigatorjs.utils.Bind=function(t,a){var i=function(t,a){"function"==typeof t&&$.proxy(t,a)};if("array"==typeof t){var n,e=t.length;for(n=0;e>n;n++)i(t[n],a)}else i(t,a)};