From 10a733877189876ed308c1fac833cb841455d599 Mon Sep 17 00:00:00 2001 From: Ben Olson Date: Sun, 6 Oct 2013 09:13:05 -0400 Subject: [PATCH] New Build --- build.sh | 0 jqueryui-multisearch.js | 64 ++++++++++++++++++++++++++----------- jqueryui-multisearch.min.js | 4 +-- 3 files changed, 48 insertions(+), 20 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/jqueryui-multisearch.js b/jqueryui-multisearch.js index 2606184..3054e38 100644 --- a/jqueryui-multisearch.js +++ b/jqueryui-multisearch.js @@ -275,7 +275,7 @@ if ( arguments.length === 0 ) { // Clear - this.$itemList.children().not( this.$input ).remove(); + this._getSelectedChildren().remove(); this.itemData = []; this.itemIndex = -1; } else if ( _.isObject( item ) ) { @@ -440,6 +440,12 @@ this._initAutoWidth(); this._initRemote(); + var self = this; + $( document ).on( 'click.multisearch', function( event ) { + + if ( self.element.has( event.target ).length === 0 ) + self._hidePicker(); + }); }, _initRemote: function() { @@ -467,17 +473,21 @@ this._remoteSearch = _.throttle( function() { - if ( self._xhr ) - self._xhr.abort(); + if ( self.localCache[self.search_text] ) { + cb( self.search_text, self.localCache[self.search_text] ); + } else { - self._xhr = - $.ajax({ - url: opt.source, - data: opt.ajaxOptions.searchTerm+'='+self.search_text, - dataType: opt.ajaxOptions.dataType, - method: opt.ajaxOptions.method - }).done( _.partial( cb, self.search_text ) ); + if ( self._xhr ) + self._xhr.abort(); + self._xhr = + $.ajax({ + url: opt.source, + data: opt.ajaxOptions.searchTerm+'='+self.search_text, + dataType: opt.ajaxOptions.dataType, + method: opt.ajaxOptions.method + }).done( _.partial( cb, self.search_text ) ); + } }, opt.searchThrottle, { leading: false } @@ -488,7 +498,11 @@ this._remoteSearch = _.throttle( function() { // Need to capture the text as of now.. - opt.source.call( self, self.search_text, _.partial( cb, self.search_text ) ); + if ( self.localCache[self.search_text] ) { + cb( self.search_text, self.localCache[self.search_text] ); + } else { + opt.source.call( self, self.search_text, _.partial( cb, self.search_text ) ); + } }, opt.searchThrottle, { leading: false } @@ -543,10 +557,16 @@ this.element.removeClass( 'osb-multisearch' ); + $( document ).off( 'click.multisearch' ); this.$input.off( 'keydown keyup' ); this.$picker.off( 'click mouseenter mouseleave' ); this.$itemList.off( 'click mouseenter mouseleave keydown' ); + this.$sizer.remove(); + this.$pickerList.html(''); + this._getSelectedChildren().remove(); + this.$picker.show(); + this._remoteSearch = null; this.localCache = null; @@ -652,7 +672,7 @@ this._addSelectedItem(); } else { - if ( !this.preventNotFound ) { + if ( !this.options.preventNotFound ) { this._addItem( this.options.buildNewItem( this.search_text ) ); } } @@ -967,7 +987,10 @@ var self = this; + // I guess this means nothing else can be + // placed in here ... this.$pickerList.html(''); + this.optionIndex = -1; if ( this.optionData.length > 0 ) { @@ -977,6 +1000,12 @@ this._showPicker(); + if ( this.options.preventNotFound ) { + this.optionIndex = 0; + this._overPickerItem( this._getPickerChildren().eq( 0 ) ); + } + + } else { this._hidePicker(); } @@ -1032,6 +1061,10 @@ if ( item[d] && self.options.localMatcher( text, item[d] ) ) { + // TODO: Figure out how to allow this to be overridden. + // as it stands now, this will find substrings that + // might not match what localMatcher thought should + // match... item[d] = item[d].replace( new RegExp( '(?![^&;]+;)(?!<[^<>]*)(' + @@ -1070,7 +1103,7 @@ if ( this.search_text.length < this.options.minSearchChars ) return; search = search.length > 1 ? search.slice( 0, search.length - 1 ) : null; - if ( search && this.localCache[search] && this.localCache[search].length < this.options.minLocalCache ) { + if ( search && this.localCache[search] && this.localCache[search].length <= this.options.minLocalCache ) { cache = _.filter( this.localCache[search], function ( item ) { return self._matcher.call( self, item ); }); @@ -1078,11 +1111,6 @@ this.optionData = cache.slice( 0, this.options.maxShowOptions ); this._renderPickerItems(); - } else if ( this.localCache[this.search_text] ) { - - this.optionData = this.localCache[this.search_text].slice( 0, this.options.maxShowOptions ); - this._renderPickerItems(); - } else { this._showPicker(); diff --git a/jqueryui-multisearch.min.js b/jqueryui-multisearch.min.js index 68ac6e6..0d301e2 100644 --- a/jqueryui-multisearch.min.js +++ b/jqueryui-multisearch.min.js @@ -1,5 +1,5 @@ -/*! jquery-ui-multisearch: jQuery UI MultiSearch (v0.0.1 built 2013-10-05) +/*! jquery-ui-multisearch: jQuery UI MultiSearch (v0.0.1 built 2013-10-06) * https://github.com/bseth99/jquery-ui-multisearch * Copyright 2013 Ben Olson; Licensed MIT */ -(function(e,t){"function"==typeof define&&define.amd?define(["jquery","underscore"],t):e.$=t(e.$,e._)})(this,function(e,t){"use strict";function i(e){return e.replace(s,"\\$&")}var s=RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g");return e.widget("osb.multisearch",{optionData:null,optionIndex:-1,itemData:null,itemIndex:-1,localCache:null,options:{source:null,ajaxOptions:null,keyAttrs:null,searchAttrs:null,formatPickerItem:function(e){return'
  • '+e.name+"
  • "},formatSelectedItem:function(e){return''+e.name+""},buildNewItem:function(e){return{id:null,name:e}},minSearchChars:2,searchThrottle:200,maxShowOptions:5,minLocalCache:50,preventNotFound:!1,preventDuplicates:!0,useAutoWidth:!0,pickerPosition:{my:"left top",at:"left bottom"},inputPosition:"end",localMatcher:function(e,t){return t.toLowerCase().indexOf(e.toLowerCase())>-1}},value:function(e){var i=this;return e?(this.remove(),t.each(e,function(e){i.add(e)}),void 0):t.map(this.itemData,function(e){return t.clone(e)})},add:function(e,t){var i,s={silent:!0};t!==void 0&&(s.at=t),(i=this._findByKeys(e))>-1&&(this._removeItem(i),(s.at===void 0||null===s.at)&&(s.at=i)),this._addItem(e,s)},remove:function(e){var i;0===arguments.length?(this.$itemList.children().not(this.$input).remove(),this.itemData=[],this.itemIndex=-1):t.isObject(e)?(i=this._findByKeys(e))>-1&&this._removeItem(i,{silent:!0}):this._removeItem(e,{silent:!0})},_findByKeys:function(e){var i,s,n=this.options.keyAttrs,r=-1;return i=t.values(t.pick(e,n)),i.length==n.length&&(s=t.findWhere(this.itemData,t.object(n,i)),s&&(r=t.indexOf(this.itemData,s))),r},_create:function(){var t=this.options;t.keyAttrs=t.keyAttrs||["id"],t.searchAttrs=t.searchAttrs||["name"],this.localCache={},this.optionData=[],this.itemData=[],this.element.addClass("osb-multisearch"),this.$input=this.element.find('[data-role="input"]').attr({autocomplete:"off",autocapitalize:"off"}),this.$picker=this.element.find('[data-role="picker"]').css("position","absolute").hide(),this.$pickerList=this.element.find('[data-role="picker-list"]'),this.$itemList=this.element.find('[data-role="selected-list"]'),this.$input.on("keydown",e.proxy(this,"_processInput")),this.$picker.on("click mouseenter mouseleave",'[data-role="picker-item"]',e.proxy(this,"_processPicker")),this.$itemList.on("click mouseenter mouseleave keydown",'[data-role="selected-item"]',e.proxy(this,"_processSelected")),this._initAutoWidth(),this._initRemote()},_initRemote:function(){var i=this,s=this.options,n=function(e,t){i._trigger("searched",null,{term:e,picker:i.$picker,list:t}),i.localCache[e]=t,i.optionData=t.slice(0,s.maxShowOptions),i._renderPickerItems()};"string"==typeof s.source?(s.ajaxOptions=s.ajaxOptions||{searchTerm:"term",dataType:"json",method:"GET"},this._remoteSearch=t.throttle(function(){i._xhr&&i._xhr.abort(),i._xhr=e.ajax({url:s.source,data:s.ajaxOptions.searchTerm+"="+i.search_text,dataType:s.ajaxOptions.dataType,method:s.ajaxOptions.method}).done(t.partial(n,i.search_text))},s.searchThrottle,{leading:!1})):this._remoteSearch=e.isFunction(s.source)?t.throttle(function(){s.source.call(i,i.search_text,t.partial(n,i.search_text))},s.searchThrottle,{leading:!1}):function(){var e=t.filter(s.source,function(e){return i._matcher.call(i,e)});i.optionData=e.slice(0,s.maxShowOptions),i._renderPickerItems()}},_initAutoWidth:function(){this.options.useAutoWidth&&(this.$sizer=e("
    ").css({position:"absolute",top:-9999,left:-9999,width:"100%",fontSize:this.$input.css("font-size"),fontFamily:this.$input.css("font-family"),fontWeight:this.$input.css("font-weight"),letterSpacing:this.$input.css("letter-spacing"),paddingLeft:this.$input.css("padding-left"),paddingRight:this.$input.css("padding-right"),marginLeft:this.$input.css("margin-left"),marginRight:this.$input.css("margin-right"),whiteSpace:"nowrap"}).insertAfter(this.$input),this.maxInputWidth=this.$sizer.width(),this.$sizer.css("width","auto"),this.$input.on("keyup",e.proxy(this,"_autoSizeInput")),this._autoSizeInput(),this.minInputWidth=this.$input.width())},_destroy:function(){this.element.removeClass("osb-multisearch"),this.$input.off("keydown keyup"),this.$picker.off("click mouseenter mouseleave"),this.$itemList.off("click mouseenter mouseleave keydown"),this._remoteSearch=null,this.localCache=null,this.optionData=null,this.itemData=null},_processInput:function(i){switch(i.keyCode){case jQuery.ui.keyCode.UP:case jQuery.ui.keyCode.DOWN:case jQuery.ui.keyCode.LEFT:case jQuery.ui.keyCode.RIGHT:return this.$input.val().length?(i.keyCode===jQuery.ui.keyCode.DOWN||i.keyCode===jQuery.ui.keyCode.RIGHT?this.optionIndex0&&this._offPickerItem(this._getPickerChildren().eq(--this.optionIndex)),!1):(i.keyCode===jQuery.ui.keyCode.DOWN||i.keyCode===jQuery.ui.keyCode.RIGHT?this._gotoPrevItem():this._gotoNextItem(),!1);case jQuery.ui.keyCode.SPACE:if(!this.$input.val().length)return this.itemIndex>-1&&this.itemIndex-1&&this.itemIndex0&&(this.itemIndex>-1&&this.itemIndex0)return this.optionIndex>-1?this._addSelectedItem():this.preventNotFound||this._addItem(this.options.buildNewItem(this.search_text)),this._clearSelectedItem(),i.stopPropagation(),i.preventDefault(),!1;break;case jQuery.ui.keyCode.ESCAPE:return this._hidePicker(),!0;default:String.fromCharCode(i.which)&&(this._clearSelectedItem(),t.defer(e.proxy(this,"_search")))}},_processPicker:function(t){var i=e(t.currentTarget);switch(t.type){case"click":this.optionIndex=this._getPickerChildren().index(i),this._addSelectedItem(),this.$input.focus();break;case"mouseenter":this._overPickerItem(i);break;case"mouseleave":this._offPickerItem(i)}},_processSelected:function(t){var i,s=e(t.target),n=e(t.currentTarget);switch(t.type){case"click":if(this.itemIndex=this._getSelectedChildren().index(n),this._activeSelectedItem(n),s.is("[data-action]")||(s=s.parents("[data-action]").first()),s.length&&n.has(s).length){if(i=s.attr("data-action"),this._trigger("itemaction",null,{action:i,data:this.itemData[this.itemIndex],element:n}))switch(i){case"remove":var r=jQuery.Event("keydown");r.keyCode=jQuery.ui.keyCode.DELETE,n.trigger(r)}}else this._trigger("itemselect",null,{data:this.itemData[this.itemIndex],element:n});break;case"mouseenter":this._overSelectedItem(n);break;case"mouseleave":this._offSelectedItem(n);break;case"keydown":switch(t.keyCode){case jQuery.ui.keyCode.UP:case jQuery.ui.keyCode.DOWN:case jQuery.ui.keyCode.LEFT:case jQuery.ui.keyCode.RIGHT:return t.keyCode===jQuery.ui.keyCode.DOWN||t.keyCode===jQuery.ui.keyCode.RIGHT?this._gotoPrevItem():this._gotoNextItem(),!1;case jQuery.ui.keyCode.SPACE:return this.itemIndex>-1&&this.itemIndex-1&&this.itemIndex0?"start"==o?r.insertAfter(this.$input):r.insertBefore(this.$input):this.$itemList.append(r),this.itemData.push(i)):(r.insertBefore(this._getSelectedChildren().eq(d)),this.itemData.splice(d,0,i)),this.$input.val(""),this.search_text="",this._hidePicker(),-1==this.itemIndex||this.itemIndex==this.itemData.length-1?this._gotoFirstItem():this.itemIndex>=d&&this.itemIndex++,l||this._trigger("added",null,{data:i,element:r,notfound:c})))},_removeSelectedItem:function(){this._removeItem(this.itemIndex)},_removeItem:function(e,t){var i=t||{},s=i.silent||!1,n=this.itemData[e];n&&(s||this._trigger("removing",null,{data:n}))&&(this._getSelectedChildren().eq(e).remove(),this.itemData.splice(e,1),this.itemData.length>0&&(this.itemIndex>e&&this.itemIndex--,this.itemIndex>-1&&this.itemIndex-1&&this._overSelectedItem(this._getSelectedChildren().eq(this.itemIndex)))},_gotoPrevItem:function(){this.itemIndex0?this.$itemList.children().not(this.$input).eq(--this.itemIndex).trigger("mouseenter"):0===this.itemIndex&&(this.itemIndex--,this.$itemList.children().removeClass("hover"))},_gotoFirstItem:function(){this.itemIndex="start"==this.options.inputPosition?-1:this.itemData.length},_renderPickerItems:function(){var i=this;this.$pickerList.html(""),this.optionData.length>0?(t.each(this.optionData,function(t){i.$pickerList.append(e(i.options.formatPickerItem(i._formatter(t))).attr("data-role","picker-item"))}),this._showPicker()):this._hidePicker()},_showPicker:function(){this.$picker.show(),this.$picker.position({my:this.options.pickerPosition.my,at:this.options.pickerPosition.at,of:this.$input})},_hidePicker:function(){this.$picker.hide()},_getPickerChildren:function(){return this.$pickerList.children('[data-role="picker-item"]')},_overPickerItem:function(e){this._trigger("pickerhoverin",null,{target:e,siblings:e.siblings('[data-role="picker-item"]')})&&e.addClass("hover").siblings('[data-role="picker-item"]').removeClass("hover")},_offPickerItem:function(e){this._trigger("pickerhoverout",null,{target:e,siblings:e.siblings('[data-role="picker-item"]')})&&(e.removeClass("hover"),this.optionIndex>-1&&this._overPickerItem(this._getPickerChildren().eq(this.optionIndex)))},_formatter:function(e){var s=this,n=this.search_text,r=t.clone(e);return n.length>0&&t.each(this.options.searchAttrs,function(e){r[e]&&s.options.localMatcher(n,r[e])&&(r[e]=r[e].replace(RegExp("(?![^&;]+;)(?!<[^<>]*)("+i(n)+")(?![^<>]*>)(?![^&;]+;)","gi"),"$1"))}),r},_matcher:function(e){var i=this;return 0===this.search_text.length||this.search_text.length>0&&t.any(t.values(t.pick(e,i.options.searchAttrs)),function(e){return i.options.localMatcher(i.search_text,e)})},_search:function(){var e,i,s=this;i=this.search_text=this.$input.val(),this.search_text.length1?i.slice(0,i.length-1):null,i&&this.localCache[i]&&this.localCache[i].length|:\\-]","g");return e.widget("osb.multisearch",{optionData:null,optionIndex:-1,itemData:null,itemIndex:-1,localCache:null,options:{source:null,ajaxOptions:null,keyAttrs:null,searchAttrs:null,formatPickerItem:function(e){return'
  • '+e.name+"
  • "},formatSelectedItem:function(e){return''+e.name+""},buildNewItem:function(e){return{id:null,name:e}},minSearchChars:2,searchThrottle:200,maxShowOptions:5,minLocalCache:50,preventNotFound:!1,preventDuplicates:!0,useAutoWidth:!0,pickerPosition:{my:"left top",at:"left bottom"},inputPosition:"end",localMatcher:function(e,t){return t.toLowerCase().indexOf(e.toLowerCase())>-1}},value:function(e){var i=this;return e?(this.remove(),t.each(e,function(e){i.add(e)}),void 0):t.map(this.itemData,function(e){return t.clone(e)})},add:function(e,t){var i,s={silent:!0};t!==void 0&&(s.at=t),(i=this._findByKeys(e))>-1&&(this._removeItem(i),(s.at===void 0||null===s.at)&&(s.at=i)),this._addItem(e,s)},remove:function(e){var i;0===arguments.length?(this._getSelectedChildren().remove(),this.itemData=[],this.itemIndex=-1):t.isObject(e)?(i=this._findByKeys(e))>-1&&this._removeItem(i,{silent:!0}):this._removeItem(e,{silent:!0})},_findByKeys:function(e){var i,s,n=this.options.keyAttrs,r=-1;return i=t.values(t.pick(e,n)),i.length==n.length&&(s=t.findWhere(this.itemData,t.object(n,i)),s&&(r=t.indexOf(this.itemData,s))),r},_create:function(){var t=this.options;t.keyAttrs=t.keyAttrs||["id"],t.searchAttrs=t.searchAttrs||["name"],this.localCache={},this.optionData=[],this.itemData=[],this.element.addClass("osb-multisearch"),this.$input=this.element.find('[data-role="input"]').attr({autocomplete:"off",autocapitalize:"off"}),this.$picker=this.element.find('[data-role="picker"]').css("position","absolute").hide(),this.$pickerList=this.element.find('[data-role="picker-list"]'),this.$itemList=this.element.find('[data-role="selected-list"]'),this.$input.on("keydown",e.proxy(this,"_processInput")),this.$picker.on("click mouseenter mouseleave",'[data-role="picker-item"]',e.proxy(this,"_processPicker")),this.$itemList.on("click mouseenter mouseleave keydown",'[data-role="selected-item"]',e.proxy(this,"_processSelected")),this._initAutoWidth(),this._initRemote();var i=this;e(document).on("click.multisearch",function(e){0===i.element.has(e.target).length&&i._hidePicker()})},_initRemote:function(){var i=this,s=this.options,n=function(e,t){i._trigger("searched",null,{term:e,picker:i.$picker,list:t}),i.localCache[e]=t,i.optionData=t.slice(0,s.maxShowOptions),i._renderPickerItems()};"string"==typeof s.source?(s.ajaxOptions=s.ajaxOptions||{searchTerm:"term",dataType:"json",method:"GET"},this._remoteSearch=t.throttle(function(){i.localCache[i.search_text]?n(i.search_text,i.localCache[i.search_text]):(i._xhr&&i._xhr.abort(),i._xhr=e.ajax({url:s.source,data:s.ajaxOptions.searchTerm+"="+i.search_text,dataType:s.ajaxOptions.dataType,method:s.ajaxOptions.method}).done(t.partial(n,i.search_text)))},s.searchThrottle,{leading:!1})):this._remoteSearch=e.isFunction(s.source)?t.throttle(function(){i.localCache[i.search_text]?n(i.search_text,i.localCache[i.search_text]):s.source.call(i,i.search_text,t.partial(n,i.search_text))},s.searchThrottle,{leading:!1}):function(){var e=t.filter(s.source,function(e){return i._matcher.call(i,e)});i.optionData=e.slice(0,s.maxShowOptions),i._renderPickerItems()}},_initAutoWidth:function(){this.options.useAutoWidth&&(this.$sizer=e("
    ").css({position:"absolute",top:-9999,left:-9999,width:"100%",fontSize:this.$input.css("font-size"),fontFamily:this.$input.css("font-family"),fontWeight:this.$input.css("font-weight"),letterSpacing:this.$input.css("letter-spacing"),paddingLeft:this.$input.css("padding-left"),paddingRight:this.$input.css("padding-right"),marginLeft:this.$input.css("margin-left"),marginRight:this.$input.css("margin-right"),whiteSpace:"nowrap"}).insertAfter(this.$input),this.maxInputWidth=this.$sizer.width(),this.$sizer.css("width","auto"),this.$input.on("keyup",e.proxy(this,"_autoSizeInput")),this._autoSizeInput(),this.minInputWidth=this.$input.width())},_destroy:function(){this.element.removeClass("osb-multisearch"),e(document).off("click.multisearch"),this.$input.off("keydown keyup"),this.$picker.off("click mouseenter mouseleave"),this.$itemList.off("click mouseenter mouseleave keydown"),this.$sizer.remove(),this.$pickerList.html(""),this._getSelectedChildren().remove(),this.$picker.show(),this._remoteSearch=null,this.localCache=null,this.optionData=null,this.itemData=null},_processInput:function(i){switch(i.keyCode){case jQuery.ui.keyCode.UP:case jQuery.ui.keyCode.DOWN:case jQuery.ui.keyCode.LEFT:case jQuery.ui.keyCode.RIGHT:return this.$input.val().length?(i.keyCode===jQuery.ui.keyCode.DOWN||i.keyCode===jQuery.ui.keyCode.RIGHT?this.optionIndex0&&this._offPickerItem(this._getPickerChildren().eq(--this.optionIndex)),!1):(i.keyCode===jQuery.ui.keyCode.DOWN||i.keyCode===jQuery.ui.keyCode.RIGHT?this._gotoPrevItem():this._gotoNextItem(),!1);case jQuery.ui.keyCode.SPACE:if(!this.$input.val().length)return this.itemIndex>-1&&this.itemIndex-1&&this.itemIndex0&&(this.itemIndex>-1&&this.itemIndex0)return this.optionIndex>-1?this._addSelectedItem():this.options.preventNotFound||this._addItem(this.options.buildNewItem(this.search_text)),this._clearSelectedItem(),i.stopPropagation(),i.preventDefault(),!1;break;case jQuery.ui.keyCode.ESCAPE:return this._hidePicker(),!0;default:String.fromCharCode(i.which)&&(this._clearSelectedItem(),t.defer(e.proxy(this,"_search")))}},_processPicker:function(t){var i=e(t.currentTarget);switch(t.type){case"click":this.optionIndex=this._getPickerChildren().index(i),this._addSelectedItem(),this.$input.focus();break;case"mouseenter":this._overPickerItem(i);break;case"mouseleave":this._offPickerItem(i)}},_processSelected:function(t){var i,s=e(t.target),n=e(t.currentTarget);switch(t.type){case"click":if(this.itemIndex=this._getSelectedChildren().index(n),this._activeSelectedItem(n),s.is("[data-action]")||(s=s.parents("[data-action]").first()),s.length&&n.has(s).length){if(i=s.attr("data-action"),this._trigger("itemaction",null,{action:i,data:this.itemData[this.itemIndex],element:n}))switch(i){case"remove":var r=jQuery.Event("keydown");r.keyCode=jQuery.ui.keyCode.DELETE,n.trigger(r)}}else this._trigger("itemselect",null,{data:this.itemData[this.itemIndex],element:n});break;case"mouseenter":this._overSelectedItem(n);break;case"mouseleave":this._offSelectedItem(n);break;case"keydown":switch(t.keyCode){case jQuery.ui.keyCode.UP:case jQuery.ui.keyCode.DOWN:case jQuery.ui.keyCode.LEFT:case jQuery.ui.keyCode.RIGHT:return t.keyCode===jQuery.ui.keyCode.DOWN||t.keyCode===jQuery.ui.keyCode.RIGHT?this._gotoPrevItem():this._gotoNextItem(),!1;case jQuery.ui.keyCode.SPACE:return this.itemIndex>-1&&this.itemIndex-1&&this.itemIndex0?"start"==o?r.insertAfter(this.$input):r.insertBefore(this.$input):this.$itemList.append(r),this.itemData.push(i)):(r.insertBefore(this._getSelectedChildren().eq(d)),this.itemData.splice(d,0,i)),this.$input.val(""),this.search_text="",this._hidePicker(),-1==this.itemIndex||this.itemIndex==this.itemData.length-1?this._gotoFirstItem():this.itemIndex>=d&&this.itemIndex++,l||this._trigger("added",null,{data:i,element:r,notfound:c})))},_removeSelectedItem:function(){this._removeItem(this.itemIndex)},_removeItem:function(e,t){var i=t||{},s=i.silent||!1,n=this.itemData[e];n&&(s||this._trigger("removing",null,{data:n}))&&(this._getSelectedChildren().eq(e).remove(),this.itemData.splice(e,1),this.itemData.length>0&&(this.itemIndex>e&&this.itemIndex--,this.itemIndex>-1&&this.itemIndex-1&&this._overSelectedItem(this._getSelectedChildren().eq(this.itemIndex)))},_gotoPrevItem:function(){this.itemIndex0?this.$itemList.children().not(this.$input).eq(--this.itemIndex).trigger("mouseenter"):0===this.itemIndex&&(this.itemIndex--,this.$itemList.children().removeClass("hover"))},_gotoFirstItem:function(){this.itemIndex="start"==this.options.inputPosition?-1:this.itemData.length},_renderPickerItems:function(){var i=this;this.$pickerList.html(""),this.optionIndex=-1,this.optionData.length>0?(t.each(this.optionData,function(t){i.$pickerList.append(e(i.options.formatPickerItem(i._formatter(t))).attr("data-role","picker-item"))}),this._showPicker(),this.options.preventNotFound&&(this.optionIndex=0,this._overPickerItem(this._getPickerChildren().eq(0)))):this._hidePicker()},_showPicker:function(){this.$picker.show(),this.$picker.position({my:this.options.pickerPosition.my,at:this.options.pickerPosition.at,of:this.$input})},_hidePicker:function(){this.$picker.hide()},_getPickerChildren:function(){return this.$pickerList.children('[data-role="picker-item"]')},_overPickerItem:function(e){this._trigger("pickerhoverin",null,{target:e,siblings:e.siblings('[data-role="picker-item"]')})&&e.addClass("hover").siblings('[data-role="picker-item"]').removeClass("hover")},_offPickerItem:function(e){this._trigger("pickerhoverout",null,{target:e,siblings:e.siblings('[data-role="picker-item"]')})&&(e.removeClass("hover"),this.optionIndex>-1&&this._overPickerItem(this._getPickerChildren().eq(this.optionIndex)))},_formatter:function(e){var s=this,n=this.search_text,r=t.clone(e);return n.length>0&&t.each(this.options.searchAttrs,function(e){r[e]&&s.options.localMatcher(n,r[e])&&(r[e]=r[e].replace(RegExp("(?![^&;]+;)(?!<[^<>]*)("+i(n)+")(?![^<>]*>)(?![^&;]+;)","gi"),"$1"))}),r},_matcher:function(e){var i=this;return 0===this.search_text.length||this.search_text.length>0&&t.any(t.values(t.pick(e,i.options.searchAttrs)),function(e){return i.options.localMatcher(i.search_text,e)})},_search:function(){var e,i,s=this;i=this.search_text=this.$input.val(),this.search_text.length1?i.slice(0,i.length-1):null,i&&this.localCache[i]&&this.localCache[i].length<=this.options.minLocalCache?(e=t.filter(this.localCache[i],function(e){return s._matcher.call(s,e)}),this.localCache[this.search_text]=e,this.optionData=e.slice(0,this.options.maxShowOptions),this._renderPickerItems()):(this._showPicker(),this._trigger("searching",null,{term:this.search_text,picker:this.$picker}),this._remoteSearch()))},_autoSizeInput:function(){var e=this.$input.val(),t=this.maxInputWidth;this.$sizer.html((i(e)||i(this.$input.attr("placeholder"))||"MMMMMMMMMMMMMMMM").replace(/ /g," ")),this.$input.css({width:Math.min(100,Math.ceil(100*(Math.max(this.minInputWidth,this.$sizer.outerWidth(!0)+25)/t)))+"%"})}}),e}); \ No newline at end of file