mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-07 15:27:43 +08:00
2 lines
8.1 KiB
JavaScript
2 lines
8.1 KiB
JavaScript
|
/*! Inputosaurus Text v0.1.6 (c) 2013 Dan Kielp <dan@sproutsocial.com>; modified by RainLoop Team | MIT */
|
||
|
!function(a){var b={version:"0.1.6",eventprefix:"inputosaurus",options:{inputDelimiters:[",",";"],outputDelimiter:",",allowDuplicates:!1,parseOnBlur:!1,wrapperElement:null,width:null,autoCompleteSource:"",activateFinalResult:!1,parseHook:null,placeholder:null},_create:function(){var b=this,c={},d=b.options,e=d.placeholder||this.element.attr("placeholder")||null;this._chosenValues=[],c.ul=a('<ul class="inputosaurus-container"></ul>'),c.fakeSpan=a('<span class="inputosaurus-fake-span"></span>'),c.input=a('<input type="text" />'),c.inputCont=a('<li class="inputosaurus-input inputosaurus-required"></li>'),c.origInputCont=a('<li class="inputosaurus-input-hidden inputosaurus-required"></li>'),c.lastEdit="",e&&(d.placeholder=e,c.input.attr("placeholder",d.placeholder),d.width&&c.input.css("min-width",d.width-50)),d.wrapperElement&&d.wrapperElement.append(c.ul),this.element.replaceWith(d.wrapperElement||c.ul),c.origInputCont.append(this.element).hide(),c.inputCont.append(c.input),c.ul.append(c.inputCont),c.ul.append(c.origInputCont),c.ul.append(c.fakeSpan),d.width&&c.ul.css("width",d.width),this.elements=c,b._attachEvents(),a.trim(this.element.val())&&(c.input.val(this.element.val()),this.parseInput()),this._instAutocomplete()},_instAutocomplete:function(){if(this.options.autoCompleteSource){var b=this;this.elements.input.autocomplete({position:{of:this.elements.ul},source:this.options.autoCompleteSource,minLength:1,select:function(a,c){a.preventDefault(),b.elements.input.val(c.item.value),b.parseInput()},open:function(){var c,d=a(this).data("ui-autocomplete").menu;d.element.width(b.elements.ul.outerWidth()),b.options.activateFinalResult&&(c=d.element.find("li"),1===c.size()&&d[d.activate?"activate":"focus"](a.Event("click"),c))},focus:function(){return!1}})}},_autoCompleteMenuPosition:function(){var a;this.options.autoCompleteSource&&(a=this.elements.input.data("ui-autocomplete"),a&&a.menu.element.position({of:this.elements.ul,my:"left top",at:"left bottom",collision:"none"}))},parseInput:function(b){var c,d=b&&b.data.widget||this,e=!1,f=[];c=d.elements.input.val(),c&&(e=d._containsDelimiter(c)),e!==!1?f=c.split(e):b&&(b.which!==a.ui.keyCode.ENTER||a(".ui-menu-item .ui-state-focus").size()||a("#ui-active-menuitem").size())?"blur"!==b.type||a("#ui-active-menuitem").size()||f.push(c):(f.push(c),b&&b.preventDefault()),a.isFunction(d.options.parseHook)&&(f=d.options.parseHook(f)),f.length&&(d._setChosen(f),d.elements.input.val(""),d._resizeInput()),d._resetPlaceholder()},_inputFocus:function(a){var b=a.data.widget||this;b.elements.input.value||b.options.autoCompleteSource.length&&b.elements.input.autocomplete("search","")},_inputKeypress:function(b){var c=b.data.widget||this;switch("keyup"===b.type&&c._trigger("keyup",b,c),b.which){case a.ui.keyCode.BACKSPACE:"keydown"===b.type&&c._inputBackspace(b);break;case a.ui.keyCode.LEFT:"keydown"===b.type&&c._inputBackspace(b);break;default:c.parseInput(b),c._resizeInput(b)}c.options.autoCompleteSource&&setTimeout(function(){c._autoCompleteMenuPosition.call(c)},200)},_resizeInput:function(a){var b=50,c=400,d=a&&a.data.widget||this,e=0;d.elements.fakeSpan.text(d.elements.input.val()),e=20+d.elements.fakeSpan.width(),e=c>e?e:c,e=b>e?b:e,d.elements.input.width(e)},_resetPlaceholder:function(){var a=this.options.placeholder,b=this.elements.input,c=this.options.width||"inherit";a&&0===this.element.val().length?b.attr("placeholder",a).css("min-width",c-50):b.attr("placeholder","").css("min-width","inherit")},_inputBackspace:function(b){var c=b&&b.data.widget||this,d=c.elements.ul.find("li:not(.inputosaurus-required):last");b.stopPropagation(),(!a(b.currentTarget).val()||"selectionStart"in b.currentTarget&&0===b.currentTarget.selectionStart&&0===b.currentTarget.selectionEnd)&&d.size()&&(b.preventDefault(),d.find("a").focus())},_editTag:function(b){var c=b&&b.data.widget||this,d="",e=a(b.currentTarget).closest("li"),f=e.data("inputosaurus");if(!f)return!0;b.preventDefault();var g=null,h=!1;a.each(c._chosenValues,function(a,b){b.key===f?(d=b.value,h=!0):h&&!g&&(g=b)}),g&&(c.elements.lastEdit=g.valu
|