diff --git a/release/ct-ui-router-extras.js b/release/ct-ui-router-extras.js index ddb2c72..0ec9f0d 100644 --- a/release/ct-ui-router-extras.js +++ b/release/ct-ui-router-extras.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Monolithic build (all modules) - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ @@ -201,7 +201,7 @@ angular.module('ct.ui.router.extras.dsr', [ 'ct.ui.router.extras.core' ]).config $provide.decorator("$state", ['$delegate', '$q', function ($state, $q) { $state_transitionTo = $state.transitionTo; $state.transitionTo = function (to, toParams, options) { - if (options.ignoreDsr) { + if (options && options.ignoreDsr) { ignoreDsr = options.ignoreDsr; } @@ -333,7 +333,12 @@ angular.module('ct.ui.router.extras.dsr').service("$deepStateRedirect", [ '$root computeDeepStateStatus(state) var cfg = getConfig(state); var key = getParamsString(params, cfg.params); - var redirect = lastSubstate[state.name][key] || cfg['default']; + var redirect = lastSubstate[state.name]; + if (redirect && redirect[key]) { + redirect = redirect[key]; + } else { + redirect = cfg['default']; + } return redirect; }, reset: function(stateOrName, params) { @@ -511,10 +516,13 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { }; } + function sortByStateDepth(a,b) { + return a.name.split(".").length - b.name.split(".").length; + } var stickySupport = { getInactiveStates: function () { - return map(inactiveStates, angular.identity); + return map(inactiveStates, angular.identity).sort(sortByStateDepth); }, getInactiveStatesByParent: function () { return mapInactives(); @@ -532,7 +540,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { // } processTransition: function (transition) { var treeChanges = calcTreeChanges(transition); - var currentInactives = map(inactiveStates, angular.identity); + var currentInactives = stickySupport.getInactiveStates(); var futureInactives, exitingTypes, enteringTypes; var keep = treeChanges.keep; @@ -620,7 +628,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { .reduce(flattenReduce, []) .concat(orphanedRoots) // Sort by depth to exit orphans in proper order - .sort(function (a,b) { return a.name.split(".").length - b.name.split(".").length; }); + .sort(sortByStateDepth); // Add them to the list of states being exited. var exitOrOrphaned = exitingTypes @@ -634,7 +642,8 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { futureInactives = currentInactives .filter(notIn(exitOrOrphaned)) .filter(notIn(treeChanges.entering)) - .concat(exitingTypes.filter(typeIs("inactivate")).map(prop("state"))); + .concat(exitingTypes.filter(typeIs("inactivate")).map(prop("state"))) + .sort(sortByStateDepth); return { keep: keep, @@ -1254,30 +1263,36 @@ angular.module("ct.ui.router.extras.sticky").config( return s.self.name; })); - var viewMsg = function (local, name) { - return "'" + name + "' (" + local.$$state.name + ")"; - }; var statesOnly = function (local, name) { return name != 'globals' && name != 'resolve'; }; + var viewsForState = function (state) { - var views = map(filterObj(state.locals, statesOnly), viewMsg).join(", "); - return "(" + (state.self.name ? state.self.name : "root") + ".locals" + (views.length ? ": " + views : "") + ")"; + var viewLocals = filterObj(state.locals, statesOnly); + + if (!Object.keys(viewLocals).length) { + viewLocals[''] = { $$state: { name: null } }; + } + + return map(viewLocals, function(local, name) { + return { + localsFor: state.self.name ? state.self.name : "(root)", + uiViewName: name || null, + filledByState: local.$$state.name + }; + }); }; - var message = viewsForState(currentState); + var viewsByState = viewsForState(currentState); var parent = currentState.parent; while (parent && parent !== currentState) { - if (parent.self.name === "") { - // Show the __inactives before showing root state. - message = viewsForState($state.$current.path[0]) + " / " + message; - } - message = viewsForState(parent) + " / " + message; + viewsByState = viewsByState.concat(viewsForState(parent)); currentState = parent; parent = currentState.parent; } - $log.debug("Views: " + message); + $log.debug("Views active on each state:"); + console.table(viewsByState.reverse()); } } ] diff --git a/release/ct-ui-router-extras.min.js b/release/ct-ui-router-extras.min.js index f5c0270..5f8862e 100644 --- a/release/ct-ui-router-extras.min.js +++ b/release/ct-ui-router-extras.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Monolithic build (all modules) http://christopherthielen.github.io/ui-router-extras/ - MIT License */ -!function(t,e){"use strict";"function"==typeof define&&define.amd?define(["angular"],function(t){e(t)}):e("object"==typeof exports?require("angular"):t.angular)}(this,function(t,e){function r(t,e){var r=[];for(var n in t.path){if(t.path[n]!==e.path[n])break;r.push(t.path[n])}return r}function n(e){if(Object.keys)return Object.keys(e);var r=[];return t.forEach(e,function(t,e){r.push(e)}),r}function a(t,e){var r=[];for(var n in t)e&&-1!==e.indexOf(n)||r.push(n);return r}function o(t,e){if(Array.prototype.indexOf)return t.indexOf(e,Number(arguments[2])||0);var r=t.length>>>0,n=Number(arguments[2])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=r);r>n;n++)if(n in t&&t[n]===e)return n;return-1}function i(t,e,a,i){var u,s=r(a,i),c={},f=[];for(var l in s)if(s[l].params&&(u=$(s[l].params)?s[l].params:n(s[l].params),u.length))for(var p in u)o(f,u[p])>=0||(f.push(u[p]),c[u[p]]=t[u[p]]);return h({},c,e)}function u(t,e){return h(new(h(function(){},{prototype:t})),e)}function s(t){d.push(t)}function c(){b=e}function f(e,r){var n=r,a=n.inheritParams,o=(n.objectKeys,n.protoKeys),i=n.forEach,u=n.map,s={},c={},f=!1;this.registerStickyState=function(t){c[t.name]=t},this.enableDebug=this.debugMode=function(e){return t.isDefined(e)&&(f=e),f},this.$get=["$rootScope","$state","$stateParams","$injector","$log",function(e,r,n,c,l){function p(){var e={};return t.forEach(s,function(t,r){for(var n=d(t),a=0;a0;l=d.exiting.map(function(t){var e=-1!==d.entering.indexOf(t),r=y&&!e?"inactivate":"exit";return{type:r,state:t}});var S=e.options&&!!e.options.reload;p=d.entering.map(function(t){var r=m(t,e.toParams,e.reloadStateTree,S);return S=S||"reload"===r,{type:r,state:t}});var b=d.entering.map(function(t){return h.filter(i(t.parent))}).reduce(n,[]).filter(g).filter(c).concat(h.filter(i(e.toState))),E=v(),k=b.map(function(t){return E[t.name]}).filter(t.isDefined).reduce(n,[]).concat(b).sort(function(t,e){return t.name.split(".").length-e.name.split(".").length}),P=l.filter(o("exit")).map(a("state")).concat(k);return f=h.filter(r(P)).filter(r(d.entering)).concat(l.filter(o("inactivate")).map(a("state"))),{keep:$,enter:new Array($).concat(p.map(a("type"))),exit:new Array($).concat(l.map(a("type"))),inactives:f,reactivatingStates:p.filter(o("reactivate")).map(a("state")),orphans:k}},stateInactivated:function(t){s[t.self.name]=t,t.self.status="inactive",t.self.onInactivate&&c.invoke(t.self.onInactivate,t.self,t.locals.globals)},stateReactivated:function(t){s[t.self.name]&&delete s[t.self.name],t.self.status="entered",t.self.onReactivate&&c.invoke(t.self.onReactivate,t.self,t.locals.globals)},stateExiting:function(e,r,n){var a={};t.forEach(r,function(t){a[t.self.name]=!0}),t.forEach(s,function(r,n){!a[n]&&r.includes[e.name]&&(f&&l.debug("Exiting "+n+" because it's a substate of "+e.name+" and wasn't found in ",a),r.self.onExit&&c.invoke(r.self.onExit,r.self,r.locals.globals),t.forEach(r.locals,function(t,e){delete j.locals[e]}),r.locals=null,r.self.status="exited",delete s[n])}),n&&c.invoke(n,e.self,e.locals.globals),e.locals=null,e.self.status="exited",delete s[e.self.name]},stateEntering:function(t,e,r,n){var a=h(t);if(a&&(n||!h(t,e))){var o=t.locals;this.stateExiting(a),t.locals=o}t.self.status="entered",r&&c.invoke(r,t.self,t.locals.globals)},reset:function(n,a){function o(t){y.reset(t)}if("*"===n)return t.forEach(y.getInactiveStates(),o),!0;var i=r.get(n);if(!i)return!1;var u=h(i,a);return u?(y.stateExiting(u),e.$broadcast("$viewContentLoading"),!0):!1}};return y}]}function l(t){return{resolve:{},locals:{globals:P&&P.locals&&P.locals.globals},views:{},self:{},params:{},ownParams:A.hasParamSet?{$$equals:function(){return!0}}:[],surrogateType:t}}var p=t.module("ct.ui.router.extras.core",["ui.router"]),v={},d=[];p.config(["$stateProvider","$injector",function(e,r){e.decorator("parent",function(e,r){return v[e.self.name]=e,e.self.$$state=function(){return v[e.self.name]},t.forEach(d,function(t){t(e)}),r(e)})}]);var m=t.forEach,h=t.extend,$=t.isArray,g=function(t,e){"use strict";var r=[];return m(t,function(t,n){r.push(e(t,n))}),r},x=function(t){"use strict";return g(t,function(t,e){return e})},y=function(t,e){"use strict";var r=[];return m(t,function(t,n){e(t,n)&&r.push(t)}),r},S=function(t,e){"use strict";var r={};return m(t,function(t,n){e(t,n)&&(r[n]=t)}),r};p.provider("uirextras_core",function(){var e={internalStates:v,onStateRegistered:s,forEach:m,extend:h,isArray:$,map:g,keys:x,filter:y,filterObj:S,ancestors:r,objectKeys:n,protoKeys:a,arraySearch:o,inheritParams:i,inherit:u};t.extend(this,e),this.$get=function(){return e}});var b;t.module("ct.ui.router.extras.dsr",["ct.ui.router.extras.core"]).config(["$provide",function(t){var e;t.decorator("$state",["$delegate","$q",function(t,r){return e=t.transitionTo,t.transitionTo=function(n,a,o){return o.ignoreDsr&&(b=o.ignoreDsr),e.apply(t,arguments).then(function(t){return c(),t},function(t){return c(),r.reject(t)})},t}])}]),t.module("ct.ui.router.extras.dsr").service("$deepStateRedirect",["$rootScope","$state","$injector",function(r,n,a){function o(t){var e=t.name;return l.hasOwnProperty(e)?l[e]:void u(e)}function i(e){var r=e.deepStateRedirect||e.dsr;if(!r)return{dsr:!1};var n={dsr:!0};return t.isFunction(r)?n.fn=r:t.isObject(r)&&(n=t.extend(n,r)),t.isString(n["default"])&&(n["default"]={state:n["default"]}),n.fn||(n.fn=["$dsr$",function(t){return t.redirect.state!=t.to.state}]),n}function u(t){var r=n.get(t);if(!r)return!1;var a=i(r);a.dsr&&(l[r.name]=p,f[t]===e&&(f[t]={}));var o=r.$$state&&r.$$state().parent;if(o){var s=u(o.self.name);s&&l[r.name]===e&&(l[r.name]=v)}return l[r.name]||!1}function s(r,n){n===!0&&(n=Object.keys(r)),null!==n&&n!==e||(n=[]);var a={};return t.forEach(n.sort(),function(t){a[t]=r[t]}),a}function c(e,r){function n(t){return t?t.toString():t}var a=s(e,r),o={};return t.forEach(a,function(t,e){o[e]=n(t)}),t.toJson(o)}var f={},l={},p="Redirect",v="AncestorRedirect";return r.$on("$stateChangeStart",function(e,r,u,l,v){var d=i(r);if(!b&&(o(r)===p||d["default"])){var m=c(u,d.params),h=f[r.name][m]||d["default"];if(h){var $={redirect:{state:h.state,params:h.params},to:{state:r.name,params:u}},g=a.invoke(d.fn,r,{$dsr$:$});if(g){g.state&&(h=g),e.preventDefault();var x=s(u,d.params);n.go(h.state,t.extend(x,h.params))}}}}),r.$on("$stateChangeSuccess",function(e,r,a,u,s){var l=o(r);if(l){var p=r.name;t.forEach(f,function(e,o){var u=i(n.get(o)),s=c(a,u.params);r.$$state().includes[o]&&(f[o][s]={state:p,params:t.copy(a)})})}}),{getRedirect:function(t,e){var r=n.get(t);o(r);var a=i(r),u=c(e,a.params),s=f[r.name][u]||a["default"];return s},reset:function(e,r){if(e){var a=n.get(e);if(!a)throw new Error("Unknown state: "+e);if(f[a.name])if(r){var o=c(r,i(a).params);delete f[a.name][o]}else f[a.name]={}}else t.forEach(f,function(t,e){f[e]={}})}}}]),t.module("ct.ui.router.extras.dsr").run(["$deepStateRedirect",function(t){}]),t.module("ct.ui.router.extras.sticky",["ct.ui.router.extras.core"]);var E=t.module("ct.ui.router.extras.sticky");f.$inject=["$stateProvider","uirextras_coreProvider"],E.provider("$stickyState",f);var k,P,w,j,v={},R=[],F={},A={hasParamSet:!1};t.module("ct.ui.router.extras.sticky").run(["$stickyState",function(t){k=t}]),t.module("ct.ui.router.extras.sticky").config(["$provide","$stateProvider","$stickyStateProvider","$urlMatcherFactoryProvider","uirextras_coreProvider",function(r,n,a,o,i){function u(e,r,n){function a(t,e,r){return t[e]?t[e].toUpperCase()+": "+r.self.name:"("+r.self.name+")"}var o=d(n.inactives,function(t){return t.self.name}),i=d(r.toState.path,function(t,e){return a(n.enter,e,t)}),u=d(r.fromState.path,function(t,e){return a(n.exit,e,t)}),s=r.fromState.self.name+": "+t.toJson(r.fromParams)+": -> "+r.toState.self.name+": "+t.toJson(r.toParams);e.debug("------------------------------------------------------"),e.debug(" Current transition: ",s),e.debug("Before transition, inactives are: : ",d(k.getInactiveStates(),function(t){return t.self.name})),e.debug("After transition, inactives will be: ",o),e.debug("Transition will exit: ",u),e.debug("Transition will enter: ",i)}function s(t,e,r){t.debug("Current state: "+e.self.name+", inactive states: ",d(k.getInactiveStates(),function(t){return t.self.name}));for(var n=function(t,e){return"'"+e+"' ("+t.$$state.name+")"},a=function(t,e){return"globals"!=e&&"resolve"!=e},o=function(t){var e=d(m(t.locals,a),n).join(", ");return"("+(t.self.name?t.self.name:"root")+".locals"+(e.length?": "+e:"")+")"},i=o(e),u=e.parent;u&&u!==e;)""===u.self.name&&(i=o(r.$current.path[0])+" / "+i),i=o(u)+" / "+i,e=u,u=e.parent;t.debug("Views: "+i)}var c=i,f=c.internalStates,p=c.inherit,v=(c.inheritParams,c.forEach),d=c.map,m=c.filterObj;A.hasParamSet=!!o.ParamSet,j=t.extend(new l("__inactives"),{self:{name:"__inactives"}}),P=w=e,R=[],i.onStateRegistered(function(t){t.self.sticky===!0&&a.registerStickyState(t.self)});var h;r.decorator("$state",["$delegate","$log","$q",function(r,n,i){return P=r.$current,f[""]=P,P.parent=j,j.parent=e,j.locals=p(F,j.locals),P.locals=p(j.locals,P.locals),delete j.locals.globals,h=r.transitionTo,r.transitionTo=function(e,c,p){function m(e){var r=t.extend(new l("reactivate_phase1"),{locals:e.locals});return r.self=t.extend({},e.self),r}function $(e){var r=t.extend(new l("reactivate_phase2"),e),n=r.self.onEnter;return r.resolve={},r.views={},r.self.onEnter=function(){r.locals=e.locals,k.stateReactivated(e)},J.addRestoreFunction(function(){e.self.onEnter=n}),r}function g(t){var e=new l("inactivate");e.self=t.self;var r=t.self.onExit;return e.self.onExit=function(){k.stateInactivated(t)},J.addRestoreFunction(function(){t.self.onExit=r}),e}function x(t,e){var r=t.self.onEnter;return t.self.onEnter=function(){k.stateEntering(t,e,r)},J.addRestoreFunction(function(){t.self.onEnter=r}),t}function y(t,e){var r=t.self.onEnter;return t.self.onEnter=function(){k.stateEntering(t,e,r,!0)},J.addRestoreFunction(function(){t.self.onEnter=r}),t}function S(t){var e=t.self.onExit;return t.self.onExit=function(){k.stateExiting(t,K,e)},J.addRestoreFunction(function(){t.self.onExit=e}),t}var b=a.debugMode();j.locals||(j.locals=P.locals);var E=R.length;w&&(w(),b&&n.debug("Restored paths from pending transition"));var O,T,_,q,I=r.$current,M=r.params,C=p&&p.relative||r.$current,D=r.get(e,C),N=[],K=[];c=c||{},arguments[1]=c;var z=function(){},J=function(){O&&(L.path=O,O=null),T&&(I.path=T,T=null),t.forEach(J.restoreFunctions,function(t){t()}),J=z,w=null,R.splice(E,1)};if(J.restoreFunctions=[],J.addRestoreFunction=function(t){this.restoreFunctions.push(t)},D){var L=f[D.name];if(L){O=L.path,T=I.path;var B=p&&p.reload||!1,H=B&&(B===!0?O[0].self:r.get(B,C));p&&B&&B!==!0&&delete p.reload;var U={toState:L,toParams:c||{},fromState:I,fromParams:M||{},options:p,reloadStateTree:H};if(R.push(U),w=J,H){U.toParams.$$uirouterextrasreload=Math.random();var V=H.$$state().params,W=H.$$state().ownParams;if(A.hasParamSet){var Y=new o.Param("$$uirouterextrasreload");V.$$uirouterextrasreload=W.$$uirouterextrasreload=Y,J.restoreFunctions.push(function(){delete V.$$uirouterextrasreload,delete W.$$uirouterextrasreload})}else V.push("$$uirouterextrasreload"),W.push("$$uirouterextrasreload"),J.restoreFunctions.push(function(){V.length=V.length-1,W.length=W.length-1})}_=k.processTransition(U),b&&u(n,U,_);var G=L.path.slice(0,_.keep),Q=I.path.slice(0,_.keep);t.forEach(j.locals,function(t,e){-1!=e.indexOf("@")&&delete j.locals[e]});var X=function(t){return function(e,r){-1!==r.indexOf("@")&&(t[r]=e)}};v(_.inactives,function(t){v(t.locals,X(j.locals))}),v(_.reactivatingStates,function(t){v(t.locals,X(F))}),J.addRestoreFunction(function(){v(F,function(t,e){delete F[e]})}),t.forEach(_.enter,function(t,e){var r,n=L.path[e];"reactivate"===t?(r=m(n),G.push(r),Q.push(r),N.push($(n)),q=n):"reload"===t?(G.push(y(n)),q=n):"enter"===t&&G.push(x(n))}),t.forEach(_.exit,function(t,e){var r=I.path[e];"inactivate"===t?(Q.push(g(r)),K.push(r)):"exit"===t&&(Q.push(S(r)),K.push(r))}),N.length&&t.forEach(N,function(t){G.push(t)});var Z=_.orphans;Q=Q.concat(d(Z,function(t){return S(t)})),K=K.concat(Z),I.path=Q,L.path=G;var tt=function(t){return(t.surrogateType?t.surrogateType+":":"")+t.self.name};b&&n.debug("SurrogateFromPath: ",d(Q,tt)),b&&n.debug("SurrogateToPath: ",d(G,tt))}}var et=h.apply(r,arguments);return et.then(function(t){return J(),b&&s(n,f[t.name],r),t.status="active",t},function(t){return J(),b&&"transition prevented"!==t.message&&"transition aborted"!==t.message&&"transition superseded"!==t.message&&(n.debug("transition failed",t),n.debug(t.stack)),i.reject(t)})},r}])}]),function(t,e){function r(e,r,n,a){function o(e,r){var n=t.isObject(e)?e.name:e;return r?v[n]:l[n]}function i(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(v[n])return v[n];r.pop()}}if(e.url){var a=[];for(var o in v){var i=v[o].urlMatcher;i&&i.exec(e.url)&&a.push(v[o])}for(var u=a.slice(0),s=a.length-1;s>=0;s--)for(var c=0;c=l.length)){var s=f,c=t.extend(l[s],{to:{state:n,params:a},from:{state:i,params:u}}),v=o(c);p[s]=v,r.$broadcast("$transitionStart",c)}}),e}])}]),function(){"use strict";function e(e,r,n){return{scope:{width:"@",height:"@"},restrict:"AE",template:"",link:function(r,a,o){function i(e){e=e.map(function(e){return""===e.name?p:t.copy(e)}),t.extend(s,e.reduce(function(t,e){return t[e.name]=e,t},{})),e.forEach(function(t){var e=t.name.split(/\./).slice(0,-1).join("."),r=t.name!=e&&s[e];r&&((r.children||(r.children=[])).push(t),t.px=r.px,t.py=r.py,v.push(t))})}function u(){function t(t){var e=t.name.split(".").pop();return t.sticky&&(e+=" (STICKY)"),t.deepStateRedirect&&(e+=" (DSR)"),e}$=$.data(l.nodes(p),function(t){return t.name}),g=g.data(l.links(v),function(t){return t.target.name}),x=x.data(d),v.forEach(function(t){t.y=70*t.depth});var e=$.enter();x.enter().append("circle").attr("class","active").attr("r",13).attr("cx",function(t){return t.parent.px||100}).attr("cy",function(t){return t.parent.py||100}),e.append("circle").attr("class","node").attr("r",9).attr("cx",function(t){return t.parent.px}).attr("cy",function(t){return t.parent.py}),e.append("text").attr("class","label").attr("x",function(t){return t.parent.px}).attr("y",function(t){return t.parent.py}).attr("text-anchor",function(t){return"middle"}).text(t).style("fill-opacity",1),g.enter().insert("path",".node").attr("class","link").attr("d",function(t){var e={x:t.source.px,y:t.source.py};return m({source:e,target:e})});var r=h.transition().duration(S);r.selectAll(".link").attr("d",m);var n={entered:"#AF0",exited:"#777",active:"#0f0",inactive:"#55F",future:"#009"};r.selectAll(".node").attr("cx",function(t){return t.px=t.x}).attr("cy",function(t){return t.py=t.y}).attr("r",function(t){return"active"===t.status?15:10}).style("fill",function(t){return n[t.status]||"#FFF"}),r.selectAll(".label").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15}).attr("transform",function(t){return"rotate(-25 "+t.x+" "+t.y+")"}),r.selectAll(".active").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15})}var s={},c=r.width||400,f=r.height||400,l=d3.layout.tree().size([c-20,f-20]).separation(function(t,e){return t.parent==e.parent?10:25}),p=e.get().filter(function(t){return""===t.name})[0],v=l(p);p.parent=p,p.px=p.x=c/2,p.py=p.y=f/2;var d={};d.px=d.x=p.px,d.py=d.y=p.py;var m=d3.svg.diagonal(),h=d3.select(a.find("svg")[0]).attr("width",c).attr("height",f).append("g").attr("transform","translate(10, 10)"),$=h.selectAll(".node"),g=h.selectAll(".link"),x=h.selectAll(".active"),y=200,S=200;setInterval(u,y);n(function(){r.states=e.get(),t.forEach(v,function(t){var r=e.get(t.name);r&&(t.status=r.status||"exited")})},250),r.$watchCollection("states",function(t,e){var r=(e||[]).map(function(t){return t.name});i((t||[]).filter(function(t){return-1==r.indexOf(t.name)}))}),u(y)}}}var r=t.module("ct.ui.router.extras.statevis",["ct.ui.router.extras.core","ct.ui.router.extras.sticky"]);r.directive("stateVis",["$state","$timeout","$interval",e])}(),t.module("ct.ui.router.extras",["ct.ui.router.extras.core","ct.ui.router.extras.dsr","ct.ui.router.extras.future","ct.ui.router.extras.previous","ct.ui.router.extras.statevis","ct.ui.router.extras.sticky","ct.ui.router.extras.transition"])}); \ No newline at end of file +/** UI-Router Extras v.0.1.3 Monolithic build (all modules) http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +!function(t,e){"use strict";"function"==typeof define&&define.amd?define(["angular"],function(t){e(t)}):e("object"==typeof exports?require("angular"):t.angular)}(this,function(t,e){function r(t,e){var r=[];for(var n in t.path){if(t.path[n]!==e.path[n])break;r.push(t.path[n])}return r}function n(e){if(Object.keys)return Object.keys(e);var r=[];return t.forEach(e,function(t,e){r.push(e)}),r}function a(t,e){var r=[];for(var n in t)e&&-1!==e.indexOf(n)||r.push(n);return r}function o(t,e){if(Array.prototype.indexOf)return t.indexOf(e,Number(arguments[2])||0);var r=t.length>>>0,n=Number(arguments[2])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=r);r>n;n++)if(n in t&&t[n]===e)return n;return-1}function i(t,e,a,i){var u,s=r(a,i),c={},f=[];for(var l in s)if(s[l].params&&(u=$(s[l].params)?s[l].params:n(s[l].params),u.length))for(var p in u)o(f,u[p])>=0||(f.push(u[p]),c[u[p]]=t[u[p]]);return h({},c,e)}function u(t,e){return h(new(h(function(){},{prototype:t})),e)}function s(t){d.push(t)}function c(){b=e}function f(e,r){var n=r,a=n.inheritParams,o=(n.objectKeys,n.protoKeys),i=n.forEach,u=n.map,s={},c={},f=!1;this.registerStickyState=function(t){c[t.name]=t},this.enableDebug=this.debugMode=function(e){return t.isDefined(e)&&(f=e),f},this.$get=["$rootScope","$state","$stateParams","$injector","$log",function(e,r,n,c,l){function p(){var e={};return t.forEach(s,function(t,r){for(var n=d(t),a=0;a0;c=l.exiting.map(function(t){var e=-1!==l.entering.indexOf(t),r=$&&!e?"inactivate":"exit";return{type:r,state:t}});var g=e.options&&!!e.options.reload;f=l.entering.map(function(t){var r=m(t,e.toParams,e.reloadStateTree,g);return g=g||"reload"===r,{type:r,state:t}});var b=l.entering.map(function(t){return p.filter(i(t.parent))}).reduce(n,[]).filter(h).filter(u).concat(p.filter(i(e.toState))),E=v(),k=b.map(function(t){return E[t.name]}).filter(t.isDefined).reduce(n,[]).concat(b).sort(y),P=c.filter(o("exit")).map(a("state")).concat(k);return s=p.filter(r(P)).filter(r(l.entering)).concat(c.filter(o("inactivate")).map(a("state"))).sort(y),{keep:d,enter:new Array(d).concat(f.map(a("type"))),exit:new Array(d).concat(c.map(a("type"))),inactives:s,reactivatingStates:f.filter(o("reactivate")).map(a("state")),orphans:k}},stateInactivated:function(t){s[t.self.name]=t,t.self.status="inactive",t.self.onInactivate&&c.invoke(t.self.onInactivate,t.self,t.locals.globals)},stateReactivated:function(t){s[t.self.name]&&delete s[t.self.name],t.self.status="entered",t.self.onReactivate&&c.invoke(t.self.onReactivate,t.self,t.locals.globals)},stateExiting:function(e,r,n){var a={};t.forEach(r,function(t){a[t.self.name]=!0}),t.forEach(s,function(r,n){!a[n]&&r.includes[e.name]&&(f&&l.debug("Exiting "+n+" because it's a substate of "+e.name+" and wasn't found in ",a),r.self.onExit&&c.invoke(r.self.onExit,r.self,r.locals.globals),t.forEach(r.locals,function(t,e){delete j.locals[e]}),r.locals=null,r.self.status="exited",delete s[n])}),n&&c.invoke(n,e.self,e.locals.globals),e.locals=null,e.self.status="exited",delete s[e.self.name]},stateEntering:function(t,e,r,n){var a=h(t);if(a&&(n||!h(t,e))){var o=t.locals;this.stateExiting(a),t.locals=o}t.self.status="entered",r&&c.invoke(r,t.self,t.locals.globals)},reset:function(n,a){function o(t){S.reset(t)}if("*"===n)return t.forEach(S.getInactiveStates(),o),!0;var i=r.get(n);if(!i)return!1;var u=h(i,a);return u?(S.stateExiting(u),e.$broadcast("$viewContentLoading"),!0):!1}};return S}]}function l(t){return{resolve:{},locals:{globals:P&&P.locals&&P.locals.globals},views:{},self:{},params:{},ownParams:A.hasParamSet?{$$equals:function(){return!0}}:[],surrogateType:t}}var p=t.module("ct.ui.router.extras.core",["ui.router"]),v={},d=[];p.config(["$stateProvider","$injector",function(e,r){e.decorator("parent",function(e,r){return v[e.self.name]=e,e.self.$$state=function(){return v[e.self.name]},t.forEach(d,function(t){t(e)}),r(e)})}]);var m=t.forEach,h=t.extend,$=t.isArray,g=function(t,e){"use strict";var r=[];return m(t,function(t,n){r.push(e(t,n))}),r},x=function(t){"use strict";return g(t,function(t,e){return e})},y=function(t,e){"use strict";var r=[];return m(t,function(t,n){e(t,n)&&r.push(t)}),r},S=function(t,e){"use strict";var r={};return m(t,function(t,n){e(t,n)&&(r[n]=t)}),r};p.provider("uirextras_core",function(){var e={internalStates:v,onStateRegistered:s,forEach:m,extend:h,isArray:$,map:g,keys:x,filter:y,filterObj:S,ancestors:r,objectKeys:n,protoKeys:a,arraySearch:o,inheritParams:i,inherit:u};t.extend(this,e),this.$get=function(){return e}});var b;t.module("ct.ui.router.extras.dsr",["ct.ui.router.extras.core"]).config(["$provide",function(t){var e;t.decorator("$state",["$delegate","$q",function(t,r){return e=t.transitionTo,t.transitionTo=function(n,a,o){return o&&o.ignoreDsr&&(b=o.ignoreDsr),e.apply(t,arguments).then(function(t){return c(),t},function(t){return c(),r.reject(t)})},t}])}]),t.module("ct.ui.router.extras.dsr").service("$deepStateRedirect",["$rootScope","$state","$injector",function(r,n,a){function o(t){var e=t.name;return l.hasOwnProperty(e)?l[e]:void u(e)}function i(e){var r=e.deepStateRedirect||e.dsr;if(!r)return{dsr:!1};var n={dsr:!0};return t.isFunction(r)?n.fn=r:t.isObject(r)&&(n=t.extend(n,r)),t.isString(n["default"])&&(n["default"]={state:n["default"]}),n.fn||(n.fn=["$dsr$",function(t){return t.redirect.state!=t.to.state}]),n}function u(t){var r=n.get(t);if(!r)return!1;var a=i(r);a.dsr&&(l[r.name]=p,f[t]===e&&(f[t]={}));var o=r.$$state&&r.$$state().parent;if(o){var s=u(o.self.name);s&&l[r.name]===e&&(l[r.name]=v)}return l[r.name]||!1}function s(r,n){n===!0&&(n=Object.keys(r)),null!==n&&n!==e||(n=[]);var a={};return t.forEach(n.sort(),function(t){a[t]=r[t]}),a}function c(e,r){function n(t){return t?t.toString():t}var a=s(e,r),o={};return t.forEach(a,function(t,e){o[e]=n(t)}),t.toJson(o)}var f={},l={},p="Redirect",v="AncestorRedirect";return r.$on("$stateChangeStart",function(e,r,u,l,v){var d=i(r);if(!b&&(o(r)===p||d["default"])){var m=c(u,d.params),h=f[r.name][m]||d["default"];if(h){var $={redirect:{state:h.state,params:h.params},to:{state:r.name,params:u}},g=a.invoke(d.fn,r,{$dsr$:$});if(g){g.state&&(h=g),e.preventDefault();var x=s(u,d.params);n.go(h.state,t.extend(x,h.params))}}}}),r.$on("$stateChangeSuccess",function(e,r,a,u,s){var l=o(r);if(l){var p=r.name;t.forEach(f,function(e,o){var u=i(n.get(o)),s=c(a,u.params);r.$$state().includes[o]&&(f[o][s]={state:p,params:t.copy(a)})})}}),{getRedirect:function(t,e){var r=n.get(t);o(r);var a=i(r),u=c(e,a.params),s=f[r.name];return s=s&&s[u]?s[u]:a["default"]},reset:function(e,r){if(e){var a=n.get(e);if(!a)throw new Error("Unknown state: "+e);if(f[a.name])if(r){var o=c(r,i(a).params);delete f[a.name][o]}else f[a.name]={}}else t.forEach(f,function(t,e){f[e]={}})}}}]),t.module("ct.ui.router.extras.dsr").run(["$deepStateRedirect",function(t){}]),t.module("ct.ui.router.extras.sticky",["ct.ui.router.extras.core"]);var E=t.module("ct.ui.router.extras.sticky");f.$inject=["$stateProvider","uirextras_coreProvider"],E.provider("$stickyState",f);var k,P,w,j,v={},F=[],R={},A={hasParamSet:!1};t.module("ct.ui.router.extras.sticky").run(["$stickyState",function(t){k=t}]),t.module("ct.ui.router.extras.sticky").config(["$provide","$stateProvider","$stickyStateProvider","$urlMatcherFactoryProvider","uirextras_coreProvider",function(r,n,a,o,i){function u(e,r,n){function a(t,e,r){return t[e]?t[e].toUpperCase()+": "+r.self.name:"("+r.self.name+")"}var o=d(n.inactives,function(t){return t.self.name}),i=d(r.toState.path,function(t,e){return a(n.enter,e,t)}),u=d(r.fromState.path,function(t,e){return a(n.exit,e,t)}),s=r.fromState.self.name+": "+t.toJson(r.fromParams)+": -> "+r.toState.self.name+": "+t.toJson(r.toParams);e.debug("------------------------------------------------------"),e.debug(" Current transition: ",s),e.debug("Before transition, inactives are: : ",d(k.getInactiveStates(),function(t){return t.self.name})),e.debug("After transition, inactives will be: ",o),e.debug("Transition will exit: ",u),e.debug("Transition will enter: ",i)}function s(t,e,r){t.debug("Current state: "+e.self.name+", inactive states: ",d(k.getInactiveStates(),function(t){return t.self.name}));for(var n=function(t,e){return"globals"!=e&&"resolve"!=e},a=function(t){var e=m(t.locals,n);return Object.keys(e).length||(e[""]={$$state:{name:null}}),d(e,function(e,r){return{localsFor:t.self.name?t.self.name:"(root)",uiViewName:r||null,filledByState:e.$$state.name}})},o=a(e),i=e.parent;i&&i!==e;)o=o.concat(a(i)),e=i,i=e.parent;t.debug("Views active on each state:"),console.table(o.reverse())}var c=i,f=c.internalStates,p=c.inherit,v=(c.inheritParams,c.forEach),d=c.map,m=c.filterObj;A.hasParamSet=!!o.ParamSet,j=t.extend(new l("__inactives"),{self:{name:"__inactives"}}),P=w=e,F=[],i.onStateRegistered(function(t){t.self.sticky===!0&&a.registerStickyState(t.self)});var h;r.decorator("$state",["$delegate","$log","$q",function(r,n,i){return P=r.$current,f[""]=P,P.parent=j,j.parent=e,j.locals=p(R,j.locals),P.locals=p(j.locals,P.locals),delete j.locals.globals,h=r.transitionTo,r.transitionTo=function(e,c,p){function m(e){var r=t.extend(new l("reactivate_phase1"),{locals:e.locals});return r.self=t.extend({},e.self),r}function $(e){var r=t.extend(new l("reactivate_phase2"),e),n=r.self.onEnter;return r.resolve={},r.views={},r.self.onEnter=function(){r.locals=e.locals,k.stateReactivated(e)},J.addRestoreFunction(function(){e.self.onEnter=n}),r}function g(t){var e=new l("inactivate");e.self=t.self;var r=t.self.onExit;return e.self.onExit=function(){k.stateInactivated(t)},J.addRestoreFunction(function(){t.self.onExit=r}),e}function x(t,e){var r=t.self.onEnter;return t.self.onEnter=function(){k.stateEntering(t,e,r)},J.addRestoreFunction(function(){t.self.onEnter=r}),t}function y(t,e){var r=t.self.onEnter;return t.self.onEnter=function(){k.stateEntering(t,e,r,!0)},J.addRestoreFunction(function(){t.self.onEnter=r}),t}function S(t){var e=t.self.onExit;return t.self.onExit=function(){k.stateExiting(t,K,e)},J.addRestoreFunction(function(){t.self.onExit=e}),t}var b=a.debugMode();j.locals||(j.locals=P.locals);var E=F.length;w&&(w(),b&&n.debug("Restored paths from pending transition"));var O,T,I,_,q=r.$current,M=r.params,C=p&&p.relative||r.$current,D=r.get(e,C),N=[],K=[];c=c||{},arguments[1]=c;var z=function(){},J=function(){O&&(B.path=O,O=null),T&&(q.path=T,T=null),t.forEach(J.restoreFunctions,function(t){t()}),J=z,w=null,F.splice(E,1)};if(J.restoreFunctions=[],J.addRestoreFunction=function(t){this.restoreFunctions.push(t)},D){var B=f[D.name];if(B){O=B.path,T=q.path;var L=p&&p.reload||!1,V=L&&(L===!0?O[0].self:r.get(L,C));p&&L&&L!==!0&&delete p.reload;var H={toState:B,toParams:c||{},fromState:q,fromParams:M||{},options:p,reloadStateTree:V};if(F.push(H),w=J,V){H.toParams.$$uirouterextrasreload=Math.random();var U=V.$$state().params,W=V.$$state().ownParams;if(A.hasParamSet){var Y=new o.Param("$$uirouterextrasreload");U.$$uirouterextrasreload=W.$$uirouterextrasreload=Y,J.restoreFunctions.push(function(){delete U.$$uirouterextrasreload,delete W.$$uirouterextrasreload})}else U.push("$$uirouterextrasreload"),W.push("$$uirouterextrasreload"),J.restoreFunctions.push(function(){U.length=U.length-1,W.length=W.length-1})}I=k.processTransition(H),b&&u(n,H,I);var G=B.path.slice(0,I.keep),Q=q.path.slice(0,I.keep);t.forEach(j.locals,function(t,e){-1!=e.indexOf("@")&&delete j.locals[e]});var X=function(t){return function(e,r){-1!==r.indexOf("@")&&(t[r]=e)}};v(I.inactives,function(t){v(t.locals,X(j.locals))}),v(I.reactivatingStates,function(t){v(t.locals,X(R))}),J.addRestoreFunction(function(){v(R,function(t,e){delete R[e]})}),t.forEach(I.enter,function(t,e){var r,n=B.path[e];"reactivate"===t?(r=m(n),G.push(r),Q.push(r),N.push($(n)),_=n):"reload"===t?(G.push(y(n)),_=n):"enter"===t&&G.push(x(n))}),t.forEach(I.exit,function(t,e){var r=q.path[e];"inactivate"===t?(Q.push(g(r)),K.push(r)):"exit"===t&&(Q.push(S(r)),K.push(r))}),N.length&&t.forEach(N,function(t){G.push(t)});var Z=I.orphans;Q=Q.concat(d(Z,function(t){return S(t)})),K=K.concat(Z),q.path=Q,B.path=G;var tt=function(t){return(t.surrogateType?t.surrogateType+":":"")+t.self.name};b&&n.debug("SurrogateFromPath: ",d(Q,tt)),b&&n.debug("SurrogateToPath: ",d(G,tt))}}var et=h.apply(r,arguments);return et.then(function(t){return J(),b&&s(n,f[t.name],r),t.status="active",t},function(t){return J(),b&&"transition prevented"!==t.message&&"transition aborted"!==t.message&&"transition superseded"!==t.message&&(n.debug("transition failed",t),n.debug(t.stack)),i.reject(t)})},r}])}]),function(t,e){function r(e,r,n,a){function o(e,r){var n=t.isObject(e)?e.name:e;return r?v[n]:l[n]}function i(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(v[n])return v[n];r.pop()}}if(e.url){var a=[];for(var o in v){var i=v[o].urlMatcher;i&&i.exec(e.url)&&a.push(v[o])}for(var u=a.slice(0),s=a.length-1;s>=0;s--)for(var c=0;c=l.length)){var s=f,c=t.extend(l[s],{to:{state:n,params:a},from:{state:i,params:u}}),v=o(c);p[s]=v,r.$broadcast("$transitionStart",c)}}),e}])}]),function(){"use strict";function e(e,r,n){return{scope:{width:"@",height:"@"},restrict:"AE",template:"",link:function(r,a,o){function i(e){e=e.map(function(e){return""===e.name?p:t.copy(e)}),t.extend(s,e.reduce(function(t,e){return t[e.name]=e,t},{})),e.forEach(function(t){var e=t.name.split(/\./).slice(0,-1).join("."),r=t.name!=e&&s[e];r&&((r.children||(r.children=[])).push(t),t.px=r.px,t.py=r.py,v.push(t))})}function u(){function t(t){var e=t.name.split(".").pop();return t.sticky&&(e+=" (STICKY)"),t.deepStateRedirect&&(e+=" (DSR)"),e}$=$.data(l.nodes(p),function(t){return t.name}),g=g.data(l.links(v),function(t){return t.target.name}),x=x.data(d),v.forEach(function(t){t.y=70*t.depth});var e=$.enter();x.enter().append("circle").attr("class","active").attr("r",13).attr("cx",function(t){return t.parent.px||100}).attr("cy",function(t){return t.parent.py||100}),e.append("circle").attr("class","node").attr("r",9).attr("cx",function(t){return t.parent.px}).attr("cy",function(t){return t.parent.py}),e.append("text").attr("class","label").attr("x",function(t){return t.parent.px}).attr("y",function(t){return t.parent.py}).attr("text-anchor",function(t){return"middle"}).text(t).style("fill-opacity",1),g.enter().insert("path",".node").attr("class","link").attr("d",function(t){var e={x:t.source.px,y:t.source.py};return m({source:e,target:e})});var r=h.transition().duration(S);r.selectAll(".link").attr("d",m);var n={entered:"#AF0",exited:"#777",active:"#0f0",inactive:"#55F",future:"#009"};r.selectAll(".node").attr("cx",function(t){return t.px=t.x}).attr("cy",function(t){return t.py=t.y}).attr("r",function(t){return"active"===t.status?15:10}).style("fill",function(t){return n[t.status]||"#FFF"}),r.selectAll(".label").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15}).attr("transform",function(t){return"rotate(-25 "+t.x+" "+t.y+")"}),r.selectAll(".active").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15})}var s={},c=r.width||400,f=r.height||400,l=d3.layout.tree().size([c-20,f-20]).separation(function(t,e){return t.parent==e.parent?10:25}),p=e.get().filter(function(t){return""===t.name})[0],v=l(p);p.parent=p,p.px=p.x=c/2,p.py=p.y=f/2;var d={};d.px=d.x=p.px,d.py=d.y=p.py;var m=d3.svg.diagonal(),h=d3.select(a.find("svg")[0]).attr("width",c).attr("height",f).append("g").attr("transform","translate(10, 10)"),$=h.selectAll(".node"),g=h.selectAll(".link"),x=h.selectAll(".active"),y=200,S=200;setInterval(u,y);n(function(){r.states=e.get(),t.forEach(v,function(t){var r=e.get(t.name);r&&(t.status=r.status||"exited")})},250),r.$watchCollection("states",function(t,e){var r=(e||[]).map(function(t){return t.name});i((t||[]).filter(function(t){return-1==r.indexOf(t.name)}))}),u(y)}}}var r=t.module("ct.ui.router.extras.statevis",["ct.ui.router.extras.core","ct.ui.router.extras.sticky"]);r.directive("stateVis",["$state","$timeout","$interval",e])}(),t.module("ct.ui.router.extras",["ct.ui.router.extras.core","ct.ui.router.extras.dsr","ct.ui.router.extras.future","ct.ui.router.extras.previous","ct.ui.router.extras.statevis","ct.ui.router.extras.sticky","ct.ui.router.extras.transition"])}); \ No newline at end of file diff --git a/release/modular/ct-ui-router-extras.core.js b/release/modular/ct-ui-router-extras.core.js index 1d3fffa..a3e5e33 100644 --- a/release/modular/ct-ui-router-extras.core.js +++ b/release/modular/ct-ui-router-extras.core.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Module: core - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ diff --git a/release/modular/ct-ui-router-extras.core.min.js b/release/modular/ct-ui-router-extras.core.min.js index 8c9905c..c446111 100644 --- a/release/modular/ct-ui-router-extras.core.min.js +++ b/release/modular/ct-ui-router-extras.core.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Module: core http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +/** UI-Router Extras v.0.1.3 Module: core http://christopherthielen.github.io/ui-router-extras/ - MIT License */ !function(r,n){"use strict";function t(r,n){var t=[];for(var e in r.path){if(r.path[e]!==n.path[e])break;t.push(r.path[e])}return t}function e(n){if(Object.keys)return Object.keys(n);var t=[];return r.forEach(n,function(r,n){t.push(n)}),t}function i(r,n){var t=[];for(var e in r)n&&-1!==n.indexOf(e)||t.push(e);return t}function u(r,n){if(Array.prototype.indexOf)return r.indexOf(n,Number(arguments[2])||0);var t=r.length>>>0,e=Number(arguments[2])||0;for(e=0>e?Math.ceil(e):Math.floor(e),0>e&&(e+=t);t>e;e++)if(e in r&&r[e]===n)return e;return-1}function a(r,n,i,a){var o,f=t(i,a),c={},s=[];for(var h in f)if(f[h].params&&(o=l(f[h].params)?f[h].params:e(f[h].params),o.length))for(var p in o)u(s,o[p])>=0||(s.push(o[p]),c[o[p]]=r[o[p]]);return v({},c,n)}function o(r,n){return v(new(v(function(){},{prototype:r})),n)}function f(r){h.push(r)}var c=r.module("ct.ui.router.extras.core",["ui.router"]),s={},h=[];c.config(["$stateProvider","$injector",function(n,t){n.decorator("parent",function(n,t){return s[n.self.name]=n,n.self.$$state=function(){return s[n.self.name]},r.forEach(h,function(r){r(n)}),t(n)})}]);var p=r.forEach,v=r.extend,l=r.isArray,d=function(r,n){var t=[];return p(r,function(r,e){t.push(n(r,e))}),t},m=function(r){return d(r,function(r,n){return n})},y=function(r,n){var t=[];return p(r,function(r,e){n(r,e)&&t.push(r)}),t},x=function(r,n){var t={};return p(r,function(r,e){n(r,e)&&(t[e]=r)}),t};c.provider("uirextras_core",function(){var n={internalStates:s,onStateRegistered:f,forEach:p,extend:v,isArray:l,map:d,keys:m,filter:y,filterObj:x,ancestors:t,objectKeys:e,protoKeys:i,arraySearch:u,inheritParams:a,inherit:o};r.extend(this,n),this.$get=function(){return n}})}(angular); \ No newline at end of file diff --git a/release/modular/ct-ui-router-extras.dsr.js b/release/modular/ct-ui-router-extras.dsr.js index 1772b51..17d4d94 100644 --- a/release/modular/ct-ui-router-extras.dsr.js +++ b/release/modular/ct-ui-router-extras.dsr.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Module: dsr - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ @@ -19,7 +19,7 @@ angular.module('ct.ui.router.extras.dsr', [ 'ct.ui.router.extras.core' ]).config $provide.decorator("$state", ['$delegate', '$q', function ($state, $q) { $state_transitionTo = $state.transitionTo; $state.transitionTo = function (to, toParams, options) { - if (options.ignoreDsr) { + if (options && options.ignoreDsr) { ignoreDsr = options.ignoreDsr; } @@ -151,7 +151,12 @@ angular.module('ct.ui.router.extras.dsr').service("$deepStateRedirect", [ '$root computeDeepStateStatus(state) var cfg = getConfig(state); var key = getParamsString(params, cfg.params); - var redirect = lastSubstate[state.name][key] || cfg['default']; + var redirect = lastSubstate[state.name]; + if (redirect && redirect[key]) { + redirect = redirect[key]; + } else { + redirect = cfg['default']; + } return redirect; }, reset: function(stateOrName, params) { diff --git a/release/modular/ct-ui-router-extras.dsr.min.js b/release/modular/ct-ui-router-extras.dsr.min.js index 4e5af46..b97ebdc 100644 --- a/release/modular/ct-ui-router-extras.dsr.min.js +++ b/release/modular/ct-ui-router-extras.dsr.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Module: dsr http://christopherthielen.github.io/ui-router-extras/ - MIT License */ -!function(t,e){"use strict";function r(){n=e}var n;t.module("ct.ui.router.extras.dsr",["ct.ui.router.extras.core"]).config(["$provide",function(t){var e;t.decorator("$state",["$delegate","$q",function(t,a){return e=t.transitionTo,t.transitionTo=function(o,i,u){return u.ignoreDsr&&(n=u.ignoreDsr),e.apply(t,arguments).then(function(t){return r(),t},function(t){return r(),a.reject(t)})},t}])}]),t.module("ct.ui.router.extras.dsr").service("$deepStateRedirect",["$rootScope","$state","$injector",function(r,a,o){function i(t){var e=t.name;return v.hasOwnProperty(e)?v[e]:void s(e)}function u(e){var r=e.deepStateRedirect||e.dsr;if(!r)return{dsr:!1};var n={dsr:!0};return t.isFunction(r)?n.fn=r:t.isObject(r)&&(n=t.extend(n,r)),t.isString(n["default"])&&(n["default"]={state:n["default"]}),n.fn||(n.fn=["$dsr$",function(t){return t.redirect.state!=t.to.state}]),n}function s(t){var r=a.get(t);if(!r)return!1;var n=u(r);n.dsr&&(v[r.name]=m,d[t]===e&&(d[t]={}));var o=r.$$state&&r.$$state().parent;if(o){var i=s(o.self.name);i&&v[r.name]===e&&(v[r.name]=$)}return v[r.name]||!1}function c(r,n){n===!0&&(n=Object.keys(r)),null!==n&&n!==e||(n=[]);var a={};return t.forEach(n.sort(),function(t){a[t]=r[t]}),a}function f(e,r){function n(t){return t?t.toString():t}var a=c(e,r),o={};return t.forEach(a,function(t,e){o[e]=n(t)}),t.toJson(o)}var d={},v={},m="Redirect",$="AncestorRedirect";return r.$on("$stateChangeStart",function(e,r,s,v,$){var p=u(r);if(!n&&(i(r)===m||p["default"])){var l=f(s,p.params),g=d[r.name][l]||p["default"];if(g){var h={redirect:{state:g.state,params:g.params},to:{state:r.name,params:s}},S=o.invoke(p.fn,r,{$dsr$:h});if(S){S.state&&(g=S),e.preventDefault();var x=c(s,p.params);a.go(g.state,t.extend(x,g.params))}}}}),r.$on("$stateChangeSuccess",function(e,r,n,o,s){var c=i(r);if(c){var v=r.name;t.forEach(d,function(e,o){var i=u(a.get(o)),s=f(n,i.params);r.$$state().includes[o]&&(d[o][s]={state:v,params:t.copy(n)})})}}),{getRedirect:function(t,e){var r=a.get(t);i(r);var n=u(r),o=f(e,n.params),s=d[r.name][o]||n["default"];return s},reset:function(e,r){if(e){var n=a.get(e);if(!n)throw new Error("Unknown state: "+e);if(d[n.name])if(r){var o=f(r,u(n).params);delete d[n.name][o]}else d[n.name]={}}else t.forEach(d,function(t,e){d[e]={}})}}}]),t.module("ct.ui.router.extras.dsr").run(["$deepStateRedirect",function(t){}])}(angular); \ No newline at end of file +/** UI-Router Extras v.0.1.3 Module: dsr http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +!function(t,e){"use strict";function r(){n=e}var n;t.module("ct.ui.router.extras.dsr",["ct.ui.router.extras.core"]).config(["$provide",function(t){var e;t.decorator("$state",["$delegate","$q",function(t,a){return e=t.transitionTo,t.transitionTo=function(o,i,u){return u&&u.ignoreDsr&&(n=u.ignoreDsr),e.apply(t,arguments).then(function(t){return r(),t},function(t){return r(),a.reject(t)})},t}])}]),t.module("ct.ui.router.extras.dsr").service("$deepStateRedirect",["$rootScope","$state","$injector",function(r,a,o){function i(t){var e=t.name;return v.hasOwnProperty(e)?v[e]:void s(e)}function u(e){var r=e.deepStateRedirect||e.dsr;if(!r)return{dsr:!1};var n={dsr:!0};return t.isFunction(r)?n.fn=r:t.isObject(r)&&(n=t.extend(n,r)),t.isString(n["default"])&&(n["default"]={state:n["default"]}),n.fn||(n.fn=["$dsr$",function(t){return t.redirect.state!=t.to.state}]),n}function s(t){var r=a.get(t);if(!r)return!1;var n=u(r);n.dsr&&(v[r.name]=m,d[t]===e&&(d[t]={}));var o=r.$$state&&r.$$state().parent;if(o){var i=s(o.self.name);i&&v[r.name]===e&&(v[r.name]=$)}return v[r.name]||!1}function c(r,n){n===!0&&(n=Object.keys(r)),null!==n&&n!==e||(n=[]);var a={};return t.forEach(n.sort(),function(t){a[t]=r[t]}),a}function f(e,r){function n(t){return t?t.toString():t}var a=c(e,r),o={};return t.forEach(a,function(t,e){o[e]=n(t)}),t.toJson(o)}var d={},v={},m="Redirect",$="AncestorRedirect";return r.$on("$stateChangeStart",function(e,r,s,v,$){var p=u(r);if(!n&&(i(r)===m||p["default"])){var l=f(s,p.params),g=d[r.name][l]||p["default"];if(g){var h={redirect:{state:g.state,params:g.params},to:{state:r.name,params:s}},S=o.invoke(p.fn,r,{$dsr$:h});if(S){S.state&&(g=S),e.preventDefault();var x=c(s,p.params);a.go(g.state,t.extend(x,g.params))}}}}),r.$on("$stateChangeSuccess",function(e,r,n,o,s){var c=i(r);if(c){var v=r.name;t.forEach(d,function(e,o){var i=u(a.get(o)),s=f(n,i.params);r.$$state().includes[o]&&(d[o][s]={state:v,params:t.copy(n)})})}}),{getRedirect:function(t,e){var r=a.get(t);i(r);var n=u(r),o=f(e,n.params),s=d[r.name];return s=s&&s[o]?s[o]:n["default"]},reset:function(e,r){if(e){var n=a.get(e);if(!n)throw new Error("Unknown state: "+e);if(d[n.name])if(r){var o=f(r,u(n).params);delete d[n.name][o]}else d[n.name]={}}else t.forEach(d,function(t,e){d[e]={}})}}}]),t.module("ct.ui.router.extras.dsr").run(["$deepStateRedirect",function(t){}])}(angular); \ No newline at end of file diff --git a/release/modular/ct-ui-router-extras.future.js b/release/modular/ct-ui-router-extras.future.js index e043638..4caf7ba 100644 --- a/release/modular/ct-ui-router-extras.future.js +++ b/release/modular/ct-ui-router-extras.future.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Module: future - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ diff --git a/release/modular/ct-ui-router-extras.future.min.js b/release/modular/ct-ui-router-extras.future.min.js index a3edda8..8dd8eac 100644 --- a/release/modular/ct-ui-router-extras.future.min.js +++ b/release/modular/ct-ui-router-extras.future.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Module: future http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +/** UI-Router Extras v.0.1.3 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",link:function(n,a,i){function c(e){e=e.map(function(e){return""===e.name?f:t.copy(e)}),t.extend(o,e.reduce(function(t,e){return t[e.name]=e,t},{})),e.forEach(function(t){var e=t.name.split(/\./).slice(0,-1).join("."),n=t.name!=e&&o[e];n&&((n.children||(n.children=[])).push(t),t.px=n.px,t.py=n.py,d.push(t))})}function u(){function t(t){var e=t.name.split(".").pop();return t.sticky&&(e+=" (STICKY)"),t.deepStateRedirect&&(e+=" (DSR)"),e}h=h.data(p.nodes(f),function(t){return t.name}),m=m.data(p.links(d),function(t){return t.target.name}),g=g.data(x),d.forEach(function(t){t.y=70*t.depth});var e=h.enter();g.enter().append("circle").attr("class","active").attr("r",13).attr("cx",function(t){return t.parent.px||100}).attr("cy",function(t){return t.parent.py||100}),e.append("circle").attr("class","node").attr("r",9).attr("cx",function(t){return t.parent.px}).attr("cy",function(t){return t.parent.py}),e.append("text").attr("class","label").attr("x",function(t){return t.parent.px}).attr("y",function(t){return t.parent.py}).attr("text-anchor",function(t){return"middle"}).text(t).style("fill-opacity",1),m.enter().insert("path",".node").attr("class","link").attr("d",function(t){var e={x:t.source.px,y:t.source.py};return y({source:e,target:e})});var n=v.transition().duration(k);n.selectAll(".link").attr("d",y);var r={entered:"#AF0",exited:"#777",active:"#0f0",inactive:"#55F",future:"#009"};n.selectAll(".node").attr("cx",function(t){return t.px=t.x}).attr("cy",function(t){return t.py=t.y}).attr("r",function(t){return"active"===t.status?15:10}).style("fill",function(t){return r[t.status]||"#FFF"}),n.selectAll(".label").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15}).attr("transform",function(t){return"rotate(-25 "+t.x+" "+t.y+")"}),n.selectAll(".active").attr("x",function(t){return t.px=t.x}).attr("y",function(t){return t.py=t.y-15})}var o={},s=n.width||400,l=n.height||400,p=d3.layout.tree().size([s-20,l-20]).separation(function(t,e){return t.parent==e.parent?10:25}),f=e.get().filter(function(t){return""===t.name})[0],d=p(f);f.parent=f,f.px=f.x=s/2,f.py=f.y=l/2;var x={};x.px=x.x=f.px,x.py=x.y=f.py;var y=d3.svg.diagonal(),v=d3.select(a.find("svg")[0]).attr("width",s).attr("height",l).append("g").attr("transform","translate(10, 10)"),h=v.selectAll(".node"),m=v.selectAll(".link"),g=v.selectAll(".active"),A=200,k=200;setInterval(u,A);r(function(){n.states=e.get(),t.forEach(d,function(t){var n=e.get(t.name);n&&(t.status=n.status||"exited")})},250),n.$watchCollection("states",function(t,e){var n=(e||[]).map(function(t){return t.name});c((t||[]).filter(function(t){return-1==n.indexOf(t.name)}))}),u(A)}}}var n=t.module("ct.ui.router.extras.statevis",["ct.ui.router.extras.core","ct.ui.router.extras.sticky"]);n.directive("stateVis",["$state","$timeout","$interval",e])}()}(angular); \ No newline at end of file diff --git a/release/modular/ct-ui-router-extras.sticky.js b/release/modular/ct-ui-router-extras.sticky.js index 3a41f86..db96ecc 100644 --- a/release/modular/ct-ui-router-extras.sticky.js +++ b/release/modular/ct-ui-router-extras.sticky.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Module: sticky - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ @@ -159,10 +159,13 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { }; } + function sortByStateDepth(a,b) { + return a.name.split(".").length - b.name.split(".").length; + } var stickySupport = { getInactiveStates: function () { - return map(inactiveStates, angular.identity); + return map(inactiveStates, angular.identity).sort(sortByStateDepth); }, getInactiveStatesByParent: function () { return mapInactives(); @@ -180,7 +183,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { // } processTransition: function (transition) { var treeChanges = calcTreeChanges(transition); - var currentInactives = map(inactiveStates, angular.identity); + var currentInactives = stickySupport.getInactiveStates(); var futureInactives, exitingTypes, enteringTypes; var keep = treeChanges.keep; @@ -268,7 +271,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { .reduce(flattenReduce, []) .concat(orphanedRoots) // Sort by depth to exit orphans in proper order - .sort(function (a,b) { return a.name.split(".").length - b.name.split(".").length; }); + .sort(sortByStateDepth); // Add them to the list of states being exited. var exitOrOrphaned = exitingTypes @@ -282,7 +285,8 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) { futureInactives = currentInactives .filter(notIn(exitOrOrphaned)) .filter(notIn(treeChanges.entering)) - .concat(exitingTypes.filter(typeIs("inactivate")).map(prop("state"))); + .concat(exitingTypes.filter(typeIs("inactivate")).map(prop("state"))) + .sort(sortByStateDepth); return { keep: keep, @@ -902,30 +906,36 @@ angular.module("ct.ui.router.extras.sticky").config( return s.self.name; })); - var viewMsg = function (local, name) { - return "'" + name + "' (" + local.$$state.name + ")"; - }; var statesOnly = function (local, name) { return name != 'globals' && name != 'resolve'; }; + var viewsForState = function (state) { - var views = map(filterObj(state.locals, statesOnly), viewMsg).join(", "); - return "(" + (state.self.name ? state.self.name : "root") + ".locals" + (views.length ? ": " + views : "") + ")"; + var viewLocals = filterObj(state.locals, statesOnly); + + if (!Object.keys(viewLocals).length) { + viewLocals[''] = { $$state: { name: null } }; + } + + return map(viewLocals, function(local, name) { + return { + localsFor: state.self.name ? state.self.name : "(root)", + uiViewName: name || null, + filledByState: local.$$state.name + }; + }); }; - var message = viewsForState(currentState); + var viewsByState = viewsForState(currentState); var parent = currentState.parent; while (parent && parent !== currentState) { - if (parent.self.name === "") { - // Show the __inactives before showing root state. - message = viewsForState($state.$current.path[0]) + " / " + message; - } - message = viewsForState(parent) + " / " + message; + viewsByState = viewsByState.concat(viewsForState(parent)); currentState = parent; parent = currentState.parent; } - $log.debug("Views: " + message); + $log.debug("Views active on each state:"); + console.table(viewsByState.reverse()); } } ] diff --git a/release/modular/ct-ui-router-extras.sticky.min.js b/release/modular/ct-ui-router-extras.sticky.min.js index 7289d1b..5d72882 100644 --- a/release/modular/ct-ui-router-extras.sticky.min.js +++ b/release/modular/ct-ui-router-extras.sticky.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Module: sticky http://christopherthielen.github.io/ui-router-extras/ - MIT License */ -!function(e,t){"use strict";function n(t,n){var r=n,a=r.inheritParams,i=(r.objectKeys,r.protoKeys),o=r.forEach,s=r.map,c={},l={},f=!1;this.registerStickyState=function(e){l[e.name]=e},this.enableDebug=this.debugMode=function(t){return e.isDefined(t)&&(f=t),f},this.$get=["$rootScope","$state","$stateParams","$injector","$log",function(t,n,r,l,v){function d(){var t={};return e.forEach(c,function(e,n){for(var r=m(e),a=0;a0;f=d.exiting.map(function(e){var t=-1!==d.entering.indexOf(e),n=x&&!t?"inactivate":"exit";return{type:n,state:e}});var E=t.options&&!!t.options.reload;v=d.entering.map(function(e){var n=g(e,t.toParams,t.reloadStateTree,E);return E=E||"reload"===n,{type:n,state:e}});var S=d.entering.map(function(e){return m.filter(o(e.parent))}).reduce(r,[]).filter($).filter(u).concat(m.filter(o(t.toState))),P=p(),y=S.map(function(e){return P[e.name]}).filter(e.isDefined).reduce(r,[]).concat(S).sort(function(e,t){return e.name.split(".").length-t.name.split(".").length}),k=f.filter(i("exit")).map(a("state")).concat(y);return l=m.filter(n(k)).filter(n(d.entering)).concat(f.filter(i("inactivate")).map(a("state"))),{keep:h,enter:new Array(h).concat(v.map(a("type"))),exit:new Array(h).concat(f.map(a("type"))),inactives:l,reactivatingStates:v.filter(i("reactivate")).map(a("state")),orphans:y}},stateInactivated:function(e){c[e.self.name]=e,e.self.status="inactive",e.self.onInactivate&&l.invoke(e.self.onInactivate,e.self,e.locals.globals)},stateReactivated:function(e){c[e.self.name]&&delete c[e.self.name],e.self.status="entered",e.self.onReactivate&&l.invoke(e.self.onReactivate,e.self,e.locals.globals)},stateExiting:function(t,n,r){var a={};e.forEach(n,function(e){a[e.self.name]=!0}),e.forEach(c,function(n,r){!a[r]&&n.includes[t.name]&&(f&&v.debug("Exiting "+r+" because it's a substate of "+t.name+" and wasn't found in ",a),n.self.onExit&&l.invoke(n.self.onExit,n.self,n.locals.globals),e.forEach(n.locals,function(e,t){delete u.locals[t]}),n.locals=null,n.self.status="exited",delete c[r])}),r&&l.invoke(r,t.self,t.locals.globals),t.locals=null,t.self.status="exited",delete c[t.self.name]},stateEntering:function(e,t,n,r){var a=h(e);if(a&&(r||!h(e,t))){var i=e.locals;this.stateExiting(a),e.locals=i}e.self.status="entered",n&&l.invoke(n,e.self,e.locals.globals)},reset:function(r,a){function i(e){E.reset(e)}if("*"===r)return e.forEach(E.getInactiveStates(),i),!0;var o=n.get(r);if(!o)return!1;var s=h(o,a);return s?(E.stateExiting(s),t.$broadcast("$viewContentLoading"),!0):!1}};return E}]}function r(e){return{resolve:{},locals:{globals:o&&o.locals&&o.locals.globals},views:{},self:{},params:{},ownParams:f.hasParamSet?{$$equals:function(){return!0}}:[],surrogateType:e}}e.module("ct.ui.router.extras.sticky",["ct.ui.router.extras.core"]);var a=e.module("ct.ui.router.extras.sticky");n.$inject=["$stateProvider","uirextras_coreProvider"],a.provider("$stickyState",n);var i,o,s,u,c=[],l={},f={hasParamSet:!1};e.module("ct.ui.router.extras.sticky").run(["$stickyState",function(e){i=e}]),e.module("ct.ui.router.extras.sticky").config(["$provide","$stateProvider","$stickyStateProvider","$urlMatcherFactoryProvider","uirextras_coreProvider",function(n,a,v,d,p){function m(t,n,r){function a(e,t,n){return e[t]?e[t].toUpperCase()+": "+n.self.name:"("+n.self.name+")"}var o=E(r.inactives,function(e){return e.self.name}),s=E(n.toState.path,function(e,t){return a(r.enter,t,e)}),u=E(n.fromState.path,function(e,t){return a(r.exit,t,e)}),c=n.fromState.self.name+": "+e.toJson(n.fromParams)+": -> "+n.toState.self.name+": "+e.toJson(n.toParams);t.debug("------------------------------------------------------"),t.debug(" Current transition: ",c),t.debug("Before transition, inactives are: : ",E(i.getInactiveStates(),function(e){return e.self.name})),t.debug("After transition, inactives will be: ",o),t.debug("Transition will exit: ",u),t.debug("Transition will enter: ",s)}function g(e,t,n){e.debug("Current state: "+t.self.name+", inactive states: ",E(i.getInactiveStates(),function(e){return e.self.name}));for(var r=function(e,t){return"'"+t+"' ("+e.$$state.name+")"},a=function(e,t){return"globals"!=t&&"resolve"!=t},o=function(e){var t=E(S(e.locals,a),r).join(", ");return"("+(e.self.name?e.self.name:"root")+".locals"+(t.length?": "+t:"")+")"},s=o(t),u=t.parent;u&&u!==t;)""===u.self.name&&(s=o(n.$current.path[0])+" / "+s),s=o(u)+" / "+s,t=u,u=t.parent;e.debug("Views: "+s)}var h=p,$=h.internalStates,x=h.inherit,b=(h.inheritParams,h.forEach),E=h.map,S=h.filterObj;f.hasParamSet=!!d.ParamSet,u=e.extend(new r("__inactives"),{self:{name:"__inactives"}}),o=s=t,c=[],p.onStateRegistered(function(e){e.self.sticky===!0&&v.registerStickyState(e.self)});var P;n.decorator("$state",["$delegate","$log","$q",function(n,a,p){return o=n.$current,$[""]=o,o.parent=u,u.parent=t,u.locals=x(l,u.locals),o.locals=x(u.locals,o.locals),delete u.locals.globals,P=n.transitionTo,n.transitionTo=function(t,h,x){function S(t){var n=e.extend(new r("reactivate_phase1"),{locals:t.locals});return n.self=e.extend({},t.self),n}function y(t){var n=e.extend(new r("reactivate_phase2"),t),a=n.self.onEnter;return n.resolve={},n.views={},n.self.onEnter=function(){n.locals=t.locals,i.stateReactivated(t)},L.addRestoreFunction(function(){t.self.onEnter=a}),n}function k(e){var t=new r("inactivate");t.self=e.self;var n=e.self.onExit;return t.self.onExit=function(){i.stateInactivated(e)},L.addRestoreFunction(function(){e.self.onExit=n}),t}function w(e,t){var n=e.self.onEnter;return e.self.onEnter=function(){i.stateEntering(e,t,n)},L.addRestoreFunction(function(){e.self.onEnter=n}),e}function F(e,t){var n=e.self.onEnter;return e.self.onEnter=function(){i.stateEntering(e,t,n,!0)},L.addRestoreFunction(function(){e.self.onEnter=n}),e}function R(e){var t=e.self.onExit;return e.self.onExit=function(){i.stateExiting(e,J,t)},L.addRestoreFunction(function(){e.self.onExit=t}),e}var T=v.debugMode();u.locals||(u.locals=o.locals);var _=c.length;s&&(s(),T&&a.debug("Restored paths from pending transition"));var I,j,O,q,A=n.$current,C=n.params,M=x&&x.relative||n.$current,D=n.get(t,M),B=[],J=[];h=h||{},arguments[1]=h;var K=function(){},L=function(){I&&(U.path=I,I=null),j&&(A.path=j,j=null),e.forEach(L.restoreFunctions,function(e){e()}),L=K,s=null,c.splice(_,1)};if(L.restoreFunctions=[],L.addRestoreFunction=function(e){this.restoreFunctions.push(e)},D){var U=$[D.name];if(U){I=U.path,j=A.path;var V=x&&x.reload||!1,z=V&&(V===!0?I[0].self:n.get(V,M));x&&V&&V!==!0&&delete x.reload;var G={toState:U,toParams:h||{},fromState:A,fromParams:C||{},options:x,reloadStateTree:z};if(c.push(G),s=L,z){G.toParams.$$uirouterextrasreload=Math.random();var H=z.$$state().params,N=z.$$state().ownParams;if(f.hasParamSet){var Q=new d.Param("$$uirouterextrasreload");H.$$uirouterextrasreload=N.$$uirouterextrasreload=Q,L.restoreFunctions.push(function(){delete H.$$uirouterextrasreload,delete N.$$uirouterextrasreload})}else H.push("$$uirouterextrasreload"),N.push("$$uirouterextrasreload"),L.restoreFunctions.push(function(){H.length=H.length-1,N.length=N.length-1})}O=i.processTransition(G),T&&m(a,G,O);var W=U.path.slice(0,O.keep),X=A.path.slice(0,O.keep);e.forEach(u.locals,function(e,t){-1!=t.indexOf("@")&&delete u.locals[t]});var Y=function(e){return function(t,n){-1!==n.indexOf("@")&&(e[n]=t)}};b(O.inactives,function(e){b(e.locals,Y(u.locals))}),b(O.reactivatingStates,function(e){b(e.locals,Y(l))}),L.addRestoreFunction(function(){b(l,function(e,t){delete l[t]})}),e.forEach(O.enter,function(e,t){var n,r=U.path[t];"reactivate"===e?(n=S(r),W.push(n),X.push(n),B.push(y(r)),q=r):"reload"===e?(W.push(F(r)),q=r):"enter"===e&&W.push(w(r))}),e.forEach(O.exit,function(e,t){var n=A.path[t];"inactivate"===e?(X.push(k(n)),J.push(n)):"exit"===e&&(X.push(R(n)),J.push(n))}),B.length&&e.forEach(B,function(e){W.push(e)});var Z=O.orphans;X=X.concat(E(Z,function(e){return R(e)})),J=J.concat(Z),A.path=X,U.path=W;var ee=function(e){return(e.surrogateType?e.surrogateType+":":"")+e.self.name};T&&a.debug("SurrogateFromPath: ",E(X,ee)),T&&a.debug("SurrogateToPath: ",E(W,ee))}}var te=P.apply(n,arguments);return te.then(function(e){return L(),T&&g(a,$[e.name],n),e.status="active",e},function(e){return L(),T&&"transition prevented"!==e.message&&"transition aborted"!==e.message&&"transition superseded"!==e.message&&(a.debug("transition failed",e),a.debug(e.stack)),p.reject(e)})},n}])}])}(angular); \ No newline at end of file +/** UI-Router Extras v.0.1.3 Module: sticky http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +!function(e,t){"use strict";function n(t,n){var a=n,r=a.inheritParams,o=(a.objectKeys,a.protoKeys),i=a.forEach,s=a.map,c={},l={},f=!1;this.registerStickyState=function(e){l[e.name]=e},this.enableDebug=this.debugMode=function(t){return e.isDefined(t)&&(f=t),f},this.$get=["$rootScope","$state","$stateParams","$injector","$log",function(t,n,a,l,v){function d(){var t={};return e.forEach(c,function(e,n){for(var a=m(e),r=0;r0;c=f.exiting.map(function(e){var t=-1!==f.entering.indexOf(e),n=h&&!t?"inactivate":"exit";return{type:n,state:e}});var $=t.options&&!!t.options.reload;l=f.entering.map(function(e){var n=g(e,t.toParams,t.reloadStateTree,$);return $=$||"reload"===n,{type:n,state:e}});var x=f.entering.map(function(e){return v.filter(i(e.parent))}).reduce(a,[]).filter(m).filter(s).concat(v.filter(i(t.toState))),y=p(),P=x.map(function(e){return y[e.name]}).filter(e.isDefined).reduce(a,[]).concat(x).sort(S),k=c.filter(o("exit")).map(r("state")).concat(P);return u=v.filter(n(k)).filter(n(f.entering)).concat(c.filter(o("inactivate")).map(r("state"))).sort(S),{keep:d,enter:new Array(d).concat(l.map(r("type"))),exit:new Array(d).concat(c.map(r("type"))),inactives:u,reactivatingStates:l.filter(o("reactivate")).map(r("state")),orphans:P}},stateInactivated:function(e){c[e.self.name]=e,e.self.status="inactive",e.self.onInactivate&&l.invoke(e.self.onInactivate,e.self,e.locals.globals)},stateReactivated:function(e){c[e.self.name]&&delete c[e.self.name],e.self.status="entered",e.self.onReactivate&&l.invoke(e.self.onReactivate,e.self,e.locals.globals)},stateExiting:function(t,n,a){var r={};e.forEach(n,function(e){r[e.self.name]=!0}),e.forEach(c,function(n,a){!r[a]&&n.includes[t.name]&&(f&&v.debug("Exiting "+a+" because it's a substate of "+t.name+" and wasn't found in ",r),n.self.onExit&&l.invoke(n.self.onExit,n.self,n.locals.globals),e.forEach(n.locals,function(e,t){delete u.locals[t]}),n.locals=null,n.self.status="exited",delete c[a])}),a&&l.invoke(a,t.self,t.locals.globals),t.locals=null,t.self.status="exited",delete c[t.self.name]},stateEntering:function(e,t,n,a){var r=h(e);if(r&&(a||!h(e,t))){var o=e.locals;this.stateExiting(r),e.locals=o}e.self.status="entered",n&&l.invoke(n,e.self,e.locals.globals)},reset:function(a,r){function o(e){E.reset(e)}if("*"===a)return e.forEach(E.getInactiveStates(),o),!0;var i=n.get(a);if(!i)return!1;var s=h(i,r);return s?(E.stateExiting(s),t.$broadcast("$viewContentLoading"),!0):!1}};return E}]}function a(e){return{resolve:{},locals:{globals:i&&i.locals&&i.locals.globals},views:{},self:{},params:{},ownParams:f.hasParamSet?{$$equals:function(){return!0}}:[],surrogateType:e}}e.module("ct.ui.router.extras.sticky",["ct.ui.router.extras.core"]);var r=e.module("ct.ui.router.extras.sticky");n.$inject=["$stateProvider","uirextras_coreProvider"],r.provider("$stickyState",n);var o,i,s,u,c=[],l={},f={hasParamSet:!1};e.module("ct.ui.router.extras.sticky").run(["$stickyState",function(e){o=e}]),e.module("ct.ui.router.extras.sticky").config(["$provide","$stateProvider","$stickyStateProvider","$urlMatcherFactoryProvider","uirextras_coreProvider",function(n,r,v,d,p){function m(t,n,a){function r(e,t,n){return e[t]?e[t].toUpperCase()+": "+n.self.name:"("+n.self.name+")"}var i=S(a.inactives,function(e){return e.self.name}),s=S(n.toState.path,function(e,t){return r(a.enter,t,e)}),u=S(n.fromState.path,function(e,t){return r(a.exit,t,e)}),c=n.fromState.self.name+": "+e.toJson(n.fromParams)+": -> "+n.toState.self.name+": "+e.toJson(n.toParams);t.debug("------------------------------------------------------"),t.debug(" Current transition: ",c),t.debug("Before transition, inactives are: : ",S(o.getInactiveStates(),function(e){return e.self.name})),t.debug("After transition, inactives will be: ",i),t.debug("Transition will exit: ",u),t.debug("Transition will enter: ",s)}function g(e,t,n){e.debug("Current state: "+t.self.name+", inactive states: ",S(o.getInactiveStates(),function(e){return e.self.name}));for(var a=function(e,t){return"globals"!=t&&"resolve"!=t},r=function(e){var t=E(e.locals,a);return Object.keys(t).length||(t[""]={$$state:{name:null}}),S(t,function(t,n){return{localsFor:e.self.name?e.self.name:"(root)",uiViewName:n||null,filledByState:t.$$state.name}})},i=r(t),s=t.parent;s&&s!==t;)i=i.concat(r(s)),t=s,s=t.parent;e.debug("Views active on each state:"),console.table(i.reverse())}var h=p,$=h.internalStates,x=h.inherit,b=(h.inheritParams,h.forEach),S=h.map,E=h.filterObj;f.hasParamSet=!!d.ParamSet,u=e.extend(new a("__inactives"),{self:{name:"__inactives"}}),i=s=t,c=[],p.onStateRegistered(function(e){e.self.sticky===!0&&v.registerStickyState(e.self)});var y;n.decorator("$state",["$delegate","$log","$q",function(n,r,p){return i=n.$current,$[""]=i,i.parent=u,u.parent=t,u.locals=x(l,u.locals),i.locals=x(u.locals,i.locals),delete u.locals.globals,y=n.transitionTo,n.transitionTo=function(t,h,x){function E(t){var n=e.extend(new a("reactivate_phase1"),{locals:t.locals});return n.self=e.extend({},t.self),n}function P(t){var n=e.extend(new a("reactivate_phase2"),t),r=n.self.onEnter;return n.resolve={},n.views={},n.self.onEnter=function(){n.locals=t.locals,o.stateReactivated(t)},V.addRestoreFunction(function(){t.self.onEnter=r}),n}function k(e){var t=new a("inactivate");t.self=e.self;var n=e.self.onExit;return t.self.onExit=function(){o.stateInactivated(e)},V.addRestoreFunction(function(){e.self.onExit=n}),t}function w(e,t){var n=e.self.onEnter;return e.self.onEnter=function(){o.stateEntering(e,t,n)},V.addRestoreFunction(function(){e.self.onEnter=n}),e}function F(e,t){var n=e.self.onEnter;return e.self.onEnter=function(){o.stateEntering(e,t,n,!0)},V.addRestoreFunction(function(){e.self.onEnter=n}),e}function R(e){var t=e.self.onExit;return e.self.onExit=function(){o.stateExiting(e,J,t)},V.addRestoreFunction(function(){e.self.onExit=t}),e}var T=v.debugMode();u.locals||(u.locals=i.locals);var I=c.length;s&&(s(),T&&r.debug("Restored paths from pending transition"));var _,j,O,q,A=n.$current,C=n.params,M=x&&x.relative||n.$current,B=n.get(t,M),D=[],J=[];h=h||{},arguments[1]=h;var K=function(){},V=function(){_&&(L.path=_,_=null),j&&(A.path=j,j=null),e.forEach(V.restoreFunctions,function(e){e()}),V=K,s=null,c.splice(I,1)};if(V.restoreFunctions=[],V.addRestoreFunction=function(e){this.restoreFunctions.push(e)},B){var L=$[B.name];if(L){_=L.path,j=A.path;var N=x&&x.reload||!1,U=N&&(N===!0?_[0].self:n.get(N,M));x&&N&&N!==!0&&delete x.reload;var z={toState:L,toParams:h||{},fromState:A,fromParams:C||{},options:x,reloadStateTree:U};if(c.push(z),s=V,U){z.toParams.$$uirouterextrasreload=Math.random();var G=U.$$state().params,H=U.$$state().ownParams;if(f.hasParamSet){var Q=new d.Param("$$uirouterextrasreload");G.$$uirouterextrasreload=H.$$uirouterextrasreload=Q,V.restoreFunctions.push(function(){delete G.$$uirouterextrasreload,delete H.$$uirouterextrasreload})}else G.push("$$uirouterextrasreload"),H.push("$$uirouterextrasreload"),V.restoreFunctions.push(function(){G.length=G.length-1,H.length=H.length-1})}O=o.processTransition(z),T&&m(r,z,O);var W=L.path.slice(0,O.keep),X=A.path.slice(0,O.keep);e.forEach(u.locals,function(e,t){-1!=t.indexOf("@")&&delete u.locals[t]});var Y=function(e){return function(t,n){-1!==n.indexOf("@")&&(e[n]=t)}};b(O.inactives,function(e){b(e.locals,Y(u.locals))}),b(O.reactivatingStates,function(e){b(e.locals,Y(l))}),V.addRestoreFunction(function(){b(l,function(e,t){delete l[t]})}),e.forEach(O.enter,function(e,t){var n,a=L.path[t];"reactivate"===e?(n=E(a),W.push(n),X.push(n),D.push(P(a)),q=a):"reload"===e?(W.push(F(a)),q=a):"enter"===e&&W.push(w(a))}),e.forEach(O.exit,function(e,t){var n=A.path[t];"inactivate"===e?(X.push(k(n)),J.push(n)):"exit"===e&&(X.push(R(n)),J.push(n))}),D.length&&e.forEach(D,function(e){W.push(e)});var Z=O.orphans;X=X.concat(S(Z,function(e){return R(e)})),J=J.concat(Z),A.path=X,L.path=W;var ee=function(e){return(e.surrogateType?e.surrogateType+":":"")+e.self.name};T&&r.debug("SurrogateFromPath: ",S(X,ee)),T&&r.debug("SurrogateToPath: ",S(W,ee))}}var te=y.apply(n,arguments);return te.then(function(e){return V(),T&&g(r,$[e.name],n),e.status="active",e},function(e){return V(),T&&"transition prevented"!==e.message&&"transition aborted"!==e.message&&"transition superseded"!==e.message&&(r.debug("transition failed",e),r.debug(e.stack)),p.reject(e)})},n}])}])}(angular); \ No newline at end of file diff --git a/release/modular/ct-ui-router-extras.transition.js b/release/modular/ct-ui-router-extras.transition.js index e393d54..edad8be 100644 --- a/release/modular/ct-ui-router-extras.transition.js +++ b/release/modular/ct-ui-router-extras.transition.js @@ -1,7 +1,7 @@ /** * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise * Module: transition - * @version 0.1.2 + * @version 0.1.3 * @link http://christopherthielen.github.io/ui-router-extras/ * @license MIT License, http://www.opensource.org/licenses/MIT */ diff --git a/release/modular/ct-ui-router-extras.transition.min.js b/release/modular/ct-ui-router-extras.transition.min.js index 4fe3ebc..38610dc 100644 --- a/release/modular/ct-ui-router-extras.transition.min.js +++ b/release/modular/ct-ui-router-extras.transition.min.js @@ -1,2 +1,2 @@ -/** UI-Router Extras v.0.1.2 Module: transition http://christopherthielen.github.io/ui-router-extras/ - MIT License */ +/** UI-Router Extras v.0.1.3 Module: transition http://christopherthielen.github.io/ui-router-extras/ - MIT License */ !function(t,n){"use strict";t.module("ct.ui.router.extras.transition",["ct.ui.router.extras.core"]).config(["$provide",function(n){n.decorator("$state",["$delegate","$rootScope","$q","$injector",function(n,r,e,o){function i(n){var r=o.invoke,e=o.instantiate;return o.invoke=function(e,o,i){return r(e,o,t.extend({$transition$:n},i))},o.instantiate=function(r,o){return e(r,t.extend({$transition$:n},o))},function(){o.invoke=r,o.instantiate=e}}function a(){p.pop()(),$.pop(),f--}function u(t,n){return function(e){return a(),r.$broadcast("$transitionSuccess",n),t.resolve(e),e}}function c(t,n){return function(o){return a(),r.$broadcast("$transitionError",n,o),t.reject(o),e.reject(o)}}var s=n.transitionTo,f=-1,$=[],p=[];return n.transitionTo=function(t,r,o){var i=e.defer(),a=$[++f]={promise:i.promise};p[f]=function(){};var d=s.apply(n,arguments);return d.then(u(i,a),c(i,a))},r.$on("$stateChangeStart",function(n,e,o,a,u){if(!(f>=$.length)){var c=f,s=t.extend($[c],{to:{state:e,params:o},from:{state:a,params:u}}),d=i(s);p[c]=d,r.$broadcast("$transitionStart",s)}}),n}])}])}(angular); \ No newline at end of file