Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bdecarne/81b8cfdd2a29b2650401 to your computer and use it in GitHub Desktop.
Save bdecarne/81b8cfdd2a29b2650401 to your computer and use it in GitHub Desktop.
'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