forked from GNUsocial/gnu-social
10 lines
2.4 KiB
JavaScript
10 lines
2.4 KiB
JavaScript
|
/**
|
||
|
* In-Field Label jQuery Plugin v0.2.1
|
||
|
* http://fuelyourcoding.com/scripts/infield.html
|
||
|
* http://github.com/streetpc/jquery-infieldlabels
|
||
|
*
|
||
|
* Copyright (c) 2009 Doug Neiner, Adrien Lavoillotte
|
||
|
* Dual licensed under the MIT and GPL licenses, see:
|
||
|
* http://docs.jquery.com/License
|
||
|
*/
|
||
|
(function(f){var d=0,a=1,b=2,g=/^(?:text|password|search|number|tel|url|email|date(?:time(?:-local)?)?|time|month|week)?$/,c=function(i,h){return(i<<3)|h},e={};e[c(a,d)]=function(h){h.fadeTo(1)};e[c(b,d)]=function(h){h.$label.css({opacity:1}).show();h.emptied(true)};e[c(d,a)]=function(h){h.fadeTo(h.options.fadeOpacity)};e[c(b,a)]=function(h){h.$label.css({opacity:h.options.fadeOpacity}).show();h.emptied(true)};e[c(d,b)]=function(h){h.$label.hide();h.emptied(false)};e[c(a,b)]=e[c(d,b)];f.InFieldLabels=function(i,k,h){var j=this;j.$label=f(i);j.label=i;j.$field=f(k);j.field=k;j.$label.data("InFieldLabels",j);j.state=d;j.init=function(){j.options=f.extend({},f.InFieldLabels.defaultOptions,h);if(j.options.labelClass){j.$label.addClass(j.options.labelClass)}if(j.options.disableAutocomplete){j.$field.attr("autocomplete","off")}j.$field.bind("blur focus change keyup.infield cut",j.updateState).bind("paste",function(l){j.setState(b)});j.updateState()};j.emptied=function(l){if(!j.options.emptyWatch){if(l){j.$field.bind("keyup.infield",j.updateState)}else{j.$field.unbind("keyup.infield",j.updateState)}}};j.fadeTo=function(l){if(!j.options.fadeDuration){j.$label.css({opacity:l})}else{j.$label.stop().animate({opacity:l},j.options.fadeDuration)}};j.updateState=function(o,m){var n=b;if(j.field.value===""){var l=o&&o.type;if(l==="focus"||l==="keyup"){l=true}else{if(l==="blur"||l==="change"){l=false}else{l=j.$field.is(":focus")}}n=l?a:d}j.setState(n,m)};j.setState=function(m,l){if(m===j.state){return}var n=e[c(j.state,m)];if(typeof n==="function"){n(j);j.state=m}else{l||j.updateState(null,true)}};j.init()};f.InFieldLabels.defaultOptions={emptyWatch:true,disableAutocomplete:true,fadeOpacity:0.5,fadeDuration:300,labelClass:"in-field"};f.fn.inFieldLabels=function(h){return this.each(function(){if(this.tagName!=="LABEL"){return}var k=this.getAttribute("for")||this.htmlFor,j,i=true;if(!k){return}j=document.getElementById(k);if(!j){return}if(j.tagName==="INPUT"){i=g.test(j.type.toLowerCase())}else{if(j.tagName!=="TEXTAREA"){i=false}}i=i&&!j.getAttribute("placeholder");if(!i){return}(new f.InFieldLabels(this,j,h))})}}(jQuery));
|