summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui-router/src
diff options
context:
space:
mode:
authorHendrik Leppelsack <hendrik@leppelsack.de>2015-10-26 11:29:01 +0100
committerHendrik Leppelsack <hendrik@leppelsack.de>2015-10-26 11:29:01 +0100
commit14804ae7b7d7a2d006b42189ad303241cde2550b (patch)
tree41740c2f9a49d9491f34a1db30261e9cb52608e1 /js/vendor/angular-ui-router/src
Initial commit
Diffstat (limited to 'js/vendor/angular-ui-router/src')
-rw-r--r--js/vendor/angular-ui-router/src/common.js292
-rw-r--r--js/vendor/angular-ui-router/src/resolve.js252
-rw-r--r--js/vendor/angular-ui-router/src/state.js1465
-rw-r--r--js/vendor/angular-ui-router/src/stateDirectives.js285
-rw-r--r--js/vendor/angular-ui-router/src/stateFilters.js39
-rw-r--r--js/vendor/angular-ui-router/src/templateFactory.js110
-rw-r--r--js/vendor/angular-ui-router/src/urlMatcherFactory.js1050
-rw-r--r--js/vendor/angular-ui-router/src/urlRouter.js427
-rw-r--r--js/vendor/angular-ui-router/src/view.js71
-rw-r--r--js/vendor/angular-ui-router/src/viewDirective.js303
-rw-r--r--js/vendor/angular-ui-router/src/viewScroll.js52
11 files changed, 4346 insertions, 0 deletions
diff --git a/js/vendor/angular-ui-router/src/common.js b/js/vendor/angular-ui-router/src/common.js
new file mode 100644
index 00000000..a85ff9e7
--- /dev/null
+++ b/js/vendor/angular-ui-router/src/common.js
@@ -0,0 +1,292 @@
+/*jshint globalstrict:true*/
+/*global angular:false*/
+'use strict';
+
+var isDefined = angular.isDefined,
+ isFunction = angular.isFunction,
+ isString = angular.isString,
+ isObject = angular.isObject,
+ isArray = angular.isArray,
+ forEach = angular.forEach,
+ extend = angular.extend,
+ copy = angular.copy;
+
+function inherit(parent, extra) {
+ return extend(new (extend(function() {}, { prototype: parent }))(), extra);
+}
+
+function merge(dst) {
+ forEach(arguments, function(obj) {
+ if (obj !== dst) {
+ forEach(obj, function(value, key) {
+ if (!dst.hasOwnProperty(key)) dst[key] = value;
+ });
+ }
+ });
+ return dst;
+}
+
+/**
+ * Finds the common ancestor path between two states.
+ *
+ * @param {Object} first The first state.
+ * @param {Object} second The second state.
+ * @return {Array} Returns an array of state names in descending order, not including the root.
+ */
+function ancestors(first, second) {
+ var path = [];
+
+ for (var n in first.path) {
+ if (first.path[n] !== second.path[n]) break;
+ path.push(first.path[n]);
+ }
+ return path;
+}
+
+/**
+ * IE8-safe wrapper for `Object.keys()`.
+ *
+ * @param {Object} object A JavaScript object.
+ * @return {Array} Returns the keys of the object as an array.
+ */
+function objectKeys(object) {
+ if (Object.keys) {
+ return Object.keys(object);
+ }
+ var result = [];
+
+ forEach(object, function(val, key) {
+ result.push(key);
+ });
+ return result;
+}
+
+/**
+ * IE8-safe wrapper for `Array.prototype.indexOf()`.
+ *
+ * @param {Array} array A JavaScript array.
+ * @param {*} value A value to search the array for.
+ * @return {Number} Returns the array index value of `value`, or `-1` if not present.
+ */
+function indexOf(array, value) {
+ if (Array.prototype.indexOf) {
+ return array.indexOf(value, Number(arguments[2]) || 0);
+ }
+ var len = array.length >>> 0, from = Number(arguments[2]) || 0;
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+
+ if (from < 0) from += len;
+
+ for (; from < len; from++) {
+ if (from in array && array[from] === value) return from;
+ }
+ return -1;
+}
+
+/**
+ * Merges a set of parameters with all parameters inherited between the common parents of the
+ * current state and a given destination state.
+ *
+ * @param {Object} currentParams The value of the current state parameters ($stateParams).
+ * @param {Object} newParams The set of parameters which will be composited with inherited params.
+ * @param {Object} $current Internal definition of object representing the current state.
+ * @param {Object} $to Internal definition of object representing state to transition to.
+ */
+function inheritParams(currentParams, newParams, $current, $to) {
+ var parents = ancestors($current, $to), parentParams, inherited = {}, inheritList = [];
+
+ for (var i in parents) {
+ if (!parents[i].params) continue;
+ parentParams = objectKeys(parents[i].params);
+ if (!parentParams.length) continue;
+
+ for (var j in parentParams) {
+ if (indexOf(inheritList, parentParams[j]) >= 0) continue;
+ inheritList.push(parentParams[j]);
+ inherited[parentParams[j]] = currentParams[parentParams[j]];
+ }
+ }
+ return extend({}, inherited, newParams);
+}
+
+/**
+ * Performs a non-strict comparison of the subset of two objects, defined by a list of keys.
+ *
+ * @param {Object} a The first object.
+ * @param {Object} b The second object.
+ * @param {Array} keys The list of keys within each object to compare. If the list is empty or not specified,
+ * it defaults to the list of keys in `a`.
+ * @return {Boolean} Returns `true` if the keys match, otherwise `false`.
+ */
+function equalForKeys(a, b, keys) {
+ if (!keys) {
+ keys = [];
+ for (var n in a) keys.push(n); // Used instead of Object.keys() for IE8 compatibility
+ }
+
+ for (var i=0; i<keys.length; i++) {
+ var k = keys[i];
+ if (a[k] != b[k]) return false; // Not '===', values aren't necessarily normalized
+ }
+ return true;
+}
+
+/**
+ * Returns the subset of an object, based on a list of keys.
+ *
+ * @param {Array} keys
+ * @param {Object} values
+ * @return {Boolean} Returns a subset of `values`.
+ */
+function filterByKeys(keys, values) {
+ var filtered = {};
+
+ forEach(keys, function (name) {
+ filtered[name] = values[name];
+ });
+ return filtered;
+}
+
+// like _.indexBy
+// when you know that your index values will be unique, or you want last-one-in to win
+function indexBy(array, propName) {
+ var result = {};
+ forEach(array, function(item) {
+ result[item[propName]] = item;
+ });
+ return result;
+}
+
+// extracted from underscore.js
+// Return a copy of the object only containing the whitelisted properties.
+function pick(obj) {
+ var copy = {};
+ var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
+ forEach(keys, function(key) {
+ if (key in obj) copy[key] = obj[key];
+ });
+ return copy;
+}
+
+// extracted from underscore.js
+// Return a copy of the object omitting the blacklisted properties.
+function omit(obj) {
+ var copy = {};
+ var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
+ for (var key in obj) {
+ if (indexOf(keys, key) == -1) copy[key] = obj[key];
+ }
+ return copy;
+}
+
+function pluck(collection, key) {
+ var result = isArray(collection) ? [] : {};
+
+ forEach(collection, function(val, i) {
+ result[i] = isFunction(key) ? key(val) : val[key];
+ });
+ return result;
+}
+
+function filter(collection, callback) {
+ var array = isArray(collection);
+ var result = array ? [] : {};
+ forEach(collection, function(val, i) {
+ if (callback(val, i)) {
+ result[array ? result.length : i] = val;
+ }
+ });
+ return result;
+}
+
+function map(collection, callback) {
+ var result = isArray(collection) ? [] : {};
+
+ forEach(collection, function(val, i) {
+ result[i] = callback(val, i);
+ });
+ return result;
+}
+
+/**
+ * @ngdoc overview
+ * @name ui.router.util
+ *
+ * @description
+ * # ui.router.util sub-module
+ *
+ * This module is a dependency of other sub-modules. Do not include this module as a dependency
+ * in your angular app (use {@link ui.router} module instead).
+ *
+ */
+angular.module('ui.router.util', ['ng']);
+
+/**
+ * @ngdoc overview
+ * @name ui.router.router
+ *
+ * @requires ui.router.util
+ *
+ * @description
+ * # ui.router.router sub-module
+ *
+ * This module is a dependency of other sub-modules. Do not include this module as a dependency
+ * in your angular app (use {@link ui.router} module instead).
+ */
+angular.module('ui.router.router', ['ui.router.util']);
+
+/**
+ * @ngdoc overview
+ * @name ui.router.state
+ *
+ * @requires ui.router.router
+ * @requires ui.router.util
+ *
+ * @description
+ * # ui.router.state sub-module
+ *
+ * This module is a dependency of the main ui.router module. Do not include this module as a dependency
+ * in your angular app (use {@link ui.router} module instead).
+ *
+ */
+angular.module('ui.router.state', ['ui.router.router', 'ui.router.util']);
+
+/**
+ * @ngdoc overview
+ * @name ui.router
+ *
+ * @requires ui.router.state
+ *
+ * @description
+ * # ui.router
+ *
+ * ## The main module for ui.router
+ * There are several sub-modules included with the ui.router module, however only this module is needed
+ * as a dependency within your angular app. The other modules are for organization purposes.
+ *
+ * The modules are:
+ * * ui.router - the main "umbrella" module
+ * * ui.router.router -
+ *
+ * *You'll need to include **only** this module as the dependency within your angular app.*
+ *
+ * <pre>
+ * <!doctype html>
+ * <html ng-app="myApp">
+ * <head>
+ * <script src="js/angular.js"></script>
+ * <!-- Include the ui-router script -->
+ * <script src="js/angular-ui-router.min.js"></script>
+ * <script>
+ * // ...and add 'ui.router' as a dependency
+ * var myApp = angular.module('myApp', ['ui.router']);
+ * </script>
+ * </head>
+ * <body>
+ * </body>
+ * </html>
+ * </pre>
+ */
+angular.module('ui.router', ['ui.router.state']);
+
+angular.module('ui.router.compat', ['ui.router']);
diff --git a/js/vendor/angular-ui-router/src/resolve.js b/js/vendor/angular-ui-router/src/resolve.js
new file mode 100644
index 00000000..f1c17900
--- /dev/null
+++ b/js/vendor/angular-ui-router/src/resolve.js
@@ -0,0 +1,252 @@
+/**
+ * @ngdoc object
+ * @name ui.router.util.$resolve
+ *
+ * @requires $q
+ * @requires $injector
+ *
+ * @description
+ * Manages resolution of (acyclic) graphs of promises.
+ */
+$Resolve.$inject = ['$q', '$injector'];
+function $Resolve( $q, $injector) {
+
+ var VISIT_IN_PROGRESS = 1,
+ VISIT_DONE = 2,
+ NOTHING = {},
+ NO_DEPENDENCIES = [],
+ NO_LOCALS = NOTHING,
+ NO_PARENT = extend($q.when(NOTHING), { $$promises: NOTHING, $$values: NOTHING });
+
+
+ /**
+ * @ngdoc function
+ * @name ui.router.util.$resolve#study
+ * @methodOf ui.router.util.$resolve
+ *
+ * @description
+ * Studies a set of invocables that are likely to be used multiple times.
+ * <pre>
+ * $resolve.study(invocables)(locals, parent, self)
+ * </pre>
+ * is equivalent to
+ * <pre>
+ * $resolve.resolve(invocables, locals, parent, self)
+ * </pre>
+ * but the former is more efficient (in fact `resolve` just calls `study`
+ * internally).
+ *
+ * @param {object} invocables Invocable objects
+ * @return {function} a function to pass in locals, parent and self
+ */
+ this.study = function (invocables) {
+ if (!isObject(invocables)) throw new Error("'invocables' must be an object");
+ var invocableKeys = objectKeys(invocables || {});
+
+ // Perform a topological sort of invocables to build an ordered plan
+ var plan = [], cycle = [], visited = {};
+ function visit(value, key) {
+ if (visited[key] === VISIT_DONE) return;
+
+ cycle.push(key);
+ if (visited[key] === VISIT_IN_PROGRESS) {
+ cycle.splice(0, indexOf(cycle, key));
+ throw new Error("Cyclic dependency: " + cycle.join(" -> "));
+ }
+ visited[key] = VISIT_IN_PROGRESS;
+
+ if (isString(value)) {
+ plan.push(key, [ function() { return $injector.get(value); }], NO_DEPENDENCIES);
+ } else {
+ var params = $injector.annotate(value);
+ forEach(params, function (param) {
+ if (param !== key && invocables.hasOwnProperty(param)) visit(invocables[param], param);
+ });
+ plan.push(key, value, params);
+ }
+
+ cycle.pop();
+ visited[key] = VISIT_DONE;
+ }
+ forEach(invocables, visit);
+ invocables = cycle = visited = null; // plan is all that's required
+
+ function isResolve(value) {
+ return isObject(value) && value.then && value.$$promises;
+ }
+
+ return function (locals, parent, self) {
+ if (isResolve(locals) && self === undefined) {
+ self = parent; parent = locals; locals = null;
+ }
+ if (!locals) locals = NO_LOCALS;
+ else if (!isObject(locals)) {
+ throw new Error("'locals' must be an object");
+ }
+ if (!parent) parent = NO_PARENT;
+ else if (!isResolve(parent)) {
+ throw new Error("'parent' must be a promise returned by $resolve.resolve()");
+ }
+
+ // To complete the overall resolution, we have to wait for the parent
+ // promise and for the promise for each invokable in our plan.
+ var resolution = $q.defer(),
+ result = resolution.promise,
+ promises = result.$$promises = {},
+ values = extend({}, locals),
+ wait = 1 + plan.length/3,
+ merged = false;
+
+ function done() {
+ // Merge parent values we haven't got yet and publish our own $$values
+ if (!--wait) {
+ if (!merged) merge(values, parent.$$values);
+ result.$$values = values;
+ result.$$promises = result.$$promises || true; // keep for isResolve()
+ delete result.$$inheritedValues;
+ resolution.resolve(values);
+ }
+ }
+
+ function fail(reason) {
+ result.$$failure = reason;
+ resolution.reject(reason);
+ }
+
+ // Short-circuit if parent has already failed
+ if (isDefined(parent.$$failure)) {
+ fail(parent.$$failure);
+ return result;
+ }
+
+ if (parent.$$inheritedValues) {
+ merge(values, omit(parent.$$inheritedValues, invocableKeys));
+ }
+
+ // Merge parent values if the parent has already resolved, or merge
+ // parent promises and wait if the parent resolve is still in progress.
+ extend(promises, parent.$$promises);
+ if (parent.$$values) {
+ merged = merge(values, omit(parent.$$values, invocableKeys));
+ result.$$inheritedValues = omit(parent.$$values, invocableKeys);
+ done();
+ } else {
+ if (parent.$$inheritedValues) {
+ result.$$inheritedValues = omit(parent.$$inheritedValues, invocableKeys);
+ }
+ parent.then(done, fail);
+ }
+
+ // Process each invocable in the plan, but ignore any where a local of the same name exists.
+ for (var i=0, ii=plan.length; i<ii; i+=3) {
+ if (locals.hasOwnProperty(plan[i])) done();
+ else invoke(plan[i], plan[i+1], plan[i+2]);
+ }
+
+ function invoke(key, invocable, params) {
+ // Create a deferred for this invocation. Failures will propagate to the resolution as well.
+ var invocation = $q.defer(), waitParams = 0;
+ function onfailure(reason) {
+ invocation.reject(reason);
+ fail(reason);
+ }
+ // Wait for any parameter that we have a promise for (either from parent or from this
+ // resolve; in that case study() will have made sure it's ordered before us in the plan).
+ forEach(params, function (dep) {
+ if (promises.hasOwnProperty(dep) && !locals.hasOwnProperty(dep)) {
+ waitParams++;
+ promises[dep].then(function (result) {
+ values[dep] = result;
+ if (!(--waitParams)) proceed();
+ }, onfailure);
+ }
+ });
+ if (!waitParams) proceed();
+ function proceed() {
+ if (isDefined(result.$$failure)) return;
+ try {
+ invocation.resolve($injector.invoke(invocable, self, values));
+ invocation.promise.then(function (result) {
+ values[key] = result;
+ done();
+ }, onfailure);
+ } catch (e) {
+ onfailure(e);
+ }
+ }
+ // Publish promise synchronously; invocations further down in the plan may depend on it.
+ promises[key] = invocation.promise;
+ }
+
+ return result;
+ };
+ };
+
+ /**
+ * @ngdoc function
+ * @name ui.router.util.$resolve#resolve
+ * @methodOf ui.router.util.$resolve
+ *
+ * @description
+ * Resolves a set of invocables. An invocable is a function to be invoked via
+ * `$injector.invoke()`, and can have an arbitrary number of dependencies.
+ * An invocable can either return a value directly,
+ * or a `$q` promise. If a promise is returned it will be resolved and the
+ * resulting value will be used instead. Dependencies of invocables are resolved
+ * (in this order of precedence)
+ *
+ * - from the specified `locals`
+ * - from another invocable that is part of this `$resolve` call
+ * - from an invocable that is inherited from a `parent` call to `$resolve`
+ * (or recursively
+ * - from any ancestor `$resolve` of that parent).
+ *
+ * The return value of `$resolve` is a promise for an object that contains
+ * (in this order of precedence)
+ *
+ * - any `locals` (if specified)
+ * - the resolved return values of all injectables
+ * - any values inherited from a `parent` call to `$resolve` (if specified)
+ *
+ * The promise will resolve after the `parent` promise (if any) and all promises
+ * returned by injectables have been resolved. If any invocable
+ * (or `$injector.invoke`) throws an exception, or if a promise returned by an
+ * invocable is rejected, the `$resolve` promise is immediately rejected with the
+ * same error. A rejection of a `parent` promise (if specified) will likewise be
+ * propagated immediately. Once the `$resolve` promise has been rejected, no
+ * further invocables will be called.
+ *
+ * Cyclic dependencies between invocables are not permitted and will caues `$resolve`
+ * to throw an error. As a special case, an injectable can depend on a parameter
+ * with the same name as the injectable, which will be fulfilled from the `parent`
+ * injectable of the same name. This allows inherited values to be decorated.
+ * Note that in this case any other injectable in the same `$resolve` with the same
+ * dependency would see the decorated value, not the inherited value.
+ *
+ * Note that missing dependencies -- unlike cyclic dependencies -- will cause an
+ * (asynchronous) rejection of the `$resolve` promise rather than a (synchronous)
+ * exception.
+ *
+ * Invocables are invoked eagerly as soon as all dependencies are available.
+ * This is true even for dependencies inherited from a `parent` call to `$resolve`.
+ *
+ * As a special case, an invocable can be a string, in which case it is taken to
+ * be a service name to be passed to `$injector.get()`. This is supported primarily
+ * for backwards-compatibility with the `resolve` property of `$routeProvider`
+ * routes.
+ *
+ * @param {object} invocables functions to invoke or
+ * `$injector` services to fetch.
+ * @param {object} locals values to make available to the injectables
+ * @param {object} parent a promise returned by another call to `$resolve`.
+ * @param {object} self the `this` for the invoked methods
+ * @return {object} Promise for an object that contains the resolved return value
+ * of all invocables, as well as any inherited and local values.
+ */
+ this.resolve = function (invocables, locals, parent, self) {
+ return this.study(invocables)(locals, parent, self);
+ };
+}
+
+angular.module('ui.router.util').service('$resolve', $Resolve);
+
diff --git a/js/vendor/angular-ui-router/src/state.js b/js/vendor/angular-ui-router/src/state.js
new file mode 100644
index 00000000..56ee5a05
--- /dev/null
+++ b/js/vendor/angular-ui-router/src/state.js
@@ -0,0 +1,1465 @@
+/**
+ * @ngdoc object
+ * @name ui.router.state.$stateProvider
+ *
+ * @requires ui.router.router.$urlRouterProvider
+ * @requires ui.router.util.$urlMatcherFactoryProvider
+ *
+ * @description
+ * The new `$stateProvider` works similar to Angular's v1 router, but it focuses purely
+ * on state.
+ *
+ * A state corresponds to a "place" in the application in terms of the overall UI and
+ * navigation. A state describes (via the controller / template / view properties) what
+ * the UI looks like and does at that place.
+ *
+ * States often have things in common, and the primary way of factoring out these
+ * commonalities in this model is via the state hierarchy, i.e. parent/child states aka
+ * nested states.
+ *
+ * The `$stateProvider` provides interfaces to declare these states for your app.
+ */
+$StateProvider.$inject = ['$urlRouterProvider', '$urlMatcherFactoryProvider'];
+function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
+
+ var root, states = {}, $state, queue = {}, abstractKey = 'abstract';
+
+ // Builds state properties from definition passed to registerState()
+ var stateBuilder = {
+
+ // Derive parent state from a hierarchical name only if 'parent' is not explicitly defined.
+ // state.children = [];
+ // if (parent) parent.children.push(state);
+ parent: function(state) {
+ if (isDefined(state.parent) && state.parent) return findState(state.parent);
+ // regex matches any valid composite state name
+ // would match "contact.list" but not "contacts"
+ var compositeName = /^(.+)\.[^.]+$/.exec(state.name);
+ return compositeName ? findState(compositeName[1]) : root;
+ },
+
+ // inherit 'data' from parent and override by own values (if any)
+ data: function(state) {
+ if (state.parent && state.parent.data) {
+ state.data = state.self.data = extend({}, state.parent.data, state.data);
+ }
+ return state.data;
+ },
+
+ // Build a URLMatcher if necessary, either via a relative or absolute URL
+ url: function(state) {
+ var url = state.url, config = { params: state.params || {} };
+
+ if (isString(url)) {
+ if (url.charAt(0) == '^') return $urlMatcherFactory.compile(url.substring(1), config);
+ return (state.parent.navigable || root).url.concat(url, config);
+ }
+
+ if (!url || $urlMatcherFactory.isMatcher(url)) return url;
+ throw new Error("Invalid url '" + url + "' in state '" + state + "'");
+ },
+
+ // Keep track of the closest ancestor state that has a URL (i.e. is navigable)
+ navigable: function(state) {
+ return state.url ? state : (state.parent ? state.parent.navigable : null);
+ },
+
+ // Own parameters for this state. state.url.params is already built at this point. Create and add non-url params
+ ownParams: function(state) {
+ var params = state.url && state.url.params || new $$UMFP.ParamSet();
+ forEach(state.params || {}, function(config, id) {
+ if (!params[id]) params[id] = new $$UMFP.Param(id, null, config, "config");
+ });
+ return params;
+ },
+
+ // Derive parameters for this state and ensure they're a super-set of parent's parameters
+ params: function(state) {
+ return state.parent && state.parent.params ? extend(state.parent.params.$$new(), state.ownParams) : new $$UMFP.ParamSet();
+ },
+
+ // If there is no explicit multi-view configuration, make one up so we don't have
+ // to handle both cases in the view directive later. Note that having an explicit
+ // 'views' property will mean the default unnamed view properties are ignored. This
+ // is also a good time to resolve view names to absolute names, so everything is a
+ // straight lookup at link time.
+ views: function(state) {
+ var views = {};
+
+ forEach(isDefined(state.views) ? state.views : { '': state }, function (view, name) {
+ if (name.indexOf('@') < 0) name += '@' + state.parent.name;
+ views[name] = view;
+ });
+ return views;
+ },
+
+ // Keep a full path from the root down to this state as this is needed for state activation.
+ path: function(state) {
+ return state.parent ? state.parent.path.concat(state) : []; // exclude root from path
+ },
+
+ // Speed up $state.contains() as it's used a lot
+ includes: function(state) {
+ var includes = state.parent ? extend({}, state.parent.includes) : {};
+ includes[state.name] = true;
+ return includes;
+ },
+
+ $delegates: {}
+ };
+
+ function isRelative(stateName) {
+ return stateName.indexOf(".") === 0 || stateName.indexOf("^") === 0;
+ }
+
+ function findState(stateOrName, base) {
+ if (!stateOrName) return undefined;
+
+ var isStr = isString(stateOrName),
+ name = isStr ? stateOrName : stateOrName.name,
+ path = isRelative(name);
+
+ if (path) {
+ if (!base) throw new Error("No reference point given for path '" + name + "'");
+ base = findState(base);
+
+ var rel = name.split("."), i = 0, pathLength = rel.length, current = base;
+
+ for (; i < pathLength; i++) {
+ if (rel[i] === "" && i === 0) {
+ current = base;
+ continue;
+ }
+ if (rel[i] === "^") {
+ if (!current.parent) throw new Error("Path '" + name + "' not valid for state '" + base.name + "'");
+ current = current.parent;
+ continue;
+ }
+ break;
+ }
+ rel = rel.slice(i).join(".");
+ name = current.name + (current.name && rel ? "." : "") + rel;
+ }
+ var state = states[name];
+
+ if (state && (isStr || (!isStr && (state === stateOrName || state.self === stateOrName)))) {
+ return state;
+ }
+ return undefined;
+ }
+
+ function queueState(parentName, state) {
+ if (!queue[parentName]) {
+ queue[parentName] = [];
+ }
+ queue[parentName].push(state);
+ }
+
+ function flushQueuedChildren(parentName) {
+ var queued = queue[parentName] || [];
+ while(queued.length) {
+ registerState(queued.shift());
+ }
+ }
+
+ function registerState(state) {
+ // Wrap a new object around the state so we can store our private details easily.
+ state = inherit(state, {
+ self: state,
+ resolve: state.resolve || {},
+ toString: function() { return this.name; }
+ });
+
+ var name = state.name;
+ if (!isString(name) || name.indexOf('@') >= 0) throw new Error("State must have a valid name");
+ if (states.hasOwnProperty(name)) throw new Error("State '" + name + "'' is already defined");
+
+ // Get parent name
+ var parentName = (name.indexOf('.') !== -1) ? name.substring(0, name.lastIndexOf('.'))
+ : (isString(state.parent)) ? state.parent
+ : (isObject(state.parent) && isString(state.parent.name)) ? state.parent.name
+ : '';
+
+ // If parent is not registered yet, add state to queue and register later
+ if (parentName && !states[parentName]) {
+ return queueState(parentName, state.self);
+ }
+
+ for (var key in stateBuilder) {
+ if (isFunction(stateBuilder[key])) state[key] = stateBuilder[key](state, stateBuilder.$delegates[key]);
+ }
+ states[name] = state;
+
+ // Register the state in the global state list and with $urlRouter if necessary.
+ if (!state[abstractKey] && state.url) {
+ $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
+ if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
+ $state.transitionTo(state, $match, { inherit: true, location: false });
+ }
+ }]);
+ }
+
+ // Register any queued children
+ flushQueuedChildren(name);
+
+ return state;
+ }
+
+ // Checks text to see if it looks like a glob.
+ function isGlob (text) {
+ return text.indexOf('*') > -1;
+ }
+
+ // Returns true if glob matches current $state name.
+ function doesStateMatchGlob (glob) {
+ var globSegments = glob.split('.'),
+ segments = $state.$current.name.split('.');
+
+ //match single stars
+ for (var i = 0, l = globSegments.length; i < l; i++) {
+ if (globSegments[i] === '*') {
+ segments[i] = '*';
+ }
+ }
+
+ //match greedy starts
+ if (globSegments[0] === '**') {
+ segments = segments.slice(indexOf(segments, globSegments[1]));
+ segments.unshift('**');
+ }
+ //match greedy ends
+ if (globSegments[globSegments.length - 1] === '**') {
+