snappymail/vendors/inputosaurus/inputosaurus.min.js

3 lines
9.7 KiB
JavaScript
Raw Normal View History

2014-04-11 04:22:10 +08:00
/*! Inputosaurus Text v0.1.6 (c) 2013 Dan Kielp <dan@sproutsocial.com>; modified by RainLoop Team | MIT */
2015-03-21 06:22:06 +08:00
!function(e){var t={version:"0.1.6",fakeSpan:e('<span class="inputosaurus-fake-span"></span>'),eventprefix:"inputosaurus",options:{inputDelimiters:[",",";"],outputDelimiter:",",allowDuplicates:!1,allowDragAndDrop:!0,focusCallback:null,parseOnBlur:!1,wrapperElement:null,width:null,autoCompleteSource:"",activateFinalResult:!1,parseHook:null,elementHook:null,placeholder:null},_create:function(){var t=this,i={},n=t.options,s=n.placeholder||this.element.attr("placeholder")||null;this._chosenValues=[],i.ul=e('<ul class="inputosaurus-container"></ul>'),this.options.allowDragAndDrop&&i.ul.droppable({drop:function(e,n){n.draggable.addClass("inputosaurus-dropped"),i.input.val(n.draggable.data("inputosaurus-value")),n.draggable.__widget&&n.draggable.__widget._removeDraggedTag(n.draggable),t.parseInput()}}),i.input=e('<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />'),i.inputCont=e('<li class="inputosaurus-input inputosaurus-required"></li>'),i.origInputCont=e('<li class="inputosaurus-input-hidden inputosaurus-required"></li>'),i.lastEdit="",i.input.on("focus",function(){t._focusTrigger(!0)}).on("blur",function(){t._focusTrigger(!1)}),s&&(n.placeholder=s,i.input.attr("placeholder",n.placeholder),n.width&&i.input.css("min-width",n.width-50)),n.wrapperElement&&n.wrapperElement.append(i.ul),this.element.replaceWith(n.wrapperElement||i.ul),i.origInputCont.append(this.element).hide(),i.inputCont.append(i.input),i.ul.append(i.inputCont),i.ul.append(i.origInputCont),n.width&&i.ul.css("width",n.width),this.elements=i,t._attachEvents(),e.trim(this.element.val())&&(i.input.val(this.element.val()),this.parseInput()),this._instAutocomplete()},_focusTriggerTimer:0,_focusTrigger:function(e){var t=this;window.clearTimeout(this._focusTriggerTimer),this._focusTriggerTimer=window.setTimeout(function(){t.elements.ul[e?"addClass":"removeClass"]("inputosaurus-focused"),t.options.focusCallback&&t.options.focusCallback(e)},10)},_instAutocomplete:function(){if(this.options.autoCompleteSource){var t=this;this.elements.input.autocomplete({position:{of:this.elements.ul},source:this.options.autoCompleteSource,minLength:1,autoFocus:!0,select:function(e,i){e.preventDefault(),t.elements.input.val(i.item.value),t.parseInput()},open:function(){var i,n=e(this).data("ui-autocomplete").menu;n.element.width(t.elements.ul.outerWidth()-6),t.options.activateFinalResult&&(i=n.element.find("li"),1===i.size()&&n[n.activate?"activate":"focus"](e.Event("click"),i))},focus:function(){return!1}})}},_autoCompleteMenuPosition:function(){var e;this.options.autoCompleteSource&&(e=this.elements.input.data("ui-autocomplete"),e&&e.menu.element.position({of:this.elements.ul,my:"left top",at:"left bottom",collision:"none"}))},parseInput:function(t){var i,n=t&&t.data.widget||this,s=!1,u=[];i=n.elements.input.val(),i&&(s=n._containsDelimiter(i)),s!==!1?u=i.split(s):t&&(t.which!==e.ui.keyCode.ENTER||e(".ui-menu-item .ui-state-focus").size()||e("#ui-active-menuitem").size())?"blur"!==t.type||e("#ui-active-menuitem").size()||u.push(i):(u.push(i),t&&t.preventDefault()),e.isFunction(n.options.parseHook)&&(u=n.options.parseHook(u)),u.length&&(n._setChosen(u),n.elements.input.val(""),n._resizeInput()),n._resetPlaceholder()},_inputFocus:function(e){var t=e.data.widget||this;t.elements.input.value||t.options.autoCompleteSource.length&&t.elements.input.autocomplete("search","")},_inputKeypress:function(t){var i=t.data.widget||this;switch("keyup"===t.type&&i._trigger("keyup",t,i),t.which){case e.ui.keyCode.BACKSPACE:"keydown"===t.type&&i._inputBackspace(t);break;case e.ui.keyCode.LEFT:"keydown"===t.type&&i._inputBackspace(t);break;default:i.parseInput(t),i._resizeInput(t)}i.options.autoCompleteSource&&setTimeout(function(){i._autoCompleteMenuPosition.call(i)},200)},resizeInput:function(){this._resizeInput()},_resizeInput:function(e){var i=e&&e.data.widget||this;t.fakeSpan.text(i.elements.input.val());var n=25+t.fakeSpan.width();n=n>50?n:50,n=500>n?n:500,i.elements.input.width(n)},_resetPlaceholder:function(){var e=this.options.placeholder,t=this.elem