forked from nr007/floatlabels.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
floatlabels.min.js
1 lines (1 loc) · 2.53 KB
/
floatlabels.min.js
1
!function(t,e,a,l){function i(e,a){this.$element=t(e),this.settings=t.extend({},n,a),this.init()}var o="floatlabel",n={slideInput:!0,labelStartTop:"0px",labelEndTop:"0px",transitionDuration:.05,transitionEasing:"ease-in-out",labelClass:"",focusColor:"rgba(0, 0, 0, 0.35)",blurColor:"rgba(0, 0, 0, 0.35)"};i.prototype={init:function(){var t=this,a=this.settings,l=a.transitionDuration,i=a.transitionEasing,o=this.$element,n={"-webkit-transition":"all "+l+"s "+i,"-moz-transition":"all "+l+"s "+i,"-o-transition":"all "+l+"s "+i,"-ms-transition":"all "+l+"s "+i,transition:"all "+l+"s "+i},s=o.attr("id");s||(s=Math.floor(100*Math.random())+1,o.attr("id",s));var r=o.attr("placeholder"),c=o.data("label"),b=o.data("class");b||(b=""),c&&""!==c||(c=r),c&&(o.wrap('<div class="floatlabel-wrapper" style="position:relative"></div>'),o.before('<label for="'+s+'" class="label-floatlabel '+a.labelClass+" "+b+'">'+c+"</label>"),this.$label=o.prev("label"),this.$label.css({position:"absolute",top:a.labelStartTop,left:"12px",display:"none","-moz-opacity":"0","-khtml-opacity":"0","-webkit-opacity":"0",opacity:"0","font-size":"8.5px","font-weight":"bold","z-index":"9",color:t.settings.blurColor}),o.on("keyup blur change",function(e){t.checkValue(e)}),o.on("blur",function(){o.prev("label").css({color:t.settings.blurColor})}),o.on("focus",function(){o.prev("label").css({color:t.settings.focusColor})}),e.setTimeout(function(){t.$label.css(n),t.$element.css(n)},100),this.checkValue())},checkValue:function(t){if(t){var e=t.keyCode||t.which;if(9===e)return}var a=this.$element;a.val()&&a.val().toString()?(a.data("flout","1"),this.showLabel()):(a.data("flout","0"),this.hideLabel())},showLabel:function(){var t=this;t.$label.css({display:"block"}),e.setTimeout(function(){t.$label.css({top:t.settings.labelEndTop,"-moz-opacity":"1","-khtml-opacity":"1","-webkit-opacity":"1",opacity:"1"}),t.$element.addClass("active-floatlabel"),t.$element.parent().parent().find(".select2-selection__rendered").addClass("active-floatlabel")},50)},hideLabel:function(){var t=this;t.$label.css({top:t.settings.labelStartTop,"-moz-opacity":"0","-khtml-opacity":"0","-webkit-opacity":"0",opacity:"0"}),t.$element.removeClass("active-floatlabel"),t.$element.parent().parent().find(".select2-selection__rendered").removeClass("active-floatlabel"),e.setTimeout(function(){"0"===t.$element.data("flout")&&t.$label.css({display:"none"})},1e3*t.settings.transitionDuration)}},t.fn[o]=function(e){return this.each(function(){t.data(this,"plugin_"+o)||t.data(this,"plugin_"+o,new i(this,e))})}}(jQuery,window,document);