forked from maman/JVFloat.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjvfloat.min.js
4 lines (4 loc) · 867 Bytes
/
jvfloat.min.js
1
2
3
4
/*
* JVFloat.js
* modified on: 29/01/2014
*/(function($){"use strict";$.fn.jvFloat=function(){return this.filter('input:not([type=submit]), textarea').each(function(){var $el=$(this).wrap('<div class=jvFloat>');var forId=$el.attr('id');if(!forId)forId=createIdOnElement($el);var required=$el.attr('required')||'';var placeholder=$('<label class="placeHolder '+required+'" for="'+forId+'">'+$el.attr('placeholder')+'</label>').insertBefore($el);setState();$el.bind('keyup blur',setState);function setState(){placeholder.toggleClass('active',$el.val()!=='');}function generateUIDNotMoreThan1million(){do{var id=("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).substr(-4);}while(!!$('#'+id).length);return id;};function createIdOnElement($el){var id=generateUIDNotMoreThan1million();$el.prop('id',id);return id;};});};})(window.jQuery||window.Zepto||window.$);