Created
June 10, 2014 15:04
-
-
Save simonjodet/8cbedc4929f08ecaa03e to your computer and use it in GitHub Desktop.
Angular directive to select the content of a textarea when it's focused
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'; | |
angular.module('myApp').directive( | |
'ngSelectOnFocus', | |
function() { | |
var factory = { | |
restrict: 'A', | |
link: function postLink(scope, element) { | |
$(element).focus(function(event) { | |
event.target.select(); | |
$(event.target).one('mouseup', function(e) { | |
e.preventDefault(); | |
}); | |
}); | |
} | |
}; | |
return factory; | |
} | |
); |
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
<textarea ng-select-on-focus></textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment