This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathfloatlabels.min.js
1 lines (1 loc) · 2.85 KB
/
floatlabels.min.js
1
!function(t,a,e,l){function s(a,e){this.$element=t(a),this.settings=t.extend({},o,e),this.init()}var i="floatlabel",o={slideInput:!0,labelStartTop:"0px",labelEndTop:"0px",paddingOffset:"12px",transitionDuration:.1,transitionEasing:"ease-in-out",labelClass:"",typeMatches:/text|password|email|number|search|url|tel/,focusColor:"#8F6593",blurColor:"#838780"};s.prototype={init:function(){var t=this,a=this.settings,e=a.transitionDuration,l=a.transitionEasing,s=this.$element,i={"-webkit-transition":"all "+e+"s "+l,"-moz-transition":"all "+e+"s "+l,"-o-transition":"all "+e+"s "+l,"-ms-transition":"all "+e+"s "+l,transition:"all "+e+"s "+l};if(("INPUT"==s.prop("tagName").toUpperCase()||"TEXTAREA"==s.prop("tagName").toUpperCase())&&("INPUT"!==s.prop("tagName").toUpperCase()||a.typeMatches.test(s.attr("type")))){var o=s.attr("id");o||(o=Math.floor(100*Math.random())+1,s.attr("id",o));var n=s.attr("placeholder"),p=s.data("label"),r=s.data("class");r||(r=""),n&&""!==n||(n="You forgot to add placeholder attribute!"),p&&""!==p||(p=n),this.inputPaddingTop=parseFloat(s.css("padding-top"))+parseFloat(a.paddingOffset),s.wrap('<div class="floatlabel-wrapper" style="position:relative"></div>'),s.before('<label for="'+o+'" class="label-floatlabel '+a.labelClass+" "+r+'">'+p+"</label>"),this.$label=s.prev("label"),this.$label.css({position:"absolute",top:a.labelStartTop,left:"8px",display:"none","-moz-opacity":"0","-khtml-opacity":"0","-webkit-opacity":"0",opacity:"0","font-size":"11px","font-weight":"bold",color:t.settings.blurColor}),a.slideInput||s.css({"padding-top":this.inputPaddingTop}),s.on("keyup blur change",function(a){t.checkValue(a)}),s.on("blur",function(){s.prev("label").css({color:t.settings.blurColor})}),s.on("focus",function(){s.prev("label").css({color:t.settings.focusColor})}),t.$label.css(i),t.$element.css(i),this.checkValue()}},checkValue:function(t){if(t){var a=t.keyCode||t.which;if(9===a)return}var e=this.$element,l=e.data("flout");""!==e.val()&&e.data("flout","1"),""===e.val()&&e.data("flout","0"),"1"===e.data("flout")&&"1"!==l&&this.showLabel(),"0"===e.data("flout")&&"0"!==l&&this.hideLabel()},showLabel:function(){var t=this;t.$label.css({top:t.settings.labelEndTop,"-moz-opacity":"1","-khtml-opacity":"1","-webkit-opacity":"1",opacity:"1"}),t.settings.slideInput&&t.$element.css({"padding-top":t.inputPaddingTop}),t.$element.addClass("active-floatlabel"),t.$label.css({display:"block"})},hideLabel:function(){var t=this;t.$label.css({top:t.settings.labelStartTop,"-moz-opacity":"0","-khtml-opacity":"0","-webkit-opacity":"0",opacity:"0"}),t.settings.slideInput&&t.$element.css({"padding-top":parseFloat(t.inputPaddingTop)-parseFloat(this.settings.paddingOffset)}),t.$element.removeClass("active-floatlabel"),t.$label.css({display:"none"})}},t.fn[i]=function(a){return this.each(function(){t.data(this,"plugin_"+i)||t.data(this,"plugin_"+i,new s(this,a))})}}(jQuery,window,document);