-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.placeholder.1.1.1.min.js
10 lines (10 loc) · 1.59 KB
/
jquery.placeholder.1.1.1.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* jQuery Placeholder 1.1.1
*
* Copyright (c) 2010 Michael J. Ryan (http://tracker1.info/)
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function(e){var g="PLACEHOLDER-INPUT";var f="PLACEHOLDER-LABEL";var a=false;var d={labelClass:"placeholder"};var i=document.createElement("input");if("placeholder" in i){e.fn.placeholder=e.fn.unplaceholder=function(){};delete i;return}delete i;e.fn.placeholder=function(j){c();var k=e.extend(d,j);this.each(function(){var n=Math.random().toString(32).replace(/\./,""),l=e(this),m=e('<label style="position:absolute;display:none;top:0;left:0;"></label>');if(!l.attr("placeholder")||l.data(g)===g){return}if(!l.attr("id")){l.attr("id")="input_"+n}m.attr("id",l.attr("id")+"_placeholder").data(g,"#"+l.attr("id")).attr("for",l.attr("id")).addClass(k.labelClass).addClass(k.labelClass+"-for-"+this.tagName.toLowerCase()).addClass(f).text(l.attr("placeholder"));l.data(f,"#"+m.attr("id")).data(g,g).addClass(g).after(m);b.call(this);h.call(this)})};e.fn.unplaceholder=function(){this.each(function(){var j=e(this),k=e(j.data(f));if(j.data(g)!==g){return}k.remove();j.removeData(g).removeData(f).removeClass(g)})};function c(){if(a){return}e("."+g).live("click",b).live("focusin",b).live("focusout",h);bound=true;a=true}function b(){var j=e(this),k=e(j.data(f));k.css("display","none")}function h(){var j=this;setTimeout(function(){var k=e(j);e(k.data(f)).css("top",k.position().top+"px").css("left",k.position().left+"px").css("display",!!k.val()?"none":"block")},200)}}(jQuery));