File: /home/accemeff/vendor/craftcms/cms/lib/vue-autosuggest/vue-autosuggest.js
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.VueAutosuggest={})}(this,function(e){"use strict";var t={name:"default-section",props:{section:{type:Object,required:!0},currentIndex:{type:Number,required:!1,default:1/0},updateCurrentIndex:{type:Function,required:!0},searchInput:{type:[String,Number],required:!1,default:""},renderSuggestion:{type:Function,required:!1},normalizeItemFunction:{type:Function,required:!0}},computed:{list:function(){var e=this.section,t=e.limit,n=e.data;return n.length<t&&(t=n.length),n.slice(0,t)},className:function(){return"autosuggest__results_title autosuggest__results_title_"+this.section.name}},methods:{getItemIndex:function(e){return this.section.start_index+e},getItemByIndex:function(e){return this.section.data[e]},getLabelByIndex:function(e){return this.section.data[e]},onMouseEnter:function(e){this.updateCurrentIndex(e.currentTarget.getAttribute("data-suggestion-index"))},onMouseLeave:function(){this.updateCurrentIndex(null)}},render:function(s){var i=this,e=this.section.label?s("li",{class:this.className},this.section.label):"";return s("ul",{attrs:{role:"listbox","aria-labelledby":"autosuggest"}},[e,this.list.map(function(e,t){var n=i.normalizeItemFunction(i.section.name,i.section.type,i.getLabelByIndex(t),e);return s("li",{attrs:{role:"option","data-suggestion-index":i.getItemIndex(t),"data-section-name":i.section.name,id:"autosuggest__results_item-"+i.getItemIndex(t)},key:i.getItemIndex(t),class:{"autosuggest__results_item-highlighted":i.getItemIndex(t)==i.currentIndex,autosuggest__results_item:!0},on:{mouseenter:i.onMouseEnter,mouseleave:i.onMouseLeave}},[i.renderSuggestion?i.renderSuggestion(n):i.$scopedSlots.default&&i.$scopedSlots.default({key:t,suggestion:n})])})])}};var n={render:function(){var s=this,e=s.$createElement,n=s._self._c||e;return n("div",{attrs:{id:s.componentAttrIdAutosuggest}},[n("input",s._g(s._b({directives:[{name:"model",rawName:"v-model",value:s.searchInput,expression:"searchInput"}],staticClass:"form-control",class:[s.isOpen?"autosuggest__input-open":"",s.inputProps.class],attrs:{type:"text",autocomplete:s.inputProps.autocomplete,role:"combobox","aria-autocomplete":"list","aria-owns":"autosuggest__results","aria-activedescendant":s.isOpen&&null!==s.currentIndex?"autosuggest__results_item-"+s.currentIndex:"","aria-haspopup":s.isOpen?"true":"false","aria-expanded":s.isOpen?"true":"false"},domProps:{value:s.searchInput},on:{keydown:s.handleKeyStroke,input:function(e){e.target.composing||(s.searchInput=e.target.value)}}},"input",s.inputProps,!1),s.listeners)),s._v(" "),n("div",{class:s.componentAttrClassAutosuggestResultsContainer},[0<s.getSize()&&!s.loading?n("div",{class:s.componentAttrClassAutosuggestResults,attrs:{"aria-labelledby":s.componentAttrIdAutosuggest}},[s._t("header"),s._v(" "),s._l(s.computedSections,function(e,t){return n(e.type,{key:s.getSectionRef(t),ref:s.getSectionRef(t),refInFor:!0,tag:"component",attrs:{"normalize-item-function":s.normalizeItem,"render-suggestion":s.renderSuggestion,section:e,"update-current-index":s.updateCurrentIndex,"search-input":s.searchInput},scopedSlots:s._u([{key:"default",fn:function(e){var t=e.suggestion,n=e._key;return[s._t("default",[s._v(" "+s._s(t.item)+" ")],{suggestion:t,index:n})]}}])})}),s._v(" "),s._t("footer")],2):s._e()])])},staticRenderFns:[],name:"Autosuggest",components:{DefaultSection:t},props:{inputProps:{type:Object,required:!0,default:function(){return{id:{type:String,default:"autosuggest__input"},onInputChange:{type:Function,required:!0},initialValue:{type:String,required:!1},onClick:{type:Function,required:!1}}}},limit:{type:Number,required:!1,default:1/0},suggestions:{type:Array,required:!0,default:function(){return[]}},renderSuggestion:{type:Function,required:!1,default:null},getSuggestionValue:{type:Function,required:!1,default:function(e){var t=e.item;return"object"==typeof t&&t.hasOwnProperty("name")?t.name:t}},shouldRenderSuggestions:{type:Function,required:!1,default:function(){return!0}},sectionConfigs:{type:Object,required:!1,default:function(){return{default:{onSelected:null}}}},onSelected:{type:Function,required:!1,default:null},componentAttrIdAutosuggest:{type:String,required:!1,default:"autosuggest"},componentAttrClassAutosuggestResultsContainer:{type:String,required:!1,default:"autosuggest__results-container"},componentAttrClassAutosuggestResults:{type:String,required:!1,default:"autosuggest__results"}},data:function(){return{searchInput:"",searchInputOriginal:null,currentIndex:null,currentItem:null,loading:!1,didSelectFromOptions:!1,computedSections:[],computedSize:0,internal_inputProps:{},defaultInputProps:{name:"q",initialValue:"",autocomplete:"off"},defaultSectionConfig:{name:"default",type:"default-section"},clientXMouseDownInitial:null}},computed:{listeners:function(){var t=this;return Object.assign({},this.$listeners,{focus:function(e){t.$listeners.focus&&t.$listeners.focus(e),t.inputProps.onFocus&&t.onFocus(e)},blur:function(e){t.$listeners.blur&&t.$listeners.blur(e),t.inputProps.onBlur&&t.onBlur(e)},click:function(){t.loading=!1,t.$listeners.click&&t.$listeners.click(t.currentItem),t.inputProps.onClick&&t.onClick(t.currentItem),t.$nextTick(function(){t.ensureItemVisible(t.currentItem,t.currentIndex)})},selected:function(){t.currentItem&&t.sectionConfigs[t.currentItem.name]&&t.sectionConfigs[t.currentItem.name].onSelected?t.sectionConfigs[t.currentItem.name].onSelected(t.currentItem,t.searchInputOriginal):t.sectionConfigs.default.onSelected?t.sectionConfigs.default.onSelected(null,t.searchInputOriginal):t.$listeners.selected?t.$emit("selected",t.currentItem):t.onSelected&&t._onSelected(t.currentItem)}})},isOpen:function(){return 0<this.getSize()&&this.shouldRenderSuggestions()&&!this.loading}},watch:{searchInput:function(e,t){this.value=e,this.didSelectFromOptions||(this.searchInputOriginal=this.value,this.currentIndex=null,this.internal_inputProps.onInputChange(e,t))},suggestions:{immediate:!0,handler:function(){var r=this;this.computedSections=[],this.computedSize=0,this.suggestions.forEach(function(e){if(e.data){var t=e.name?e.name:r.defaultSectionConfig.name,n=r.sectionConfigs[t],s=n.type,i=n.limit,u=n.label;i=i||r.limit,s=s||r.defaultSectionConfig.type,i=i||1/0,i=e.data.length<i?e.data.length:i;var o={name:t,label:u=u||e.label,type:s,limit:i,data:e.data,start_index:r.computedSize,end_index:r.computedSize+i-1};r.computedSections.push(o),r.computedSize+=i}},this)}}},created:function(){this.internal_inputProps=Object.assign({},this.defaultInputProps,this.inputProps),this.inputProps.autocomplete=this.internal_inputProps.autocomplete,this.inputProps.name=this.internal_inputProps.name,this.searchInput=this.internal_inputProps.initialValue},mounted:function(){document.addEventListener("mouseup",this.onDocumentMouseUp),document.addEventListener("mousedown",this.onDocumentMouseDown),this.loading=!0},beforeDestroy:function(){document.removeEventListener("mouseup",this.onDocumentMouseUp),document.removeEventListener("mousedown",this.onDocumentMouseDown)},methods:{getSectionRef:function(e){return"computed_section_"+e},getSize:function(){return this.computedSize},getItemByIndex:function(e){var t=!1;if(null===e)return t;for(var n=0;n<this.computedSections.length;n++)if(e>=this.computedSections[n].start_index&&e<=this.computedSections[n].end_index){var s=e-this.computedSections[n].start_index,i=this.$refs["computed_section_"+n][0];if(i){t=this.normalizeItem(this.computedSections[n].name,this.computedSections[n].type,i.getLabelByIndex(s),i.getItemByIndex(s));break}}return t},handleKeyStroke:function(e){var t=e.keyCode;if(!(-1<[16,9,18,91,93].indexOf(t)))switch(this.loading=!1,this.didSelectFromOptions=!1,t){case 40:case 38:if(e.preventDefault(),this.isOpen){if(38===t&&null===this.currentIndex)break;var n=40===t?1:-1,s=parseInt(this.currentIndex)+n;this.setCurrentIndex(s,this.getSize(),n),this.didSelectFromOptions=!0,0<this.getSize()&&0<=this.currentIndex?(this.setChangeItem(this.getItemByIndex(this.currentIndex)),this.didSelectFromOptions=!0):-1==this.currentIndex&&(this.currentIndex=null,this.searchInput=this.searchInputOriginal,e.preventDefault())}break;case 13:if(e.preventDefault(),229===t)break;0<this.getSize()&&0<=this.currentIndex&&(this.setChangeItem(this.getItemByIndex(this.currentIndex),!0),this.didSelectFromOptions=!0),this.loading=!0,this.listeners.selected(this.didSelectFromOptions);break;case 27:this.isOpen&&(this.loading=!0,this.currentIndex=null,this.searchInput=this.searchInputOriginal,e.preventDefault())}},setChangeItem:function(e,t){void 0===t&&(t=!1),null===this.currentIndex?this.currentItem=null:e&&(this.searchInput=this.getSuggestionValue(e),this.currentItem=e,t&&(this.searchInputOriginal=this.getSuggestionValue(e)),this.ensureItemVisible(e,this.currentIndex))},normalizeItem:function(e,t,n,s){return{name:e,type:t,label:n,item:s}},ensureItemVisible:function(e,t){var n=document.querySelector("."+this.componentAttrClassAutosuggestResults);if(e&&(t||0===t)&&n){var s=document.querySelector("#autosuggest__results_item-"+t);if(s){var i=n.clientHeight,u=n.scrollTop,o=s.clientHeight,r=s.offsetTop;u+i<=o+r?n.scrollTo(0,o+r-i):r<u&&0<u&&n.scrollTo(0,r)}}},updateCurrentIndex:function(e){this.currentIndex=e},clickedOnScrollbar:function(e){var t=document.querySelector("."+this.componentAttrClassAutosuggestResults);return t&&t.clientWidth<=e+16||!1},onDocumentMouseDown:function(e){var t=e.target.getBoundingClientRect?e.target.getBoundingClientRect():0;this.clientXMouseDownInitial=e.clientX-t.left},onDocumentMouseUp:function(e){var t=this;this.$el.contains(e.target)&&"INPUT"===e.target.tagName||this.clickedOnScrollbar(this.clientXMouseDownInitial)||(null!==this.currentIndex&&this.isOpen?(this.loading=!0,this.didSelectFromOptions=!0,this.setChangeItem(this.getItemByIndex(this.currentIndex),!0),this.$nextTick(function(){t.listeners.selected(!0)})):this.loading=this.shouldRenderSuggestions())},setCurrentIndex:function(e,t,n){void 0===t&&(t=-1);var s=e;null===this.currentIndex&&(s=0),this.currentIndex<0&&1===n&&(s=0),t<=e&&(s=0),this.currentIndex=s;var i,u,o,r,c=document.getElementById("autosuggest__results_item-"+this.currentIndex),a="autosuggest__results_item-highlighted";document.querySelector("."+a)&&(a,(i=document.querySelector("."+a)).classList&&i.classList.remove("autosuggest__results_item-highlighted")),c&&(r=o=a,(u=c).className.match(new RegExp("(\\s|^)"+r+"(\\s|$)"))||(u.className+=" "+o))},_onSelected:function(e){console.warn('onSelected is deprecated. Please use click event listener \n\ne.g. <vue-autosuggest ... @selected="onSelectedMethod" /> \n\nhttps://vuejs.org/v2/guide/syntax.html#v-on-Shorthand'),this.onSelected&&this.onSelected(e)},onClick:function(e){console.warn('inputProps.onClick is deprecated. Please use native click event listener \n\ne.g. <vue-autosuggest ... @click="clickMethod" /> \n\nhttps://vuejs.org/v2/guide/syntax.html#v-on-Shorthand'),this.internal_inputProps.onClick&&this.internal_inputProps.onClick(e)},onBlur:function(e){console.warn('inputProps.onBlur is deprecated. Please use native blur event listener \n\ne.g. <vue-autosuggest ... @blur="blurMethod" /> \n\nhttps://vuejs.org/v2/guide/syntax.html#v-on-Shorthand'),this.internal_inputProps.onBlur&&this.internal_inputProps.onBlur(e)},onFocus:function(e){console.warn('inputProps.onFocus is deprecated. Please use native focus event listener \n\ne.g. <vue-autosuggest ... @focus="focusMethod" /> \n\nhttps://vuejs.org/v2/guide/syntax.html#v-on-Shorthand'),this.internal_inputProps.onFocus&&this.internal_inputProps.onFocus(e)}}},s={install:function(e){e.component("vue-autosuggest-default-section",t),e.component("vue-autosuggest",n)}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(s),e.default=s,e.VueAutosuggest=n,e.DefaultSection=t,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=vue-autosuggest.js.map