forked from gesquive/bootstrap-add-clear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-add-clear.min.js
5 lines (5 loc) · 2.09 KB
/
bootstrap-add-clear.min.js
1
2
3
4
5
/*!
* bootstrap-add-clear v1.0.4 (http://github.com/gesquive/bootstrap-add-clear)
* Licensed under MIT (http://github.com/gesquive/bootstrap-add-clear/blob/master/LICENSE)
*/
(function(e,c,a,g){var d="addClear",f={closeSymbol:"",symbolClass:"glyphicon glyphicon-remove-circle",color:"#CCC",top:0,right:0,returnFocus:true,showOnLoad:false,onClear:null,hideOnBlur:false,clearOnEscape:true,wrapperClass:"",zindex:100};function b(i,h){this.element=i;this.options=e.extend({},f,h);this._defaults=f;this._name=d;this.init()}b.prototype={init:function(){var j=e(this.element),i=this,h=this.options;j.wrap("<div class='add-clear-span has-feedback "+h.wrapperClass+"'></div>");j.after(e("<span class='add-clear-x form-control-feedback "+h.symbolClass+"' style='display: none;'>"+h.closeSymbol+"</span>"));j.next().css({color:h.color,cursor:"pointer","text-decoration":"none",display:"none",overflow:"hidden",position:"absolute","pointer-events":"auto",right:h.right,top:h.top,zindex:h.zindex},this);if(j.val().length>=1&&h.showOnLoad===true){j.siblings(".add-clear-x").show()}j.on("focus.addclear",function(){if(e(this).val().length>=1){e(this).siblings(".add-clear-x").show()}});j.on("blur.addclear",function(){var k=this;if(h.hideOnBlur){setTimeout(function(){e(k).siblings(".add-clear-x").hide()},50)}});j.on("keyup.addclear",function(k){if(h.clearOnEscape===true&&k.keyCode==27){e(this).val("").focus();if(h.onClear){h.onClear(e(this).siblings("input"))}}if(e(this).val().length>=1){e(this).siblings(".add-clear-x").show()}else{e(this).siblings(".add-clear-x").hide()}});j.on("input.addclear change.addclear paste.addclear",function(){if(e(this).val().length>=1){e(this).siblings(".add-clear-x").show()}else{e(this).siblings(".add-clear-x").hide()}});j.siblings(".add-clear-x").on("click.addclear",function(k){e(this).siblings(i.element).val("");e(this).hide();if(h.returnFocus===true){e(this).siblings(i.element).focus()}if(h.onClear){h.onClear(e(this).siblings("input"))}k.preventDefault()})}};e.fn[d]=function(h){return this.each(function(){if(!e.data(this,"plugin_"+d)){e.data(this,"plugin_"+d,new b(this,h))}})}})(jQuery,window,document);