* ```
*
* Note:
* The parameter values expression is `$watch`ed for updates.
*
* ### Transition Options
* You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `ui-sref-opts` attribute.
* Options are restricted to `location`, `inherit`, and `reload`.
*
* #### Example:
* ```html
* Home
* ```
*
* ### Other DOM Events
*
* You can also customize which DOM events to respond to (instead of `click`) by
* providing an `events` array in the `ui-sref-opts` attribute.
*
* #### Example:
* ```html
*
* ```
*
* ### Highlighting the active link
* This directive can be used in conjunction with [[uiSrefActive]] to highlight the active link.
*
* ### Examples
* If you have the following template:
*
* ```html
* Home
* About
* Next page
*
*
*
* Home
* ```
*
* ### Notes
*
* - You can use `ui-sref` to change **only the parameter values** by omitting the state name and parentheses.
* #### Example:
* Sets the `lang` parameter to `en` and remains on the same state.
*
* ```html
* English
* ```
*
* - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example.
*
* - Unlike the parameter values expression, the state name is not `$watch`ed (for performance reasons).
* If you need to dynamically update the state being linked to, use the fully dynamic [[uiState]] directive.
*/
var uiSrefDirective;
uiSrefDirective = [
'$uiRouter',
'$timeout',
function $StateRefDirective($uiRouter, $timeout) {
var $state = $uiRouter.stateService;
return {
restrict: 'A',
require: ['?^uiSrefActive', '?^uiSrefActiveEq'],
link: function (scope, element, attrs, uiSrefActive) {
var type = getTypeInfo(element);
var active = uiSrefActive[1] || uiSrefActive[0];
var unlinkInfoFn = null;
var rawDef = {};
var getDef = function () { return processedDef($state, element, rawDef); };
var ref = parseStateRef(attrs.uiSref);
rawDef.uiState = ref.state;
rawDef.uiStateOpts = attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {};
function update() {
var def = getDef();
if (unlinkInfoFn)
unlinkInfoFn();
if (active)
unlinkInfoFn = active.$$addStateInfo(def.uiState, def.uiStateParams);
if (def.href != null)
attrs.$set(type.attr, def.href);
}
if (ref.paramExpr) {
scope.$watch(ref.paramExpr, function (val) {
rawDef.uiStateParams = extend({}, val);
update();
}, true);
rawDef.uiStateParams = extend({}, scope.$eval(ref.paramExpr));
}
update();
scope.$on('$destroy', $uiRouter.stateRegistry.onStatesChanged(update));
scope.$on('$destroy', $uiRouter.transitionService.onSuccess({}, update));
if (!type.clickable)
return;
var hookFn = clickHook(element, $state, $timeout, type, getDef);
bindEvents(element, scope, hookFn, rawDef.uiStateOpts);
},
};
},
];
/**
* `ui-state`: A fully dynamic directive for linking to a state
*
* A directive which links to a state (and optionally, parameters).
* When clicked, this directive activates the linked state with the supplied parameter values.
*
* **This directive is very similar to [[uiSref]], but it `$observe`s and `$watch`es/evaluates all its inputs.**
*
* A directive which links to a state (and optionally, parameters).
* When clicked, this directive activates the linked state with the supplied parameter values.
*
* ### Linked State
* The attribute value of `ui-state` is an expression which is `$watch`ed and evaluated as the state to link to.
* **This is in contrast with `ui-sref`, which takes a state name as a string literal.**
*
* #### Example:
* Create a list of links.
* ```html
*
* ```
*
* ### Relative Links
* If the expression evaluates to a relative path, it is processed like [[uiSref]].
* You just need to be aware that the path is relative to the state that *created* the link.
* This allows a state to create relative `ui-state` which always targets the same destination.
*
* ### hrefs
* If the linked state has a URL, the directive will automatically generate and
* update the `href` attribute (using the [[StateService.href]] method).
*
* ### Parameter Values
* In addition to the state name expression, a `ui-state` can include parameter values which are applied when activating the state.
* Param values should be provided using the `ui-state-params` attribute.
* The `ui-state-params` attribute value is `$watch`ed and evaluated as an expression.
*
* #### Example:
* This example renders a list of links with param values.
* The state's `userId` parameter value comes from each user's `user.id` property.
* ```html
*
* ```
*
* ### Transition Options
* You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `ui-state-opts` attribute.
* Options are restricted to `location`, `inherit`, and `reload`.
* The value of the `ui-state-opts` is `$watch`ed and evaluated as an expression.
*
* #### Example:
* ```html
* Home
* ```
*
* ### Other DOM Events
*
* You can also customize which DOM events to respond to (instead of `click`) by
* providing an `events` array in the `ui-state-opts` attribute.
*
* #### Example:
* ```html
*
* ```
*
* ### Highlighting the active link
* This directive can be used in conjunction with [[uiSrefActive]] to highlight the active link.
*
* ### Notes
*
* - You can use `ui-params` to change **only the parameter values** by omitting the state name and supplying only `ui-state-params`.
* However, it might be simpler to use [[uiSref]] parameter-only links.
*
* #### Example:
* Sets the `lang` parameter to `en` and remains on the same state.
*
* ```html
* English
* ```
*
* - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example.
* ```
*/
var uiStateDirective;
uiStateDirective = [
'$uiRouter',
'$timeout',
function $StateRefDynamicDirective($uiRouter, $timeout) {
var $state = $uiRouter.stateService;
return {
restrict: 'A',
require: ['?^uiSrefActive', '?^uiSrefActiveEq'],
link: function (scope, element, attrs, uiSrefActive) {
var type = getTypeInfo(element);
var active = uiSrefActive[1] || uiSrefActive[0];
var unlinkInfoFn = null;
var hookFn;
var rawDef = {};
var getDef = function () { return processedDef($state, element, rawDef); };
var inputAttrs = ['uiState', 'uiStateParams', 'uiStateOpts'];
var watchDeregFns = inputAttrs.reduce(function (acc, attr) { return ((acc[attr] = noop), acc); }, {});
function update() {
var def = getDef();
if (unlinkInfoFn)
unlinkInfoFn();
if (active)
unlinkInfoFn = active.$$addStateInfo(def.uiState, def.uiStateParams);
if (def.href != null)
attrs.$set(type.attr, def.href);
}
inputAttrs.forEach(function (field) {
rawDef[field] = attrs[field] ? scope.$eval(attrs[field]) : null;
attrs.$observe(field, function (expr) {
watchDeregFns[field]();
watchDeregFns[field] = scope.$watch(expr, function (newval) {
rawDef[field] = newval;
update();
}, true);
});
});
update();
scope.$on('$destroy', $uiRouter.stateRegistry.onStatesChanged(update));
scope.$on('$destroy', $uiRouter.transitionService.onSuccess({}, update));
if (!type.clickable)
return;
hookFn = clickHook(element, $state, $timeout, type, getDef);
bindEvents(element, scope, hookFn, rawDef.uiStateOpts);
},
};
},
];
/**
* `ui-sref-active` and `ui-sref-active-eq`: A directive that adds a CSS class when a `ui-sref` is active
*
* A directive working alongside [[uiSref]] and [[uiState]] to add classes to an element when the
* related directive's state is active (and remove them when it is inactive).
*
* The primary use-case is to highlight the active link in navigation menus,
* distinguishing it from the inactive menu items.
*
* ### Linking to a `ui-sref` or `ui-state`
* `ui-sref-active` can live on the same element as `ui-sref`/`ui-state`, or it can be on a parent element.
* If a `ui-sref-active` is a parent to more than one `ui-sref`/`ui-state`, it will apply the CSS class when **any of the links are active**.
*
* ### Matching
*
* The `ui-sref-active` directive applies the CSS class when the `ui-sref`/`ui-state`'s target state **or any child state is active**.
* This is a "fuzzy match" which uses [[StateService.includes]].
*
* The `ui-sref-active-eq` directive applies the CSS class when the `ui-sref`/`ui-state`'s target state is directly active (not when child states are active).
* This is an "exact match" which uses [[StateService.is]].
*
* ### Parameter values
* If the `ui-sref`/`ui-state` includes parameter values, the current parameter values must match the link's values for the link to be highlighted.
* This allows a list of links to the same state with different parameters to be rendered, and the correct one highlighted.
*
* #### Example:
* ```html
*
* ```
*
* When the app state is `app.user` (or any child state),
* and contains the state parameter "user" with value "bilbobaggins",
* the resulting HTML will appear as (note the 'active' class):
*
* ```html
*
* ```
*
* ### Glob mode
*
* It is possible to pass `ui-sref-active` an expression that evaluates to an object.
* The objects keys represent active class names and values represent the respective state names/globs.
* `ui-sref-active` will match if the current active state **includes** any of
* the specified state names/globs, even the abstract ones.
*
* #### Example:
* Given the following template, with "admin" being an abstract state:
* ```html
*
* ```
*
* Arrays are also supported as values in the `ngClass`-like interface.
* This allows multiple states to add `active` class.
*
* #### Example:
* Given the following template, with "admin.roles" being the current state, the class will be added too:
* ```html
*