Created
January 12, 2016 18:57
-
-
Save infomofo/4e9828fbd886eeb226a8 to your computer and use it in GitHub Desktop.
select on click directive
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
module.directive('selectOnClick', ['$window', function ($window) { | |
return { | |
restrict: 'A', | |
link: function (scope, element, attrs) { | |
element.on('touchend', function (event) { | |
event.stopPropagation(); | |
event.preventDefault(); | |
// Required for mobile Safari | |
this.setSelectionRange(0, this.value.length); | |
}); | |
element.on('click', function () { | |
if (!$window.getSelection().toString()) { | |
// Required for mobile Safari | |
this.setSelectionRange(0, 9999); | |
} | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment