Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Forked from nobuf/gist:3419910
Last active December 27, 2016 02:58
Show Gist options
  • Save thomseddon/4703810 to your computer and use it in GitHub Desktop.
Save thomseddon/4703810 to your computer and use it in GitHub Desktop.
Supporting placeholder on IE9 with AngularJS (without jQuery) > Removed jQuery dependency > Slight optimisation in retrieving placeholder text
angular.module('test', [])
.directive('placeholder', function($timeout){
var i = document.createElement('input');
if ('placeholder' in i) {
return {}
}
return {
link: function(scope, elm, attrs){
if (attrs.type === 'password') {
return;
}
$timeout(function(){
elm.val(attrs.placeholder);
elm.bind('focus', function(){
if (elm.val() == attrs.placeholder) {
elm.val('');
}
}).bind('blur', function(){
if (elm.val() == '') {
elm.val(attrs.placeholder);
}
});
});
}
}
});
@lutsifer
Copy link

lutsifer commented Apr 9, 2016

Great, thanks:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment