This repository has been archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathjquery.superLabels.min.js
10 lines (10 loc) · 3.77 KB
/
jquery.superLabels.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
* Version: 2.0.4
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
;(function(t){"use strict";var e,a,i,s,n,l,o,r,d={autoCharLimit:!1,baseZindex:0,duration:500,easingIn:t.easing&&t.easing.def?"easeInOutCubic":!1,easingOut:t.easing&&t.easing.def?"easeInOutCubic":!1,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:!1,opacity:.5,slide:!0,wrapSelector:!1},u=["text","search","url","tel","email","password","number"],h=["input","textarea","select"];t.fn.superLabels=function(l){var o,r=[];return 0===this.length?!1:(o=t.extend({},d),t(this).data("slDefaults",t.extend(o,l||{})).addClass("sl-defaults"),1===this.length&&/form/i.test(this[0].tagName)?r=t(h.join(","),this):this.length>1?this.each(function(){/form/i.test(this.tagName)?t.merge(r,t(h.join(","),this)):r.push(this)}):r=this,t(r).each(function(){var l,o,r=t(this),d=r.attr("placeholder");return-1===("input"===r[0].tagName.toLowerCase()&&t.inArray(r.attr("type"),u))&&-1!==t.inArray(r[0].tagName.toLowerCase(),h)?!0:(l=e(this),d&&(0===l.length?(o='<label for="'+(r.attr("id")||r.attr("name"))+'">'+d+"</label>",o+="</label>",o=t(o),l=o,r.before(l)):l.attr("title",d),r.removeAttr("placeholder")),0===l.length?!0:(a(r,l),this.tagName.match(/select/i)||(r.focus(i),r.blur(s),r.change(s),r.bind("input",n),r.bind("propertychange",s),r.keyup(n),l.click(function(){r.focus()})),void 0))}))},e=function(e){var a,i=t(e).closest(".sl-defaults").data("slDefaults"),s=t(e).siblings("label");return 0===s.length&&(i.wrapSelector?s=t(e).parents(i.wrapSelector).find("label"):(a=e.id||e.name,s=t('[for="'+a+'"]'))),s},a=function(e,a){var i,s=e.data("slCharLimit"),n=t(e).closest(".sl-defaults").data("slDefaults"),d=0;e[0].tagName.match(/select/i)?(i=0===e.find("[selected]").length?" selected":"",e.prepend('<option value="" disabled'+i+' rel="label">'+a.html()+"</option>"),a.css("display","none")):(("auto"===s||n.autoCharLimit&&isNaN(s))&&r(e,a),l(e)?d=1:o(e)&&(d=n._opacity),e.css({zIndex:n.baseZindex+1}).addClass("sl_field"),a.css({left:l(e)?n.labelLeft:t(e).width()-a.width(),opacity:d,position:"absolute",top:n.labelTop,zIndex:n.baseZindex+2}).addClass("sl_label"))},i=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,n={opacity:0};if(l(this)){if(a=e(this),i.noAnimate)return a.hide(),!1;i.slide?(n.left=t(this).width()-a.width(),n.opacity=i.opacity):s=i.fadeDuration,a.stop(!0,!1).animate(n,s,i.easingOut)}},s=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,o={opacity:1};if(l(this)){if(a=e(this),i.noAnimate)return a.show(),!1;i.slide?o.left=i.labelLeft:s=i.fadeDuration,a.stop(!0,!1).animate(o,s,i.easingOut)}else n.apply(this)},n=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=0;return i.noAnimate?!1:(a=e(this),l(this)&&a.css("opacity")>0||!l(this)&&0===a.css("opacity")?!1:((l(this)&&0!==a.css("opacity")||o(this))&&(s=i.opacity),a.stop(!0,!1).animate({opacity:s},i.fadeDuration,i.easingOut),void 0))},l=function(e){return""===t(e).val()},o=function(e){var a=t(e).data("slCharLimit");return a&&"number"==typeof a?(e=e.length?e[0]:e,a&&e.value&&a>=e.value.length):!1},r=function(e,a){var i,s,n="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",l=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],o=t("<div>"+n+"</div>");t.each(l,function(t,a){o.css(a,e.css(a))}),o.css({position:"absolute",visibility:"hidden"}),e.parent().append(o),s=Math.round(o.width()/n.length),o.remove(),i=e.width()-a.width(),e.data("slCharLimit",Math.floor(i/s))}})(jQuery);