-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaceholder-ie.min.js
1 lines (1 loc) · 1.77 KB
/
placeholder-ie.min.js
1
if(!directive){var directive=angular.module("directive",[])}directive.directive("placeholder",function(){return{restrict:"A",require:"?ngModel",link:function(m,i,h,a){try{var k="<style>.placeholder-style{color: gray;};</style>";if(document.getElementsByClassName("placeholder-style").length===0){angular.element(document).find("head").append(k)}var b=function(o,c){var p=window.navigator.userAgent.toLowerCase(),e;if(p.indexOf("msie")!==-1){var q=p.match(/msie\s([0-9]*)/);e=(arguments.length===0)?q[1]:(arguments.length===1)?(parseInt(q[1])===o):(q[1]>=o&&q[1]<=c)?q[1]:false}return e};if(b(8,9)){if(!a.$modelValue&&a.$modelValue!==false&&a.$modelValue!==0){i.val(h.placeholder);i.addClass("placeholder-style")}try{a.$setViewValue()}catch(d){}if(h.type==="password"){i.removeClass("placeholder-style");var f=new Date().getTime();var n=h.style||"";var j=h.class||"";i.after('<input id="'+f+'" type="text" value="'+h.placeholder+'" autocomplete="off" style="'+n+'" class="'+j+' placeholder-style" />');var g=i.next();g.css("display","inline-block");i.css("display","none");g.on("focus",function(){i.css("display","inline-block");g.css("display","none");i.on("focus",function(){})})}var l=false;i.on("focus",function(){l=true;if(h.type==="password"){if(!a.$modelValue){i.val("")}}else{i.removeClass("placeholder-style");if(i.val()===h.placeholder&&(!a.$modelValue||a.$modelValue===h.placeholder)){i.val("")}}});i.on("blur",function(){l=false;if(h.type==="password"){if(i.val()===""){g.css("display","inline-block");i.css("display","none")}}else{if(!i.val()&&!a.$modelValue){i.val(h.placeholder);i.addClass("placeholder-style")}}});m.$watch(function(){return a.$modelValue},function(c){if(c){i.removeClass("placeholder-style")}else{if(l===false){i.val(h.placeholder);i.addClass("placeholder-style")}}})}}catch(d){}}}});