-
-
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
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
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); | |
} | |
}); | |
}); | |
} | |
} | |
}); |
Thank you :) Works well in IE8 & IE9!
Great, thanks:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I appreciate this. Thanks!