mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
7 lines
10 KiB
JavaScript
7 lines
10 KiB
JavaScript
|
|
/**
|
||
|
|
* State-based routing for AngularJS
|
||
|
|
* @version v0.0.1 - 2013-04-15
|
||
|
|
* @link http://angular-ui.github.com/
|
||
|
|
* @license MIT License, http://www.opensource.org/licenses/MIT
|
||
|
|
*/
|
||
|
|
(function(t,r,e){"use strict";function n(t,r){return g(new(g(function(){},{prototype:t})),r)}function a(t){return d(arguments,function(r){r!==t&&d(r,function(r,e){t.hasOwnProperty(e)||(t[e]=r)})}),t}function i(t,r,e){this.fromConfig=function(t,r,e){return h(t.template)?this.fromString(t.template,r):h(t.templateUrl)?this.fromUrl(t.templateUrl,r):h(t.templateProvider)?this.fromProvider(t.templateProvider,r,e):null},this.fromString=function(t,r){return p(t)?t(r):t},this.fromUrl=function(e,n){return p(e)&&(e=e(n)),null==e?null:t.get(e,{cache:r}).then(function(t){return t.data})},this.fromProvider=function(t,r,n){return e.invoke(t,null,n||{params:r})}}function o(t){function r(r){if(!/^\w+$/.test(r))throw Error("Invalid parameter name '"+r+"' in pattern '"+t+"'");if(i[r])throw Error("Duplicate parameter name '"+r+"' in pattern '"+t+"'");i[r]=!0,l.push(r)}function e(t){return t.replace(/[\\\[\]\^$*+?.()|{}]/g,"\\$&")}var n,a=/([:*])(\w+)|\{(\w+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,i={},o="^",s=0,u=this.segments=[],l=this.params=[];this.source=t;for(var c,f,h;(n=a.exec(t))&&(c=n[2]||n[3],f=n[4]||("*"==n[1]?".*":"[^/]*"),h=t.substring(s,n.index),!(h.indexOf("?")>=0));)o+=e(h)+"("+f+")",r(c),u.push(h),s=a.lastIndex;h=t.substring(s);var p=h.indexOf("?");if(p>=0){var m=this.sourceSearch=h.substring(p);h=h.substring(0,p),this.sourcePath=t.substring(0,s+p),d(m.substring(1).split(/[&?]/),r)}else this.sourcePath=t,this.sourceSearch="";o+=e(h)+"$",u.push(h),this.regexp=RegExp(o),this.prefix=u[0]}function s(){this.compile=function(t){return new o(t)},this.isMatcher=function(t){return t instanceof o},this.$get=function(){return this}}function u(t){function r(t){var r=/^\^((?:\\[^a-zA-Z0-9]|[^\\\[\]\^$*+?.()|{}]+)*)/.exec(t.source);return null!=r?r[1].replace(/\\(.)/g,"$1"):""}function e(t,r){return t.replace(/\$(\$|\d{1,2})/,function(t,e){return r["$"===e?0:Number(e)]})}function n(t,r,e){if(!e)return!1;var n=r(e,t);return h(n)?n:!0}var a=[],i=null;this.rule=function(t){if(!p(t))throw Error("'rule' must be a function");return a.push(t),this},this.otherwise=function(t){if(m(t)){var r=t;t=function(){return r}}else if(!p(t))throw Error("'rule' must be a function");return i=t,this},this.when=function(a,i){var o,s;if(m(a)&&(a=t.compile(a)),t.isMatcher(a)){if(m(i))s=t.compile(i),i=function(t){return s.format(t)};else if(!p(i))throw Error("invalid 'handler' in when()");o=function(t){return n(t,i,a.exec(t.path(),t.search()))},o.prefix=m(a.prefix)?a.prefix:""}else{if(!(a instanceof RegExp))throw Error("invalid 'what' in when()");if(m(i))s=i,i=function(t){return e(s,t)};else if(!p(i))throw Error("invalid 'handler' in when()");if(a.global||a.sticky)throw Error("when() RegExp must not be global or sticky");o=function(t){return n(t,i,a.exec(t.path()))},o.prefix=r(a)}return this.rule(o)},this.$get=["$location","$rootScope",function(t,r){function e(){var r,e,n=a.length;for(r=0;n>r;r++)if(e=a[r](t)){m(e)&&t.replace().url(e);break}}return i&&a.push(i),r.$on("$locationChangeSuccess",e),{}}]}function l(t,r){function e(t){var r;if(m(t)){if(r=c[t],!r)throw Error("No such state '"+t+"'")}else if(r=c[t.name],!r||r!==t&&r.self!==t)throw Error("Invalid or unregistered state");return r}function i(a){a=n(a,{self:a,toString:function(){return this.name}});var i=a.name;if(!m(i)||i.indexOf("@")>=0)throw Error("State must have a valid name");if(c[i])throw Error("State '"+i+"'' is already defined");var o=u;if(h(a.parent))null!=a.parent&&(o=e(a.parent));else{var s=/^(.+)\.[^.]+$/.exec(i);null!=s&&(o=e(s[1]))}a.parent=o;var f=a.url;if(m(f))f=a.url="^"==f.charAt(0)?r.compile(f.substring(1)):(o.navigable||u).url.concat(f);else if($(f)&&p(f.exec)&&p(f.format)&&p(f.concat));else if(null!=f)throw Error("Invalid url '"+f+"' in state '"+a+"'");a.navigable=f?a:o?o.navigable:null;var w=a.params;if(w){if(!v(w))throw Error("Invalid params in state '"+a+"'");if(f)throw Error("Both params and url specicified in state '"+a+"'")}else w=a.params=f?f.parameters():a.parent.params;var b={};if(d(w,function(t){b[t]=!0}),o){d(o.params,function(t){if(!b[t])throw Error("Missing req
|