mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-18 19:59:30 +03:00
38 lines
2.9 KiB
JavaScript
38 lines
2.9 KiB
JavaScript
/*!
|
|
Author: Stephen Korecky
|
|
Website: http://stephenkorecky.com
|
|
Plugin Website: http://github.com/skorecky/Add-Clear
|
|
Version: 2.0.6
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2015 Stephen Korecky
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
!function(n,t,i,e){function o(t,i){this.element=t,this.options=n.extend({},a,i),this._defaults=a,this._name=s,this.init()}var s="addClear",a={closeSymbol:"✖",color:"#CCC",top:1,right:4,returnFocus:!0,showOnLoad:!1,onClear:null,hideOnBlur:!1,tabbable:!0,paddingRight:"20px"}
|
|
o.prototype={init:function(){var t,e=n(this.element),o=this,s=this.options
|
|
e.wrap("<span style='position:relative;' class='add-clear-span'></span>")
|
|
var a=s.tabbable?"":" tabindex='-1'"
|
|
t=n("<a href='#clear' style='display: none;'"+a+">"+s.closeSymbol+"</a>"),e.after(t),e.next().css({color:s.color,"text-decoration":"none",display:"none","line-height":1,overflow:"hidden",position:"absolute",right:s.right,top:s.top},this),s.paddingRight&&e.css({"padding-right":s.paddingRight}),e.val().length>=1&&s.showOnLoad===!0&&t.css({display:"block"}),e.focus(function(){n(this).val().length>=1&&t.css({display:"block"})}),e.blur(function(n){s.hideOnBlur&&setTimeout(function(){var e=n.relatedTarget||n.explicitOriginalTarget||i.activeElement
|
|
e!==t[0]&&t.css({display:"none"})},0)})
|
|
var l=function(){t.css(n(this).val().length>=1?{display:"block"}:{display:"none"})},c=function(){e.off("keyup",l),e.off("cut",l),c=l,l.call(this)}
|
|
e.on("keyup",l),e.on("cut",function(){var n=this
|
|
setTimeout(function(){l.call(n)},0)}),e.on("input",function(){c.call(this)}),s.hideOnBlur&&t.blur(function(){t.css({display:"none"})}),t.click(function(t){var i=n(o.element)
|
|
i.val(""),n(this).css({display:"none"}),s.returnFocus===!0&&i.focus(),s.onClear&&s.onClear(i),t.preventDefault()})}},n.fn[s]=function(t){return this.each(function(){n.data(this,"plugin_"+s)||n.data(this,"plugin_"+s,new o(this,t))})}}(jQuery,window,document)
|