forked from stoodder/finchjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finch.min.js
14 lines (10 loc) · 11.2 KB
/
finch.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
Finch.js - Powerfully simple javascript routing
by Rick Allen (stoodder) and Greg Smith (smrq)
Version 0.5.14
Full source at https://github.com/stoodder/finchjs
Copyright (c) 2011 RokkinCat, http://www.rokkincat.com
MIT License, https://github.com/stoodder/finchjs/blob/master/LICENSE.md
This file is generated by `cake build`, do not edit it by hand.
*/
(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb,cb,db,eb,fb,gb,hb=[].slice;N=function(a){return typeof a==typeof{}&&null!==a},L=function(a){return"[object Function]"===Object.prototype.toString.call(a)},K=function(a){return"[object Boolean]"===Object.prototype.toString.call(a)},J=function(a){return"[object Array]"===Object.prototype.toString.call(a)},O=function(a){return"[object String]"===Object.prototype.toString.call(a)},M=function(a){return"[object Number]"===Object.prototype.toString.call(a)},eb=function(a){return a.replace(/^\s+/,"").replace(/\s+$/,"")},fb=function(a){return a.replace(/^\//,"").replace(/\/$/,"")},$=function(a,b){return 0===a.indexOf(b)},B=function(a,b){return-1!==a.indexOf(b,a.length-b.length)},y=function(a,b){var c,d,e;if(L(a.indexOf))return-1!==a.indexOf(b);if(J(a))for(d=0,e=a.length;e>d;d++)if(c=a[d],c===b)return!0;return!1},V=function(a){return a[a.length-1]},z=function(a,b){return a.split(b).length-1},P=function(a){var b,c;c=[];for(b in a)c.push(b);return c},Q=function(a){var b,c,d;d=[];for(b in a)c=a[b],d.push(c);return d},C=function(a,b){var c,d;N(a)||(a={}),N(b)||(b={});for(c in b)d=b[c],a[c]=d;return a},w=function(a){var b,c,d;N(a)||(a={}),c={};for(b in a)d=a[b],null!=d&&(c[b]=d);return c},R=function(a,b){var c,d;for(c in a)if(d=a[c],b[c]!==d)return!1;for(c in b)if(d=b[c],a[c]!==d)return!1;return!0},v=function(a,b){var c,d,e,f;if(a.length!==b.length)return!1;for(c=e=0,f=a.length;f>e;c=++e)if(d=a[c],b[c]!==d)return!1;return!0},A=function(a,b){var c,d,e;null==a&&(a={}),null==b&&(b={}),d={};for(c in a)e=a[c],b[c]!==e&&(d[c]=b[c]);for(c in b)e=b[c],a[c]!==e&&(d[c]=e);return d},x=null!=(gb=window.console)?gb:{},null==x.log&&(x.log=function(){}),null==x.warn&&(x.warn=function(){}),n=function(){function a(a){var b,c;c=a.components,b=a.childIndex,this.components=null!=c?c:[],this.childIndex=null!=b?b:0}return a}(),q=function(){function a(a){var b,c,d,e;e=null!=a?a:{},b=e.name,c=e.nodeType,d=e.parent,this.name=null!=b?b:"",this.nodeType=null!=c?c:null,this.parent=null!=d?d:null,this.routeSettings=null,this.childLiterals={},this.childVariable=null,this.bindings=[]}return a}(),s=function(){function a(a){var b,c,d,e,f,g;g=null!=a?a:{},d=g.setup,e=g.teardown,c=g.load,f=g.unload,b=g.context,this.setup=L(d)?d:function(){},this.load=L(c)?c:function(){},this.unload=L(f)?f:function(){},this.teardown=L(e)?e:function(){},this.context=N(b)?b:{}}return a}(),r=function(){function a(a){var b,c,d,e;e=null!=a?a:{},c=e.node,b=e.boundValues,d=e.parameterObservables,this.node=null!=c?c:null,this.boundValues=null!=b?b:[],this.parameterObservables=null!=d?d:[[]]}return a.prototype.getBindings=function(){var a,b,c,d,e,f;for(b={},f=this.node.bindings,c=d=0,e=f.length;e>d;c=++d)a=f[c],b[a]=this.boundValues[c];return S(b)},a.prototype.isEqual=function(a){return null!=a&&this.node===a.node&&v(this.boundValues,a.boundValues)},a.prototype.isRoot=function(){return null==this.node.parent},a.prototype.getParent=function(){var b,c,d,e,f;return null==this.node?null:(b=null!=(e=null!=(f=this.node.parent)?f.bindings.length:void 0)?e:0,c=this.boundValues.slice(0,b),d=this.parameterObservables.slice(0,-1),new a({node:this.node.parent,boundValues:c,parameterObservables:d}))},a.prototype.getChild=function(a){for(var b;null!=a&&!this.isEqual(b=a.getParent());)a=b;return a.parameterObservables=this.parameterObservables.slice(0),a.parameterObservables.push([]),a},a}(),m=function(){function a(a){this.callback=a,L(this.callback)||(this.callback=function(){}),this.dependencies=[],this.initialized=!1}return a.prototype.notify=function(a){var b,c=this;return b=function(){var b,d,e,f;if(!c.initialized)return!0;for(f=c.dependencies,d=0,e=f.length;e>d;d++)if(b=f[d],y(a,b))return!0;return!1}(),b?this.trigger():void 0},a.prototype.trigger=function(){var a,c=this;return this.dependencies=[],a=function(a){return y(c.dependencies,a)||c.dependencies.push(a),b[a]},this.callback(a),this.initialized=!0},a}(),k=new r({node:null}),j={Literal:"Literal",Variable:"Variable"},T=function(a){var b,c,d,e,f,g,h,i;if(a=O(a)?eb(a):"",d={},""!==a)for(h=a.split("&"),f=0,g=h.length;g>f;f++)c=h[f],i=c.split("=",2),b=i[0],e=i[1],d[b]=e;return S(d)},H=function(){var a;return"#"+(null!=(a=window.location.href.split("#",2)[1])?a:"")},Y=function(a){return O(a)||(a=""),a=eb(a),"#"===a.slice(0,1)&&(a=a.slice(1)),window.location.hash=a},S=function(a){var b,c;if(N(a)||(a={}),l.CoerceParameterTypes)for(b in a)c=a[b],"true"===c?c=!0:"false"===c?c=!1:/^[0-9]+$/.test(c)?c=parseInt(c):/^[0-9]+\.[0-9]*$/.test(c)&&(c=parseFloat(c)),a[b]=c;return a},Z=function(a){var b;return a=fb(a),b=""===a?[]:a.split("/"),b.unshift("/"),b},U=function(a){var b,c,d,e,f,g,h,i,j;for(f=y(a,"[")||y(a,"]"),f&&!function(){var b,c;return c=z(a,"["),1!==c?(c>1&&x.warn('[FINCH] Parsing failed on "'+a+'": Extra ['),1>c&&x.warn('[FINCH] Parsing failed on "'+a+'": Missing ['),null):(b=z(a,"]"),1!==b?(b>1&&x.warn('[FINCH] Parsing failed on "'+a+'": Extra ]'),1>b&&x.warn('[FINCH] Parsing failed on "'+a+'": Missing ]'),null):$(a,"[")?void 0:(x.warn('[FINCH] Parsing failed on "'+a+'": [ not at beginning'),null))}(),e=a.replace(/[\[\]]/g,""),d=""===e?[]:Z(e),i=0,j=d.length;j>i;i++)if(c=d[i],""===c)return x.warn('[FINCH] Parsing failed on "'+a+'": Blank component'),null;if(b=0,f){if(h=a.split("]")[0],g=Z(h.replace("[","")),g[g.length-1]!==d[g.length-1])return x.warn('[FINCH] Parsing failed on "'+a+'": ] in the middle of a component'),null;if(g.length===d.length)return x.warn('[FINCH] Parsing failed on "'+a+'": No child components'),null;b=g.length}return new n({components:d,childIndex:b})},G=function(a){return $(a,":")?j.Variable:j.Literal},F=function(a){switch(G(a)){case j.Literal:return a;case j.Variable:return a.slice(1)}},u=function(a,b,c){var d,e,f,g,h;return f=b.components,e=b.childIndex,g=a,d=[],(h=function(i,k){var l,m,n,o,p;if(k===e&&(g=i),b.components.length<=0)return i.parent=g,i.bindings=d,i.routeSettings=new s(c);switch(l=f.shift(),n=G(l),m=F(l),n){case j.Literal:o=null!=(p=i.childLiterals)[m]?(p=i.childLiterals)[m]:p[m]=new q({name:""+i.name+l+"/",nodeType:n,parent:a});break;case j.Variable:o=null!=i.childVariable?i.childVariable:i.childVariable=new q({name:""+i.name+l+"/",nodeType:n,parent:a}),d.push(m)}return h(o,k+1)})(a,0)},E=function(a,b){var c,d,e;return e=Z(b),c=[],(d=function(a,b){var e,f;if(b.length<=0&&null!=a.routeSettings)return new r({node:a,boundValues:c});if(e=b[0],null!=a.childLiterals[e]&&(f=d(a.childLiterals[e],b.slice(1)),null!=f))return f;if(null!=a.childVariable){if(c.push(e),f=d(a.childVariable,b.slice(1)),null!=f)return f;c.pop()}return null})(a,e)},D=function(a,b){var c,d,e,f,g;for(d=[],e=b;null!=e;)d.push(e),e=e.getParent();for(e=a;null!=e;){for(f=0,g=d.length;g>f;f++)if(c=d[f],e.isEqual(c))return e;e=e.getParent()}return null},p=c=d=null,o=b=null,f=a=null,g=!1,h=t=!1,i=!1,l={CoerceParameterTypes:!1},(W=function(){return p=new q({name:"*"}),c=k,o={},b={},d=null,f=null,a=null,g=!1,h=!1,t=!1,i=!1})(),_=function(){var a;return null===d?X():i?db():d.isEqual(c)?ab():(a=D(c,d),c.isEqual(a)?bb():cb())},bb=function(){var a,b,e,f,g,h,i,j,k,l;return t=!0,f=(null!=(i=null!=(j=c.node)?j.routeSettings:void 0)?i:{context:null}).context,c=c.getChild(d),l=null!=(k=c.node.routeSettings)?k:{},b=l.context,h=l.setup,e=l.load,null==b&&(b={}),b.parent=f,null==h&&(h=function(){}),null==e&&(e=function(){}),a=c.getBindings(),g=function(){return _()},2===h.length?h.call(b,a,g):(h.call(b,a),g())},ab=function(){var a,b,e,f,g,h,j;return f=function(){return i=!0,d=null,_()},null==c.node?f():(j=null!=(h=c.node.routeSettings)?h:{},b=j.context,g=j.setup,e=j.load,null==b&&(b={}),null==g&&(g=function(){}),null==e&&(e=function(){}),a=c.getBindings(),2===e.length?e.call(b,a,f):(e.call(b,a),f()))},db=function(){var a,b,d,e,f,g;return i=!1,d=function(){return _()},g=null!=(f=c.node.routeSettings)?f:{},b=g.context,e=g.unload,null==b&&(b={}),null==e&&(e=function(){}),a=c.getBindings(),2===e.length?e.call(b,a,d):(e.call(b,a),d())},cb=function(){var a,b,d,e,f,g;return t=!1,g=null!=(f=c.node.routeSettings)?f:{},b=g.context,e=g.teardown,null==b&&(b={}),null==e&&(e=function(){}),a=c.getBindings(),d=function(){return c=c.getParent(),_()},2===e.length?e.call(b,a,d):(e.call(b,a),d())},X=function(){var a,d,e,f,g,h,i;for(a=P(A(o,b)),o=b,h=c.parameterObservables,i=[],f=0,g=h.length;g>f;f++)e=h[f],i.push(function(){var b,c,f;for(f=[],b=0,c=e.length;c>b;b++)d=e[b],f.push(d.notify(a));return f}());return i},I=function(){var b;return b=H(),$(b,"#")&&(b=b.slice(1)),b=unescape(b),b!==a?e.call(b)?a=b:Y(null!=a?a:""):void 0},e={route:function(a,b){var c,d;return L(b)&&(c=b,b={setup:c},b.load=2===c.length?function(a,b){return t?b():(h=!0,c(a,b))}:function(a){return t?void 0:(h=!0,c(a))}),N(b)||(b={}),O(a)||(a=""),a=eb(a),a.length>0||(a="/"),d=U(a),null==d?!1:(u(p,d,b),!0)},call:function(a){var e,f,g,h,i,j;return O(a)||(a="/"),""===a&&(a="/"),j=a.split("?",2),a=j[0],i=j[1],f=E(p,a),null==f?(x.warn("[FINCH] Could not find route for: "+a),!1):(h=T(i),e=f.getBindings(),b=C(h,e),null===d&&c.isEqual(f)?_():(g=d,d=f,null==g&&_()),!0)},reload:function(){return i?null==c||null==c.node?this:(d=c,_(),this):this},observe:function(){var a,b,d,f;return a=1<=arguments.length?hb.call(arguments,0):[],h?h=!1:(b=a.pop(),L(b)||(b=function(){}),a.length>0?(d=1===a.length&&J(a[0])?a[0]:a,e.observe(function(a){var c,e;return e=function(){var b,e,f;for(f=[],b=0,e=d.length;e>b;b++)c=d[b],f.push(a(c));return f}(),b.apply(null,e)})):(f=new m(b),V(c.parameterObservables).push(f)))},abort:function(){return d=null},listen:function(){return g||("onhashchange"in window&&(L(window.addEventListener)?(window.addEventListener("hashchange",I,!0),g=!0):L(window.attachEvent)&&(window.attachEvent("hashchange",I),g=!0)),g||(f=setInterval(I,33),g=!0),I()),g},ignore:function(){return g&&(null!==f?(clearInterval(f),f=null,g=!1):"onhashchange"in window&&(L(window.removeEventListener)?(window.removeEventListener("hashchange",I,!0),g=!1):L(window.detachEvent)&&(window.detachEvent("hashchange",I),g=!1))),!g},navigate:function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p;if(o=H().split("?",2),g=o[0],f=o[1],null==g&&(g=""),null==f&&(f=""),"#"===g.slice(0,1)&&(g=g.slice(1)),g=unescape(g),e=T(f),K(b)&&(c=b),N(a)&&(b=a),O(a)||(a=""),N(b)||(b={}),K(c)||(c=!1),a=eb(a),0===a.length&&(a=null),c&&(!function(){var a,b,c;b={};for(a in e)c=e[a],b[unescape(a)]=unescape(c);return e=b}(),b=C(e,b)),null===a&&(a=g),p=a.split("?",2),a=p[0],l=p[1],"#"===a.slice(0,1)&&(a=a.slice(1)),$(a,"./")||$(a,"../")){for(d=g;$(a,"./")||$(a,"../");)k=a.indexOf("/"),i=a.slice(0,k),a=a.slice(k+1),".."===i&&(d=d.slice(0,d.lastIndexOf("/")));a=a.length>0?""+d+"/"+a:d}return m=O(l)?T(l):{},b=C(m,b),b=w(b),a=escape(a),j=function(){var a;a=[];for(h in b)n=b[h],a.push(escape(h)+"="+escape(n));return a}().join("&"),j.length>0&&(a+="?"+j),Y(a)},reset:function(){e.options({CoerceParameterTypes:!1}),d=k,_(),e.ignore(),W()},options:function(a){return C(l,a)}},this.Finch=e}).call(this);