UNPKG

whitesource

Version:
2 lines 3.94 kB
/** UI-Router Extras v.0.0.14 Module: future http://christopherthielen.github.io/ui-router-extras/ - MIT License */ !function(t,e){"use strict";!function(t,e){function r(e,r,n,o){function a(e,r){var n=t.isObject(e)?e.name:e;return r?h[n]:l[n]}function u(t,e){if(e.name){var r=e.name.split(/\./);for("."===e.name.charAt(0)&&(r[0]=t.current.name);r.length;){var n=r.join(".");if(t.get(n,{relative:t.current}))return null;if(h[n])return h[n];r.pop()}}if(e.url){var o=[];for(var a in h){var u=h[a].urlMatcher;u&&u.exec(e.url)&&o.push(h[a])}for(var i=o.slice(0),c=o.length-1;c>=0;c--)for(var f=0;f<i.length;f++)o[c]===i[f].parentFutureState&&o.splice(c,1);return o[0]}}function i(t,e){function r(){delete h[e.name]}function n(t){return"remove"===l&&r(),o.reject(t)}p=!0;var o=t.get("$q");if(!e){var a=o.defer();return a.reject("No lazyState passed in "+e),a.promise}var u=o.when([]),c=e.parentFutureState;c&&h[c.name]&&(u=i(t,h[c.name]));var f=e.type,s=v[f];if(!s)throw Error("No state factory for futureState.type: "+(e&&e.type));var l=s.$options&&s.$options.failedLazyLoadPolicy||"remove";return u.then(function(n){var o=t.invoke(s,s,{futureState:e});return o.then(function(t){return r(),t&&n.push(t),n})})["catch"](n)}function c(t,r){var n=!1,o=["$rootScope","$urlRouter","$state",function(o,a,c){function s(){n=!0,a.sync(),n=!1}if(!$)return f().then(s),void($=!0);var l=u(c,{url:r.path()});return l?void i(t,l).then(function(t){t.forEach(function(t){t&&(!c.get(t)||t.name&&!c.get(t.name))&&e.state(t)}),p=!1,s()},function(){p=!1,s()}):t.invoke(d)}];if(!p){var a=n?d:o;return t.invoke(a)}}var f,s=o,l=s.internalStates,v={},h={},p=!1,m=[],$=!1,g=this;this.addResolve=function(t){m.push(t)},this.stateFactory=function(t,e){v[t]=e},this.futureState=function(e){e.stateName&&(e.name=e.stateName),e.urlPrefix&&(e.url="^"+e.urlPrefix),h[e.name]=e;var r,o=e.name.split(/\./).slice(0,-1).join("."),u=a(e.parent||o);if(u)r=u.url||u.navigable&&u.navigable.url;else if(""===o)r=n.compile("");else{var i=a(e.parent||o,!0);if(!i)throw new Error("Couldn't determine parent state of future state. FutureState:"+t.toJson(e));var c=i.urlMatcher.source.replace(/\*rest$/,"");r=n.compile(c),e.parentFutureState=i}e.url&&(e.urlMatcher="^"===e.url.charAt(0)?n.compile(e.url.substring(1)+"*rest"):r.concat(e.url+"*rest"))},this.get=function(){return t.extend({},h)};var d=["$log","$location",function(t,e){}];r.otherwise(c),r.otherwise=function(e){if(t.isString(e)){var n=e;e=function(){return n}}else if(!t.isFunction(e))throw new Error("'rule' must be a function");return d=["$injector","$location",e],r};var S={getResolvePromise:function(){return f()}};this.$get=["$injector","$state","$q","$rootScope","$urlRouter","$timeout","$log",function(r,n,o,a,c,s,l){function v(){if(a.$on("$stateNotFound",function(t,o,a,c){if(!p){var f=u(n,{name:o.to});if(f){t.preventDefault();var s=i(r,f);s.then(function(t){t.forEach(function(t){t&&(!n.get(t)||t.name&&!n.get(t.name))&&e.state(t)}),n.go(o.to,o.toParams),p=!1},function(t){console.log("failed to lazy load state ",t),a.name&&n.go(a,c),p=!1})}}}),!f){var l=[];t.forEach(m,function(t){l.push(r.invoke(t))}),f=function(){return o.all(l)}}f().then(function v(){s(function(){n.transition?n.transition.then(v,v):c.sync()})})}return v(),S.state=e.state,S.futureState=g.futureState,S.get=g.get,S}]}var n=t.module("ct.ui.router.extras.future",["ct.ui.router.extras.core"]);r.$inject=["$stateProvider","$urlRouterProvider","$urlMatcherFactoryProvider","uirextras_coreProvider"],n.provider("$futureState",r);var o={state:function(t){o.$rootScope&&o.$rootScope.$broadcast("$stateAdded",t)},itsNowRuntimeOhWhatAHappyDay:function(t){o.$rootScope=t},$rootScope:e};n.config(["$stateProvider",function(e){var r=e.state;e.state=function(){var n=r.apply(e,arguments),a=t.isObject(arguments[0])?arguments[0]:arguments[1];return o.state(a),n}}]),n.run(["$futureState",function(t,e){o.itsNowRuntimeOhWhatAHappyDay(e)}])}(t)}(angular);