Skip to content

Instantly share code, notes, and snippets.

@infomofo
Created January 12, 2016 18:57
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 infomofo/4e9828fbd886eeb226a8 to your computer and use it in GitHub Desktop.
Save infomofo/4e9828fbd886eeb226a8 to your computer and use it in GitHub Desktop.
select on click directive
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