Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created September 2, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/6dd958772ee559fe0b2e55d36d39a60f to your computer and use it in GitHub Desktop.
Save gdyrrahitis/6dd958772ee559fe0b2e55d36d39a60f to your computer and use it in GitHub Desktop.
/** @hidden */
function clickHook(el: IAugmentedJQuery, $state: StateService, $timeout: ITimeoutService, type: TypeInfo, getDef: () => Def) {
return function (e: JQueryMouseEventObject) {
var button = e.which || e.button, target = getDef();
if (!(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || el.attr('target'))) {
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
var transition = $timeout(function () {
$state.go(target.uiState, target.uiStateParams, target.uiStateOpts);
});
e.preventDefault();
// if the state has no URL, ignore one preventDefault from the <a> directive.
var ignorePreventDefaultCount = type.isAnchor && !target.href ? 1 : 0;
e.preventDefault = function () {
if (ignorePreventDefaultCount-- <= 0) $timeout.cancel(transition);
};
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment