Created
October 2, 2014 15:06
-
-
Save kennethlynne/5a01fbfdcce766c8af75 to your computer and use it in GitHub Desktop.
A decorator to override uiSref to trigger state change on touchstart instead of click (to remove 300ms delay on touch screens)
This file contains hidden or 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