Forked from kennethlynne/ui-sref-fastclick-decorator.js
Last active
August 29, 2015 14:09
-
-
Save bdecarne/81b8cfdd2a29b2650401 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
'use strict'; | |
// A decorator to override uiSref to trigger state change on touchstart if the element does not have disable-fastclick attribute | |
// It also logs the time between state changes | |
angular.module('app') | |
.config(function ($provide) { | |
$provide.decorator('uiSrefDirective', function ($delegate) { | |
var originalUiSref, originalUiSrefLink; | |
originalUiSref = $delegate[0]; | |
originalUiSrefLink = originalUiSref.link; | |
$delegate[0].compile = function () { | |
return function (scope, element, attrs, uiSref) { | |
var originalBind = element.bind, enableFastClick = !angular.isDefined(attrs.disableFastclick); | |
element.bind = function (event, callback) { | |
originalBind.call(element, event === 'click' && enableFastClick ? 'touchstart mousedown' : event, function () { | |
callback.apply(element, arguments); | |
}); | |
}; | |
originalUiSrefLink.call($delegate, scope, element, attrs, uiSref); | |
}; | |
}; | |
return $delegate; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment