-
Notifications
You must be signed in to change notification settings - Fork 1
/
placeholder.min.js
20 lines (20 loc) · 2.67 KB
/
placeholder.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
* Brings HTML5 "placeholder" attribute into all older browser - v0.0.3 beta
*
* Support: IE6+, FF3+, Opera 9+, Safari, Chrome
*
* Copyright 2011-2012, Dmitriy Pakhtinov ( spb.piksel@gmail.com )
*
* http://spb-piksel.ru/
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Update: 05-09-2012
*/
(function(d){var f=d.document,i=eval("/*@cc_on (@_jscript_version+'').replace(/\\d\\./, '');@*/"),g=function(a){var b=",:input-,-o-,:-o-input-,-moz-,:-webkit-input-,-ms-,:-ms-input-".split(",");f.documentElement.firstChild.appendChild(a);for(var e=0;e<b.length;e++)try{a.sheet.insertRule(":"+b[e]+"placeholder{}",0)}catch(d){}b=a.sheet?0<a.sheet.cssRules.length:0;a.parentNode.removeChild(a);return b}(f.createElement("style"));d.inputPlaceholder=function(){};if(!g||!d.external&&!d.opera){var h=["input",
"textarea"],c=d.addEventListener?["","addEventListener"]:["on","attachEvent"],j=function(a){var b=a&&a.target||d.event.srcElement;if(a=b.getAttribute("data-placeholder-type"))b.a&&(b.parentNode.removeChild(b.a),b.runtimeStyle.display=b.b,b.a=null),b.removeAttribute("data-placeholder-type"),b.className=(" "+b.className+" ").replace(/\s+input-placeholder\s+/," ").replace(/^[\s]+|[\s](?=\s)|[\s]+$/g,""),b.value="",(!i||8<i)&&"INPUT"===b.nodeName&&b.type!==a&&b.setAttribute("type",a)},k=function(a){a=
a&&a.target||d.event.srcElement;if(""===a.value&&(a.setAttribute("data-placeholder-type","INPUT"===a.nodeName?a.type:"true"),a.className+=" input-placeholder",a.value=a.getAttribute("data-placeholder"),"INPUT"===a.nodeName&&"text"!==a.type))try{a.setAttribute("type","text")}catch(b){var e=f.createElement("input");e.a=a;a.a=e;a.b=a.currentStyle.display;a.runtimeStyle.display="none";e.className=a.className+" input-placeholder";e.type="text";e.value=a.getAttribute("data-placeholder");e.onfocus=function(){var a=
d.event.srcElement,b=a.nextSibling;b===a.a&&(b.runtimeStyle.display=b.b,b.focus(),b.a=null);a.parentNode.removeChild(a)};a.parentNode.insertBefore(e,a)}};d.inputPlaceholder=function(a,b){if(b=a.getAttribute("placeholder"))a.setAttribute("data-placeholder",b),a.removeAttribute("placeholder"),k({target:a}),a[c[1]](c[0]+"focus",j,!1),a[c[1]](c[0]+"blur",k,!1),a.form&&!a.form.c&&(a.form.c=!0,a.form[c[1]](c[0]+"submit",function(a){for(var a=a&&a.target||d.event.srcElement,b=0,c;b<h.length;b++){c=a.getElementsByTagName(h[b]);
for(var f=0,g;g=c[f++];)j({target:g})}},!1))};g=function(){for(var a=0,b;a<h.length;a++){b=f.getElementsByTagName(h[a]);for(var e=0,c;c=b[e++];)d.inputPlaceholder(c)}};f.addEventListener&&f.addEventListener("DOMContentLoaded",g,!1);d[c[1]](c[0]+"load",g,!1)}})(window);