-
-
Save gdyrrahitis/b90ec9626c08a1a174475e7f528d6485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let uiSref: ng1_directive; | |
uiSref = ['$uiRouter', '$timeout', | |
function $StateRefDirective($uiRouter: UIRouter, $timeout: ITimeoutService) { | |
let $state = $uiRouter.stateService; | |
return { | |
restrict: 'A', | |
require: ['?^uiSrefActive', '?^uiSrefActiveEq'], | |
link: function (scope: IScope, element: IAugmentedJQuery, attrs: any, uiSrefActive: any) { | |
let type = getTypeInfo(element); | |
let active = uiSrefActive[1] || uiSrefActive[0]; | |
let unlinkInfoFn: Function = null; | |
let hookFn; | |
let rawDef = {} as Def; | |
let getDef = () => processedDef($state, element, rawDef); | |
let ref = parseStateRef(attrs.uiSref); | |
rawDef.uiState = ref.state; | |
rawDef.uiStateOpts = attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {}; | |
function update() { | |
let 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', <any> $uiRouter.stateRegistry.onStatesChanged(update)); | |
scope.$on('$destroy', <any> $uiRouter.transitionService.onSuccess({}, update)); | |
if (!type.clickable) return; | |
hookFn = clickHook(element, $state, $timeout, type, getDef); | |
bindEvents(element, scope, hookFn, rawDef.uiStateOpts); | |
} | |
}; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment