ax5ui-combobox
Advanced tools
Comparing version 0.1.4 to 0.1.6
{ | ||
"name": "ax5ui-combobox", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"description": "A combobox plugin that works with Bootstrap & jQuery", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(e,t){var o=ax5.util,i=function(){var e,i=this;t&&t.call(this),this.instanceId=ax5.getGuid(),this.queue=[],this.config={theme:"default",animateTime:250,lang:{noSelected:"",noOptions:"no options",loading:"now loading.."},columnKeys:{optionValue:"value",optionText:"text",optionSelected:"selected"}},this.activecomboboxOptionGroup=null,this.activecomboboxQueueIndex=-1,this.openTimer=null,this.closeTimer=null,this.waitOptionsCallback=null,this.keyUpTimer=null,e=this.config;var n=function(e,t){return e&&e.onStateChanged?e.onStateChanged.call(t,t):this.onStateChanged&&this.onStateChanged.call(t,t),"changeValue"==t.state&&(e&&e.onChange?e.onChange.call(t,t):this.onChange&&this.onChange.call(t,t)),e=null,t=null,!0},a=function(e){return'\n <div class="ax5combobox-option-group {{theme}} {{size}}" data-ax5combobox-option-group="{{id}}">\n <div class="ax-combobox-body">\n <div class="ax-combobox-option-group-content" data-els="content"></div>\n </div>\n <div class="ax-combobox-arrow"></div> \n </div>\n '},s=function(){return'\n <div class="form-control {{formSize}} ax5combobox-display {{theme}}" \n data-ax5combobox-display="{{id}}" data-ax5combobox-instance="{{instanceId}}">\n <div class="ax5combobox-display-table" data-els="display-table">\n <div data-ax5combobox-display="label-holder"> \n <a {{^tabIndex}}href="#ax5combobox-{{id}}" {{/tabIndex}}{{#tabIndex}}tabindex="{{tabIndex}}" {{/tabIndex}}\n data-ax5combobox-display="label"\n contenteditable="true"\n spellcheck="false">{{{label}}}</a>\n </div>\n <div data-ax5combobox-display="addon"> \n {{#multiple}}{{#reset}}\n <span class="addon-icon-reset" data-selected-clear="true">{{{.}}}</span>\n {{/reset}}{{/multiple}}\n {{#icons}}\n <span class="addon-icon-closed">{{clesed}}</span>\n <span class="addon-icon-opened">{{opened}}</span>\n {{/icons}}\n {{^icons}}\n <span class="addon-icon-closed"><span class="addon-icon-arrow"></span></span>\n <span class="addon-icon-opened"><span class="addon-icon-arrow"></span></span>\n {{/icons}}\n </div>\n </div>\n </a>\n '},l=function(){return'\n <select tabindex="-1" class="form-control {{formSize}}" name="{{name}}" {{#multiple}}multiple="multiple"{{/multiple}}></select>\n '},c=function(e){return'\n {{#waitOptions}}\n <div class="ax-combobox-option-item">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">\n {{{lang.loading}}}\n </span>\n </div>\n </div>\n {{/waitOptions}}\n {{^waitOptions}}\n {{#options}}\n {{#optgroup}}\n <div class="ax-combobox-option-group">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-group-label">\n {{{.}}}\n </span>\n </div>\n {{#options}}\n {{^hide}}\n <div class="ax-combobox-option-item" data-option-focus-index="{{@findex}}" data-option-group-index="{{@gindex}}" data-option-index="{{@index}}" \n data-option-value="{{'+e.optionValue+'}}" \n {{#'+e.optionSelected+'}}data-option-selected="true"{{/'+e.optionSelected+'}}>\n <div class="ax-combobox-option-item-holder">\n {{#multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-checkbox">\n <span class="item-checkbox-wrap useCheckBox" data-option-checkbox-index="{{@i}}"></span>\n </span>\n {{/multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">{{'+e.optionText+'}}</span>\n </div>\n </div>\n {{/hide}}\n {{/options}}\n </div> \n {{/optgroup}}\n {{^optgroup}}\n {{^hide}}\n <div class="ax-combobox-option-item" data-option-focus-index="{{@findex}}" data-option-index="{{@index}}" data-option-value="{{'+e.optionValue+'}}" {{#'+e.optionSelected+'}}data-option-selected="true"{{/'+e.optionSelected+'}}>\n <div class="ax-combobox-option-item-holder">\n {{#multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-checkbox">\n <span class="item-checkbox-wrap useCheckBox" data-option-checkbox-index="{{@i}}"></span>\n </span>\n {{/multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">{{'+e.optionText+'}}</span>\n </div>\n </div>\n {{/hide}}\n {{/optgroup}}\n {{/options}}\n {{^options}}\n <div class="ax-combobox-option-item">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">\n {{{lang.noOptions}}}\n </span>\n </div>\n </div>\n {{/options}}\n {{/waitOptions}}\n '},u=function(e){return'\n {{#selected}}\n <span tabindex="-1" data-ax5combobox-selected-label="{{@i}}" data-ax5combobox-selected-text="{{text}}">{{text}}</span> \n {{/selected}}\n <span> </span>\n '},d=function(){for(var e,t=this.queue.length;t--;){var i=this.queue[t];if(i.$display&&(e=Math.max(i.$select.outerWidth(),o.number(i.minWidth)),i.$display.css({"min-width":e}),i.reset&&i.$display.find(".addon-icon-reset").css({"line-height":this.queue[t].$display.height()+"px"}),i.multiple)){var n=function(){return o.number(i.$display.css("border-top-width"))+o.number(i.$display.css("border-bottom-width"))}.call(this);i.$target.height(""),i.$display.height("");var a=i.$displayTable.outerHeight();Math.abs(a-i.$target.height())>n&&(i.$target.css({height:a+n}),i.$display.css({height:a+n}))}}return t=null,e=null,this},p=function(e){if(!this.activecomboboxOptionGroup)return this;var t=this.queue[this.activecomboboxQueueIndex],o={},i={};e&&jQuery(document.body).append(this.activecomboboxOptionGroup),o=t.$target.offset(),i={width:t.$target.outerWidth(),height:t.$target.outerHeight()},t.direction&&""!==t.direction&&"auto"!==t.direction||(t.direction="top"),e&&this.activecomboboxOptionGroup.addClass("direction-"+t.direction),this.activecomboboxOptionGroup.css(function(){return"top"==t.direction?{left:o.left,top:o.top+i.height+1,width:i.width}:"bottom"==t.direction?{left:o.left,top:o.top-this.activecomboboxOptionGroup.outerHeight()-1,width:i.width}:void 0}.call(this))},r=function(e,t){if(!this.activecomboboxOptionGroup)return this;var i=this.queue[this.activecomboboxQueueIndex],n="display";return(t=o.findParentNode(e.target,function(e){return e.getAttribute("data-option-value")?(n="optionItem",!0):i.$target.get(0)==e?(n="display",!0):void 0}))?("optionItem"===n&&(this.val(i.id,{index:{gindex:t.getAttribute("data-option-group-index"),index:t.getAttribute("data-option-index")}},void 0,"internal"),o.selectRange(i.$displayLabel,"end"),i.multiple||this.close()),this):(this.close(),this)},h=function(e){if(e.keyCode==ax5.info.eventKeys.ESC)this.close();else if(e.which==ax5.info.eventKeys.RETURN){for(var t=[],o=this.queue[this.activecomboboxQueueIndex],i=o.$displayLabel.get(0).childNodes,n=0,a=i.length;a>n;n++){var s=i[n];if(s.nodeType in O){var l=O[s.nodeType].call(this,this.activecomboboxQueueIndex,s);"undefined"!=typeof l&&t.push(l)}}console.log(t),this.val(o.id,t,!0,"internal"),o.multiple||this.close()}},x=function(e){var t=this.queue[e],o={};return o.id=t.id,o.theme=t.theme,o.size="ax5combobox-option-group-"+t.size,o.multiple=t.multiple,o.lang=t.lang,o.options=t.options,o.selected=t.selected,o.hasSelected=o.selected&&o.selected.length>0,ax5.mustache.render(u.call(this,t.columnKeys),o)},b=function(e){var t,i=this.queue[e];if(i.$displayLabel.html(x.call(this,e)),i.$target.height(""),i.$display.height(""),i.$target.height()<(t=i.$displayTable.outerHeight())){var n=function(){return o.number(i.$display.css("border-top-width"))+o.number(i.$display.css("border-bottom-width"))}();i.$target.css({height:t+n}),i.$display.css({height:t+n})}},m=function(e){this.queue[e].$displayLabel.trigger("focus"),o.selectRange(this.queue[e].$displayLabel,"end")},f=function(e,t){this.queue[e].waitOptions=!0,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,this.queue[e].columnKeys),this.queue[e]))),this.queue[e].onSearch.call({self:this,item:this.queue[e]},function(e){var t={},i=this.queue[this.activecomboboxQueueIndex];!function(e,t){var i={};t.options.forEach(function(t,o){t["@index"]=o,i[t[e.columnKeys.optionValue]]=t}),o.isArray(e.selected)&&e.selected.forEach(function(o){i[o[e.columnKeys.optionValue]]&&(t.options[i[o[e.columnKeys.optionValue]]["@index"]][e.columnKeys.optionSelected]=!0)})}(i,e),i.options=q.call(this,this.activecomboboxQueueIndex,e.options),d.call(this),t.id=i.id,t.theme=i.theme,t.size="ax5combobox-option-group-"+i.size,t.multiple=i.multiple,t.lang=i.lang,t.options=i.options,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,i.columnKeys),t)))}.bind(this))},v=function(e,t){var o,i=[],n=-1,a=this.queue[e].indexedOptions.length-1;if(""!=t){var s=/[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi;if(t=t.replace(s,""),this.queue[e].onSearch){f.call(this,e,t);try{return i}finally{i=null,n=null,a=null,o=null}}for(;a-n++;){if(o=this.queue[e].indexedOptions[n],(""+o.text).toLowerCase()==t.toLowerCase()){i=[{"@findex":o["@findex"],optionsSort:0}];break}var l=(""+o.text).toLowerCase().search(t.toLowerCase());if(l>-1&&(i.push({"@findex":o["@findex"],optionsSort:l}),i.length>2))break;l=null}i.sort(function(e,t){return e.optionsSort-t.optionsSort})}i&&i.length>0?y.call(this,e,void 0,i[0]["@findex"]):g.call(this,e);try{return i}finally{i=null,n=null,a=null,o=null}},g=function(e){this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.find("[data-option-focus-index]").removeClass("hover").removeAttr("data-option-selected"),this.queue[e].optionFocusIndex=-1},y=function(e,t,i){var n,a,s,l,c=this.queue[e];if(this.activecomboboxOptionGroup&&c.options&&c.options.length>0){if("undefined"!=typeof i?n=i:(a=-1==c.optionFocusIndex?c.optionSelectedIndex||-1:c.optionFocusIndex,-1==a?n=0:(n=a+t,0>n?n=0:n>c.optionItemLength-1&&(n=c.optionItemLength-1))),c.optionFocusIndex=n,c.options[n]&&c.options[n].hide){if("undefined"==typeof t)return this;for(;c.options[n].hide;){if(n+=t,0>n){n=0;break}if(n>c.optionItemLength-1){n=c.optionItemLength-1;break}}}if("undefined"!=typeof n&&(this.activecomboboxOptionGroup.find("[data-option-focus-index]").removeClass("hover"),s=this.activecomboboxOptionGroup.find('[data-option-focus-index="'+n+'"]').addClass("hover"),l=this.activecomboboxOptionGroup.find('[data-els="content"]'),s.get(0))){var u=s.outerHeight(),d=l.innerHeight(),p=l.scrollTop(),r=s.position().top+l.scrollTop();if(r+u>d+p?l.scrollTop(r+u-d):p>r&&l.scrollTop(r),"undefined"!=typeof t){var h=c.$displayLabel.get(0).childNodes,x=h[h.length-1];if("1"!=x.nodeType&&(x=h[h.length-2]),!x)return this;x.getAttribute("data-ax5combobox-selected-text")||(x.innerHTML=" "+c.indexedOptions[n].text,o.selectRange(c.$displayLabel,"end"))}}}},$=function(){var e=o.debounce(function(e){for(var t=[],n="",a=this.queue[e],s=a.$displayLabel.get(0).childNodes,l=0,c=s.length;c>l;l++){var u=s[l];if(u.nodeType in O){var d=O[u.nodeType].call(this,this.activecomboboxQueueIndex,u,!0);"undefined"==typeof d||(o.isString(d)?(n=d,"1"==u.nodeType&&u.getAttribute("data-ax5combobox-selected-text")?n=!1:t.push(d)):t.push(d))}}0==s.length?this.val(a.id,null,void 0,"internal"):n===!1?(this.val(a.id,t,void 0,"internal"),o.selectRange(a.$displayLabel,"end")):""!=n&&v.call(i,e,n)},300),t={click:function(e,t){var n=o.findParentNode(t.target,function(e){return e.getAttribute("data-selected-clear")?!0:void 0});n?this.val(e,{clear:!0}):i.activecomboboxQueueIndex==e?-1==this.queue[e].optionFocusIndex&&i.close():(i.open(e),""==this.queue[e].$displayLabel.text().replace(/^\W*|\W*$/g,"")&&(this.queue[e].$displayLabel.html(x.call(this,e)),m.call(this,e)))},keyUp:function(t,n){return n.which==ax5.info.eventKeys.ESC&&-1===i.activecomboboxQueueIndex?(o.stopEvent(n),this):(i.activecomboboxQueueIndex!=t&&(i.open(t),o.stopEvent(n)),void e.call(this,t))},keyDown:function(e,t){t.which==ax5.info.eventKeys.ESC?o.stopEvent(t):t.which==ax5.info.eventKeys.RETURN?o.stopEvent(t):t.which==ax5.info.eventKeys.DOWN?(y.call(this,e,1),o.stopEvent(t)):t.which==ax5.info.eventKeys.UP&&(y.call(this,e,-1),o.stopEvent(t))},focus:function(e,t){},blur:function(e,t){}};return function(e){var o=this.queue[e],i={};return o.selected=[],o.$display?(o.$displayLabel.html(x.call(this,e)),o.options=q.call(this,e,o.options),d.call(this)):(i.instanceId=this.instanceId,i.id=o.id,i.name=o.name,i.theme=o.theme,i.tabIndex=o.tabIndex,i.multiple=o.multiple,i.reset=o.reset,i.label=x.call(this,e),i.formSize=function(){return o.size?"input-"+o.size:""}(),o.$display=jQuery(ax5.mustache.render(s.call(this,e),i)),o.$displayTable=o.$display.find('[data-els="display-table"]'),o.$displayLabel=o.$display.find('[data-ax5combobox-display="label"]'),o.$target.find("select").get(0)?(o.$select=o.$target.find("select"),o.$select.attr("tabindex","-1").attr("class","form-control "+i.formSize),i.name&&o.$select.attr("name","name"),i.multiple&&o.$select.attr("multiple","multiple")):(o.$select=jQuery(ax5.mustache.render(l.call(this,e),i)),o.$target.append(o.$select)),o.$target.append(o.$display),o.options=q.call(this,e,o.options),d.call(this)),o.$display.unbind("click.ax5combobox").bind("click.ax5combobox",t.click.bind(this,e)),o.$displayLabel.unbind("focus.ax5combobox").bind("focus.ax5combobox",t.focus.bind(this,e)).unbind("blur.ax5combobox").bind("blur.ax5combobox",t.blur.bind(this,e)).unbind("keyup.ax5combobox").bind("keyup.ax5combobox",t.keyUp.bind(this,e)).unbind("keydown.ax5combobox").bind("keydown.ax5combobox",t.keyDown.bind(this,e)),i=null,o=null,e=null,this}}(),q=function(){var e=function(e,t){t?this.queue[e].selected.push(jQuery.extend({},t)):this.queue[e].selected=[]};return function(t,n){var a,s,l,c=this.queue[t],u=0;return e.call(this,t,!1),n?(c.options=n,c.indexedOptions=[],a=[],a.push('<option value=""></option>'),c.options.forEach(function(o,n){o.optgroup?(o["@gindex"]=n,o.options.forEach(function(o,s){o["@index"]=s,o["@findex"]=u,a.push('<option value="'+o[c.columnKeys.optionValue]+'" '+(o[c.columnKeys.optionSelected]?' selected="selected"':"")+">"+o[c.columnKeys.optionText]+"</option>"),o[c.columnKeys.optionSelected]&&e.call(i,t,o),c.indexedOptions.push({"@gindex":n,"@index":s,"@findex":u,value:o[c.columnKeys.optionValue],text:o[c.columnKeys.optionText]}),u++})):(o["@index"]=n,o["@findex"]=u,a.push('<option value="'+o[c.columnKeys.optionValue]+'" '+(o[c.columnKeys.optionSelected]?' selected="selected"':"")+">"+o[c.columnKeys.optionText]+"</option>"),o[c.columnKeys.optionSelected]&&e.call(i,t,o),c.indexedOptions.push({"@index":n,"@findex":u,value:o[c.columnKeys.optionValue],text:o[c.columnKeys.optionText]}),u++)}),c.optionItemLength=u,c.$select.html(a.join(""))):(s=o.toArray(c.$select.get(0).options),l=[],s.forEach(function(o,n){var a={};a[c.columnKeys.optionValue]=o.value,a[c.columnKeys.optionText]=o.text,a[c.columnKeys.optionSelected]=o.selected,a["@index"]=n,a["@findex"]=u,o.selected&&e.call(i,t,a),l.push(a),u++,a=null}),c.options=l,c.indexedOptions=l,c.$select.prepend('<option value=""></option>'),c.$select.get(0).options[0].selected=!0),a=null,s=null,l=null,c.options}}(),S=function(e){return o.isString(e)||(e=jQuery(e).data("data-ax5combobox-id")),o.isString(e)?o.search(this.queue,function(){return this.id==e}):void console.log(ax5.info.getError("ax5combobox","402","getQueIdx"))},w=function(e,t,o){return"undefined"==typeof o?e.multiple?!t:!0:o},I=function(e){this.queue[e].options.forEach(function(e){e.optgroup?e.options.forEach(function(e){e.selected=!1}):e.selected=!1})},O={1:function(t,o,i){var n,a,s=(o.textContent||o.innerText).replace(/^[\s\r\n\t]*|[\s\r\n\t]*$/g,""),l=this.queue[t];if(l.selected&&l.selected.length>0&&o.getAttribute("data-ax5combobox-selected-text")==s)return n=o.getAttribute("data-ax5combobox-selected-label"),a=l.selected[n],{index:{gindex:a["@gindex"],index:a["@index"],value:a[e.columnKeys.optionValue]}};if(o.getAttribute("data-ax5combobox-selected-text"))return s;if(""!=s){var a;return l.optionFocusIndex>-1&&(a=l.indexedOptions[l.optionFocusIndex])&&a[e.columnKeys.optionText].substr(0,s.length)===s?{index:{gindex:a["@gindex"],index:a["@index"],value:a[e.columnKeys.optionValue]}}:this.queue[t].editable||i?s:void 0}},3:function(e,t,o){var i=(t.textContent||t.innerText).replace(/^[\s\r\n\t]*|[\s\r\n\t]*$/g,""),n=this.queue[e];if(""!=i){var a;return n.optionFocusIndex>-1&&(a=this.activecomboboxOptionGroup.find('[data-option-focus-index="'+n.optionFocusIndex+'"]')),n.optionFocusIndex>-1&&a.get(0)&&a.attr("data-option-value")?{index:{gindex:a.attr("data-option-group-index"),index:a.attr("data-option-index")}}:n.editable||o?i:void 0}}};this.init=function(){this.onStateChanged=e.onStateChanged,this.onChange=e.onChange,jQuery(window).bind("resize.ax5combobox-display-"+this.instanceId,function(){d.call(this)}.bind(this))},this.bind=function(t){var i,n={};return t=jQuery.extend(!0,n,e,t),t.target?(t.$target=jQuery(t.target),t.id||(t.id=t.$target.data("data-ax5combobox-id")),t.id||(t.id="ax5combobox-"+ax5.getGuid(),t.$target.data("data-ax5combobox-id",t.id)),t.name=t.$target.attr("data-ax5combobox"),t.options&&(t.options=JSON.parse(JSON.stringify(t.options))),function(e){o.isObject(e)&&!e.error&&(t=jQuery.extend(!0,t,e))}(o.parseJson(t.$target.attr("data-ax5combobox-config"),!0)),i=o.search(this.queue,function(){return this.id==t.id}),-1===i?(this.queue.push(t),$.call(this,this.queue.length-1)):(this.queue[i]=jQuery.extend(!0,{},this.queue[i],t),$.call(this,i)),n=null,i=null,this):(console.log(ax5.info.getError("ax5combobox","401","bind")),this)},this.open=function(){var t=function(e){e.onExpand.call({self:this,item:e},function(e){if(this.waitOptionsCallback){var t={},i=this.queue[this.activecomboboxQueueIndex];!function(e,t){var i={};t.options.forEach(function(t,o){t["@index"]=o,i[t[e.columnKeys.optionValue]]=t}),o.isArray(e.selected)&&e.selected.forEach(function(o){i[o[e.columnKeys.optionValue]]&&(t.options[i[o[e.columnKeys.optionValue]]["@index"]][e.columnKeys.optionSelected]=!0)})}(i,e),i.$display.find('[data-ax5combobox-display="label"]').html(x.call(this,this.activecomboboxQueueIndex)),i.options=q.call(this,this.activecomboboxQueueIndex,e.options),d.call(this),t.id=i.id,t.theme=i.theme,t.size="ax5combobox-option-group-"+i.size,t.multiple=i.multiple,t.lang=i.lang,t.options=i.options,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,i.columnKeys),t)))}}.bind(this))};return function(i,s){this.waitOptionsCallback=null;var l,u,d=o.isNumber(i)?i:S.call(this,i),x=this.queue[d],b={};return x.$display.attr("disabled")?this:(this.openTimer&&clearTimeout(this.openTimer),this.activecomboboxOptionGroup?this.activecomboboxQueueIndex==d?this:s>2?this:(this.close(),this.openTimer=setTimeout(function(){this.open(d,(s||0)+1)}.bind(this),e.animateTime),this):(x.optionFocusIndex=-1,x.selected&&x.selected.length>0&&(x.optionSelectedIndex=x.selected[0]["@findex"]),b.id=x.id,b.theme=x.theme,b.size="ax5combobox-option-group-"+x.size,b.multiple=x.multiple,b.lang=x.lang,x.$display.attr("data-combobox-option-group-opened","true"),x.onExpand&&(b.waitOptions=!0),b.options=x.options,this.activecomboboxOptionGroup=jQuery(ax5.mustache.render(a.call(this,x.columnKeys),b)),this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,x.columnKeys),b))),this.activecomboboxQueueIndex=d,p.call(this,"append"),jQuery(window).bind("resize.ax5combobox-"+this.instanceId,function(){p.call(this)}.bind(this)),x.selected&&x.selected.length>0&&(u=this.activecomboboxOptionGroup.find('[data-option-index="'+x.selected[0]["@index"]+'"]'),u.get(0)&&(l=u.position().top-this.activecomboboxOptionGroup.height()/3,this.activecomboboxOptionGroup.find('[data-els="content"]').stop().animate({scrollTop:l},x.animateTime,"swing",function(){}))),jQuery(window).bind("keyup.ax5combobox-"+this.instanceId,function(e){e=e||window.event,h.call(this,e),o.stopEvent(e)}.bind(this)),jQuery(window).bind("click.ax5combobox-"+this.instanceId,function(e){e=e||window.event,r.call(this,e),o.stopEvent(e)}.bind(this)),n.call(this,x,{self:this,state:"open",item:x}),x.onExpand&&(this.waitOptionsCallback=!0,t.call(this,x)),b=null,l=null,u=null,this))}}(),this.update=function(e){return this.bind(e),this},this.val=function(){var e={index:function(e,t,n,a){var s=this.queue[e];o.isString(t.index.gindex)?"undefined"!=typeof s.options[t.index.gindex]&&(s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected]=w(s,s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected],n),i.activecomboboxOptionGroup.find('[data-option-group-index="'+t.index.gindex+'"][data-option-index="'+t.index.index+'"]').attr("data-option-Selected",s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected].toString())):"undefined"!=typeof s.options[t.index.index]&&(s.options[t.index.index][s.columnKeys.optionSelected]=w(s,s.options[t.index.index][s.columnKeys.optionSelected],n),i.activecomboboxOptionGroup.find('[data-option-index="'+t.index.index+'"]').attr("data-option-Selected",s.options[t.index.index][s.columnKeys.optionSelected].toString())),("undefined"==typeof a||"justSetValue"!==a)&&(q.call(this,e,s.options),b.call(this,e),p.call(this),o.selectRange(s.$displayLabel,"end"))},arr:function(t,n,a){n.forEach(function(n){if(o.isString(n)||o.isNumber(n))e.value.call(i,t,n,a,"justSetValue");else for(var s in e)if(n[s]){e[s].call(i,t,n,a,"justSetValue");break}}),q.call(this,t,this.queue[t].options),b.call(this,t),p.call(this),o.selectRange(this.queue[t].$displayLabel,"end")},value:function(e,t,i,n){var a,s=this.queue[e],l=o.search(s.options,function(){return this[s.columnKeys.optionValue]==t});l>-1?s.options[l][s.columnKeys.optionSelected]=w(s,s.options[l][s.columnKeys.optionSelected],i):(l=s.options.length,a={"@index":l,hide:!0,addedOption:!0},a[s.columnKeys.optionValue]=t,a[s.columnKeys.optionText]=t,s.options.push(a),s.options[l][s.columnKeys.optionSelected]=w(s,s.options[l][s.columnKeys.optionSelected],i)),("undefined"==typeof n||"justSetValue"!==n)&&(q.call(this,e,this.queue[e].options),b.call(this,e),p.call(this),o.selectRange(this.queue[e].$displayLabel,"end"))},text:function(e,t,o,i){},clear:function(e){I.call(this,e),q.call(this,e,this.queue[e].options),m.call(this,e),g.call(this,e),this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.find("[data-option-index]").attr("data-option-Selected","false"),this.queue[e].optionSelectedIndex=-1}};return function(t,i,a,s){var l=o.isNumber(t)?t:S.call(this,t);if(-1===l)return void console.log(ax5.info.getError("ax5combobox","402","val"));if("undefined"==typeof i)return this.queue[l].selected;if(o.isArray(i))e.clear.call(this,l),e.arr.call(this,l,this.queue[l].multiple||0==i.length?i:[i[i.length-1]],a);else if(o.isString(i)||o.isNumber(i))"undefined"==typeof i||null===i||this.queue[l].multiple||I.call(this,l),e.value.call(this,l,i,a),b.call(this,l);else if(null===i)e.clear.call(this,l),b.call(this,l);else{this.queue[l].multiple||I.call(this,l);for(var c in e)if(i[c]){e[c].call(this,l,i,a);break}b.call(this,l)}return"undefined"!=typeof i&&n.call(this,this.queue[l],{self:this,item:this.queue[l],state:s?"changeValue":"setValue",value:this.queue[l].selected,internal:s}),t=null,this}}(),this.close=function(t){return this.closeTimer&&clearTimeout(this.closeTimer),this.activecomboboxOptionGroup?(t=this.queue[this.activecomboboxQueueIndex],t.optionFocusIndex=-1,t.$display.removeAttr("data-combobox-option-group-opened").trigger("focus"),this.activecomboboxOptionGroup.addClass("destroy"),jQuery(window).unbind("resize.ax5combobox-"+this.instanceId).unbind("click.ax5combobox-"+this.instanceId).unbind("keyup.ax5combobox-"+this.instanceId),this.closeTimer=setTimeout(function(){this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.remove(),this.activecomboboxOptionGroup=null,this.activecomboboxQueueIndex=-1,n.call(this,t,{self:this,state:"close"})}.bind(this),e.animateTime),this.waitOptionsCallback=null,this):this},this.enable=function(e){var t=S.call(this,e);return this.queue[t].$display.removeAttr("disabled"),this.queue[t].$input.removeAttr("disabled"),n.call(this,this.queue[t],{self:this,state:"enable"}),this},this.disable=function(e){var t=S.call(this,e);return this.queue[t].$display.attr("disabled","disabled"),this.queue[t].$input.attr("disabled","disabled"),n.call(this,this.queue[t],{self:this,state:"disable"}),this},this.main=function(){arguments&&o.isObject(arguments[0])?this.setConfig(arguments[0]):this.init()}.apply(this,arguments)};e.combobox=function(){return o.isFunction(t)&&(i.prototype=new t),i}()}(ax5.ui,ax5.ui.root),ax5.ui.combobox_instance=new ax5.ui.combobox,jQuery.fn.ax5combobox=function(){return function(e){if(ax5.util.isString(arguments[0])){var t=arguments[0];switch(t){case"open":return ax5.ui.combobox_instance.open(this);case"close":return ax5.ui.combobox_instance.close(this);case"setValue":return ax5.ui.combobox_instance.val(this,arguments[1],arguments[2]);case"getValue":return ax5.ui.combobox_instance.val(this);case"enable":return ax5.ui.combobox_instance.enable(this);case"disable":return ax5.ui.combobox_instance.disable(this);default:return this}}else"undefined"==typeof e&&(e={}),jQuery.each(this,function(){var t={target:this};e=jQuery.extend({},e,t),ax5.ui.combobox_instance.bind(e)});return this}}(); | ||
"use strict";!function(e,t){var o=ax5.util,i=function(){var e,i=this;t&&t.call(this),this.instanceId=ax5.getGuid(),this.queue=[],this.config={theme:"default",animateTime:250,lang:{noSelected:"",noOptions:"no options",loading:"now loading.."},columnKeys:{optionValue:"value",optionText:"text",optionSelected:"selected"}},this.activecomboboxOptionGroup=null,this.activecomboboxQueueIndex=-1,this.openTimer=null,this.closeTimer=null,this.waitOptionsCallback=null,this.keyUpTimer=null,e=this.config;var n=function(e,t){return e&&e.onStateChanged?e.onStateChanged.call(t,t):this.onStateChanged&&this.onStateChanged.call(t,t),"changeValue"==t.state&&(e&&e.onChange?e.onChange.call(t,t):this.onChange&&this.onChange.call(t,t)),e=null,t=null,!0},a=function(e){return'\n <div class="ax5combobox-option-group {{theme}} {{size}}" data-ax5combobox-option-group="{{id}}">\n <div class="ax-combobox-body">\n <div class="ax-combobox-option-group-content" data-els="content"></div>\n </div>\n <div class="ax-combobox-arrow"></div> \n </div>\n '},s=function(){return'\n <div class="form-control {{formSize}} ax5combobox-display {{theme}}" \n data-ax5combobox-display="{{id}}" data-ax5combobox-instance="{{instanceId}}">\n <div class="ax5combobox-display-table" data-els="display-table">\n <div data-ax5combobox-display="label-holder"> \n <a {{^tabIndex}}href="#ax5combobox-{{id}}" {{/tabIndex}}{{#tabIndex}}tabindex="{{tabIndex}}" {{/tabIndex}}\n data-ax5combobox-display="label"\n contenteditable="true"\n spellcheck="false">{{{label}}}</a>\n </div>\n <div data-ax5combobox-display="addon"> \n {{#multiple}}{{#reset}}\n <span class="addon-icon-reset" data-selected-clear="true">{{{.}}}</span>\n {{/reset}}{{/multiple}}\n {{#icons}}\n <span class="addon-icon-closed">{{clesed}}</span>\n <span class="addon-icon-opened">{{opened}}</span>\n {{/icons}}\n {{^icons}}\n <span class="addon-icon-closed"><span class="addon-icon-arrow"></span></span>\n <span class="addon-icon-opened"><span class="addon-icon-arrow"></span></span>\n {{/icons}}\n </div>\n </div>\n </a>\n '},l=function(){return'\n <select tabindex="-1" class="form-control {{formSize}}" name="{{name}}" {{#multiple}}multiple="multiple"{{/multiple}}></select>\n '},c=function(e){return'\n {{#waitOptions}}\n <div class="ax-combobox-option-item">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">\n {{{lang.loading}}}\n </span>\n </div>\n </div>\n {{/waitOptions}}\n {{^waitOptions}}\n {{#options}}\n {{#optgroup}}\n <div class="ax-combobox-option-group">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-group-label">\n {{{.}}}\n </span>\n </div>\n {{#options}}\n {{^hide}}\n <div class="ax-combobox-option-item" data-option-focus-index="{{@findex}}" data-option-group-index="{{@gindex}}" data-option-index="{{@index}}" \n data-option-value="{{'+e.optionValue+'}}" \n {{#'+e.optionSelected+'}}data-option-selected="true"{{/'+e.optionSelected+'}}>\n <div class="ax-combobox-option-item-holder">\n {{#multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-checkbox">\n <span class="item-checkbox-wrap useCheckBox" data-option-checkbox-index="{{@i}}"></span>\n </span>\n {{/multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">{{'+e.optionText+'}}</span>\n </div>\n </div>\n {{/hide}}\n {{/options}}\n </div> \n {{/optgroup}}\n {{^optgroup}}\n {{^hide}}\n <div class="ax-combobox-option-item" data-option-focus-index="{{@findex}}" data-option-index="{{@index}}" data-option-value="{{'+e.optionValue+'}}" {{#'+e.optionSelected+'}}data-option-selected="true"{{/'+e.optionSelected+'}}>\n <div class="ax-combobox-option-item-holder">\n {{#multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-checkbox">\n <span class="item-checkbox-wrap useCheckBox" data-option-checkbox-index="{{@i}}"></span>\n </span>\n {{/multiple}}\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">{{'+e.optionText+'}}</span>\n </div>\n </div>\n {{/hide}}\n {{/optgroup}}\n {{/options}}\n {{^options}}\n <div class="ax-combobox-option-item">\n <div class="ax-combobox-option-item-holder">\n <span class="ax-combobox-option-item-cell ax-combobox-option-item-label">\n {{{lang.noOptions}}}\n </span>\n </div>\n </div>\n {{/options}}\n {{/waitOptions}}\n '},u=function(e){return'\n {{#selected}}\n <span tabindex="-1" data-ax5combobox-selected-label="{{@i}}" data-ax5combobox-selected-text="{{text}}">{{text}}</span> \n {{/selected}}\n <span> </span>\n '},d=function(){for(var e,t=this.queue.length;t--;){var i=this.queue[t];if(i.$display&&(e=Math.max(i.$select.outerWidth(),o.number(i.minWidth)),i.$display.css({"min-width":e}),i.reset&&i.$display.find(".addon-icon-reset").css({"line-height":this.queue[t].$display.height()+"px"}),i.multiple)){var n=function(){return o.number(i.$display.css("border-top-width"))+o.number(i.$display.css("border-bottom-width"))}.call(this);i.$target.height(""),i.$display.height("");var a=i.$displayTable.outerHeight();Math.abs(a-i.$target.height())>n&&(i.$target.css({height:a+n}),i.$display.css({height:a+n}))}}return t=null,e=null,this},p=function(e){if(!this.activecomboboxOptionGroup)return this;var t=this.queue[this.activecomboboxQueueIndex],o={},i={};e&&jQuery(document.body).append(this.activecomboboxOptionGroup),o=t.$target.offset(),i={width:t.$target.outerWidth(),height:t.$target.outerHeight()},t.direction&&""!==t.direction&&"auto"!==t.direction||(t.direction="top"),e&&this.activecomboboxOptionGroup.addClass("direction-"+t.direction),this.activecomboboxOptionGroup.css(function(){return"top"==t.direction?{left:o.left,top:o.top+i.height+1,width:i.width}:"bottom"==t.direction?{left:o.left,top:o.top-this.activecomboboxOptionGroup.outerHeight()-1,width:i.width}:void 0}.call(this))},r=function(e,t){if(!this.activecomboboxOptionGroup)return this;var i=this.queue[this.activecomboboxQueueIndex],n="display";return(t=o.findParentNode(e.target,function(e){return e.getAttribute("data-option-value")?(n="optionItem",!0):i.$target.get(0)==e?(n="display",!0):void 0}))?("optionItem"===n&&(this.val(i.id,{index:{gindex:t.getAttribute("data-option-group-index"),index:t.getAttribute("data-option-index")}},void 0,"internal"),o.selectRange(i.$displayLabel,"end"),i.multiple||this.close()),this):(this.close(),this)},h=function(e){if(e.keyCode==ax5.info.eventKeys.ESC)this.close();else if(e.which==ax5.info.eventKeys.RETURN){for(var t=[],o=this.queue[this.activecomboboxQueueIndex],i=o.$displayLabel.get(0).childNodes,n=0,a=i.length;a>n;n++){var s=i[n];if(s.nodeType in O){var l=O[s.nodeType].call(this,this.activecomboboxQueueIndex,s);"undefined"!=typeof l&&t.push(l)}}this.val(o.id,t,!0,"internal"),o.multiple||this.close()}},x=function(e){var t=this.queue[e],o={};return o.id=t.id,o.theme=t.theme,o.size="ax5combobox-option-group-"+t.size,o.multiple=t.multiple,o.lang=t.lang,o.options=t.options,o.selected=t.selected,o.hasSelected=o.selected&&o.selected.length>0,ax5.mustache.render(u.call(this,t.columnKeys),o)},b=function(e){var t,i=this.queue[e];if(i.$displayLabel.html(x.call(this,e)),i.$target.height(""),i.$display.height(""),i.$target.height()<(t=i.$displayTable.outerHeight())){var n=function(){return o.number(i.$display.css("border-top-width"))+o.number(i.$display.css("border-bottom-width"))}();i.$target.css({height:t+n}),i.$display.css({height:t+n})}},m=function(e){this.queue[e].$displayLabel.trigger("focus"),o.selectRange(this.queue[e].$displayLabel,"end")},f=function(e,t){this.queue[e].waitOptions=!0,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,this.queue[e].columnKeys),this.queue[e]))),this.queue[e].onSearch.call({self:this,item:this.queue[e]},function(e){var t={},i=this.queue[this.activecomboboxQueueIndex];!function(e,t){var i={};t.options.forEach(function(t,o){t["@index"]=o,i[t[e.columnKeys.optionValue]]=t}),o.isArray(e.selected)&&e.selected.forEach(function(o){i[o[e.columnKeys.optionValue]]&&(t.options[i[o[e.columnKeys.optionValue]]["@index"]][e.columnKeys.optionSelected]=!0)})}(i,e),i.options=q.call(this,this.activecomboboxQueueIndex,e.options),d.call(this),t.id=i.id,t.theme=i.theme,t.size="ax5combobox-option-group-"+i.size,t.multiple=i.multiple,t.lang=i.lang,t.options=i.options,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,i.columnKeys),t)))}.bind(this))},v=function(e,t){if(-1==this.activecomboboxQueueIndex)return this;var o,i=[],n=-1,a=this.queue[e].indexedOptions.length-1;if(""!=t){var s=/[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi;if(t=t.replace(s,""),this.queue[e].onSearch){f.call(this,e,t);try{return i}finally{i=null,n=null,a=null,o=null}}for(;a-n++;){if(o=this.queue[e].indexedOptions[n],(""+o.text).toLowerCase()==t.toLowerCase()){i=[{"@findex":o["@findex"],optionsSort:0}];break}var l=(""+o.text).toLowerCase().search(t.toLowerCase());if(l>-1&&(i.push({"@findex":o["@findex"],optionsSort:l}),i.length>2))break;l=null}i.sort(function(e,t){return e.optionsSort-t.optionsSort})}i&&i.length>0?y.call(this,e,void 0,i[0]["@findex"]):g.call(this,e);try{return i}finally{i=null,n=null,a=null,o=null}},g=function(e){this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.find("[data-option-focus-index]").removeClass("hover").removeAttr("data-option-selected"),this.queue[e].optionFocusIndex=-1},y=function(e,t,i){var n,a,s,l,c=this.queue[e];if(this.activecomboboxOptionGroup&&c.options&&c.options.length>0){if("undefined"!=typeof i?n=i:(a=-1==c.optionFocusIndex?c.optionSelectedIndex||-1:c.optionFocusIndex,-1==a?n=0:(n=a+t,0>n?n=0:n>c.optionItemLength-1&&(n=c.optionItemLength-1))),c.optionFocusIndex=n,c.options[n]&&c.options[n].hide){if("undefined"==typeof t)return this;for(;c.options[n].hide;){if(n+=t,0>n){n=0;break}if(n>c.optionItemLength-1){n=c.optionItemLength-1;break}}}if("undefined"!=typeof n&&(this.activecomboboxOptionGroup.find("[data-option-focus-index]").removeClass("hover"),s=this.activecomboboxOptionGroup.find('[data-option-focus-index="'+n+'"]').addClass("hover"),l=this.activecomboboxOptionGroup.find('[data-els="content"]'),s.get(0))){var u=s.outerHeight(),d=l.innerHeight(),p=l.scrollTop(),r=s.position().top+l.scrollTop();if(r+u>d+p?l.scrollTop(r+u-d):p>r&&l.scrollTop(r),"undefined"!=typeof t){var h=c.$displayLabel.get(0).childNodes,x=h[h.length-1];if("1"!=x.nodeType&&(x=h[h.length-2]),!x)return this;x.getAttribute("data-ax5combobox-selected-text")||(x.innerHTML=" "+c.indexedOptions[n].text,o.selectRange(c.$displayLabel,"end"))}}}},$=function(){var e=o.debounce(function(e){if(-1==this.activecomboboxQueueIndex)return this;for(var t=[],n="",a=this.queue[e],s=a.$displayLabel.get(0).childNodes,l=0,c=s.length;c>l;l++){var u=s[l];if(u.nodeType in O){var d=O[u.nodeType].call(this,this.activecomboboxQueueIndex,u,!0);"undefined"==typeof d||(o.isString(d)?(n=d,"1"==u.nodeType&&u.getAttribute("data-ax5combobox-selected-text")?n=!1:t.push(d)):t.push(d))}}0==s.length?this.val(a.id,null,void 0,"internal"):n===!1?(this.val(a.id,t,void 0,"internal"),o.selectRange(a.$displayLabel,"end")):""!=n&&v.call(i,e,n)},300),t=function(e){for(var t,i=[],n=this.queue[e],a=n.$displayLabel.get(0).childNodes,s=0,l=a.length;l>s;s++){var c=a[s];if(c.nodeType in O){var u=O[c.nodeType].call(this,e,c,!0);"undefined"==typeof u||(o.isString(u)?(t=u,i.push(u)):i.push(u))}}"undefined"!=typeof t&&this.val(n.id,i,void 0,"internal")},n={click:function(e,t){var n=o.findParentNode(t.target,function(e){return e.getAttribute("data-selected-clear")?!0:void 0});n?this.val(e,{clear:!0}):i.activecomboboxQueueIndex==e?-1==this.queue[e].optionFocusIndex&&i.close():(i.open(e),""==this.queue[e].$displayLabel.text().replace(/^\W*|\W*$/g,"")&&(this.queue[e].$displayLabel.html(x.call(this,e)),m.call(this,e)))},keyUp:function(t,n){return n.which==ax5.info.eventKeys.ESC&&-1===i.activecomboboxQueueIndex?(o.stopEvent(n),this):(i.activecomboboxQueueIndex!=t&&(i.open(t),o.stopEvent(n)),void e.call(this,t))},keyDown:function(e,t){t.which==ax5.info.eventKeys.ESC?o.stopEvent(t):t.which==ax5.info.eventKeys.RETURN?o.stopEvent(t):t.which==ax5.info.eventKeys.DOWN?(y.call(this,e,1),o.stopEvent(t)):t.which==ax5.info.eventKeys.UP&&(y.call(this,e,-1),o.stopEvent(t))},focus:function(e,t){},blur:function(e,i){t.call(this,e),o.stopEvent(i)},selectChange:function(e,t){this.val(e,this.queue[e].$select.val(),!0)}};return function(e){var t=this.queue[e],o={};return t.selected=[],t.$display?(t.$displayLabel.html(x.call(this,e)),t.options=q.call(this,e,t.options),d.call(this)):(o.instanceId=this.instanceId,o.id=t.id,o.name=t.name,o.theme=t.theme,o.tabIndex=t.tabIndex,o.multiple=t.multiple,o.reset=t.reset,o.label=x.call(this,e),o.formSize=function(){return t.size?"input-"+t.size:""}(),t.$display=jQuery(ax5.mustache.render(s.call(this,e),o)),t.$displayTable=t.$display.find('[data-els="display-table"]'),t.$displayLabel=t.$display.find('[data-ax5combobox-display="label"]'),t.$target.find("select").get(0)?(t.$select=t.$target.find("select"),t.$select.attr("tabindex","-1").attr("class","form-control "+o.formSize),o.name&&t.$select.attr("name","name"),o.multiple&&t.$select.attr("multiple","multiple")):(t.$select=jQuery(ax5.mustache.render(l.call(this,e),o)),t.$target.append(t.$select)),t.$target.append(t.$display),t.options=q.call(this,e,t.options),d.call(this)),t.$display.unbind("click.ax5combobox").bind("click.ax5combobox",n.click.bind(this,e)),t.$displayLabel.unbind("focus.ax5combobox").bind("focus.ax5combobox",n.focus.bind(this,e)).unbind("blur.ax5combobox").bind("blur.ax5combobox",n.blur.bind(this,e)).unbind("keyup.ax5combobox").bind("keyup.ax5combobox",n.keyUp.bind(this,e)).unbind("keydown.ax5combobox").bind("keydown.ax5combobox",n.keyDown.bind(this,e)),t.$select.unbind("change.ax5combobox").bind("change.ax5combobox",n.selectChange.bind(this,e)),o=null,t=null,e=null,this}}(),q=function(){var e=function(e,t){t?this.queue[e].selected.push(jQuery.extend({},t)):this.queue[e].selected=[]};return function(t,n){var a,s,l,c=this.queue[t],u=0;return e.call(this,t,!1),n?(c.options=n,c.indexedOptions=[],a=[],a.push('<option value=""></option>'),c.options.forEach(function(o,n){o.optgroup?(o["@gindex"]=n,o.options.forEach(function(o,s){o["@index"]=s,o["@findex"]=u,a.push('<option value="'+o[c.columnKeys.optionValue]+'" '+(o[c.columnKeys.optionSelected]?' selected="selected"':"")+">"+o[c.columnKeys.optionText]+"</option>"),o[c.columnKeys.optionSelected]&&e.call(i,t,o),c.indexedOptions.push({"@gindex":n,"@index":s,"@findex":u,value:o[c.columnKeys.optionValue],text:o[c.columnKeys.optionText]}),u++})):(o["@index"]=n,o["@findex"]=u,a.push('<option value="'+o[c.columnKeys.optionValue]+'" '+(o[c.columnKeys.optionSelected]?' selected="selected"':"")+">"+o[c.columnKeys.optionText]+"</option>"),o[c.columnKeys.optionSelected]&&e.call(i,t,o),c.indexedOptions.push({"@index":n,"@findex":u,value:o[c.columnKeys.optionValue],text:o[c.columnKeys.optionText]}),u++)}),c.optionItemLength=u,c.$select.html(a.join(""))):(s=o.toArray(c.$select.get(0).options),l=[],s.forEach(function(o,n){var a={};a[c.columnKeys.optionValue]=o.value,a[c.columnKeys.optionText]=o.text,a[c.columnKeys.optionSelected]=o.selected,a["@index"]=n,a["@findex"]=u,o.selected&&e.call(i,t,a),l.push(a),u++,a=null}),c.options=l,c.indexedOptions=l,c.$select.prepend('<option value=""></option>'),c.$select.get(0).options[0].selected=!0),a=null,s=null,l=null,c.options}}(),S=function(e){return o.isString(e)||(e=jQuery(e).data("data-ax5combobox-id")),o.isString(e)?o.search(this.queue,function(){return this.id==e}):void console.log(ax5.info.getError("ax5combobox","402","getQueIdx"))},I=function(e,t,o){return"undefined"==typeof o?e.multiple?!t:!0:o},w=function(e){this.queue[e].options.forEach(function(e){e.optgroup?e.options.forEach(function(e){e.selected=!1}):e.selected=!1})},O={1:function(t,o,i){var n,a,s=(o.textContent||o.innerText).replace(/^[\s\r\n\t]*|[\s\r\n\t]*$/g,""),l=this.queue[t];if(l.selected&&l.selected.length>0&&o.getAttribute("data-ax5combobox-selected-text")==s)return n=o.getAttribute("data-ax5combobox-selected-label"),a=l.selected[n],{index:{gindex:a["@gindex"],index:a["@index"],value:a[e.columnKeys.optionValue]}};if(o.getAttribute("data-ax5combobox-selected-text"))return s;if(""!=s){var a;return l.optionFocusIndex>-1&&(a=l.indexedOptions[l.optionFocusIndex])&&a[e.columnKeys.optionText].substr(0,s.length)===s?{index:{gindex:a["@gindex"],index:a["@index"],value:a[e.columnKeys.optionValue]}}:this.queue[t].editable||i?s:void 0}},3:function(e,t,o){var i=(t.textContent||t.innerText).replace(/^[\s\r\n\t]*|[\s\r\n\t]*$/g,""),n=this.queue[e];if(""!=i){var a;return n.optionFocusIndex>-1&&(a=this.activecomboboxOptionGroup.find('[data-option-focus-index="'+n.optionFocusIndex+'"]')),n.optionFocusIndex>-1&&a.get(0)&&a.attr("data-option-value")?{index:{gindex:a.attr("data-option-group-index"),index:a.attr("data-option-index")}}:n.editable||o?i:void 0}}};this.init=function(){this.onStateChanged=e.onStateChanged,this.onChange=e.onChange,jQuery(window).bind("resize.ax5combobox-display-"+this.instanceId,function(){d.call(this)}.bind(this))},this.bind=function(t){var i,n={};return t=jQuery.extend(!0,n,e,t),t.target?(t.$target=jQuery(t.target),t.id||(t.id=t.$target.data("data-ax5combobox-id")),t.id||(t.id="ax5combobox-"+ax5.getGuid(),t.$target.data("data-ax5combobox-id",t.id)),t.name=t.$target.attr("data-ax5combobox"),t.options&&(t.options=JSON.parse(JSON.stringify(t.options))),function(e){o.isObject(e)&&!e.error&&(t=jQuery.extend(!0,t,e))}(o.parseJson(t.$target.attr("data-ax5combobox-config"),!0)),i=o.search(this.queue,function(){return this.id==t.id}),-1===i?(this.queue.push(t),$.call(this,this.queue.length-1)):(this.queue[i]=jQuery.extend(!0,{},this.queue[i],t),$.call(this,i)),n=null,i=null,this):(console.log(ax5.info.getError("ax5combobox","401","bind")),this)},this.open=function(){var t=function(e){e.onExpand.call({self:this,item:e},function(e){if(this.waitOptionsCallback){var t={},i=this.queue[this.activecomboboxQueueIndex];!function(e,t){var i={};t.options.forEach(function(t,o){t["@index"]=o,i[t[e.columnKeys.optionValue]]=t}),o.isArray(e.selected)&&e.selected.forEach(function(o){i[o[e.columnKeys.optionValue]]&&(t.options[i[o[e.columnKeys.optionValue]]["@index"]][e.columnKeys.optionSelected]=!0)})}(i,e),i.$display.find('[data-ax5combobox-display="label"]').html(x.call(this,this.activecomboboxQueueIndex)),i.options=q.call(this,this.activecomboboxQueueIndex,e.options),d.call(this),t.id=i.id,t.theme=i.theme,t.size="ax5combobox-option-group-"+i.size,t.multiple=i.multiple,t.lang=i.lang,t.options=i.options,this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,i.columnKeys),t)))}}.bind(this))};return function(i,s){this.waitOptionsCallback=null;var l,u,d=o.isNumber(i)?i:S.call(this,i),x=this.queue[d],b={};return x.$display.attr("disabled")?this:(this.openTimer&&clearTimeout(this.openTimer),this.activecomboboxOptionGroup?this.activecomboboxQueueIndex==d?this:s>2?this:(this.close(),this.openTimer=setTimeout(function(){this.open(d,(s||0)+1)}.bind(this),e.animateTime),this):(x.optionFocusIndex=-1,x.selected&&x.selected.length>0&&(x.optionSelectedIndex=x.selected[0]["@findex"]),b.id=x.id,b.theme=x.theme,b.size="ax5combobox-option-group-"+x.size,b.multiple=x.multiple,b.lang=x.lang,x.$display.attr("data-combobox-option-group-opened","true"),x.onExpand&&(b.waitOptions=!0),b.options=o.filter(x.options,function(){return!this.hide}),this.activecomboboxOptionGroup=jQuery(ax5.mustache.render(a.call(this,x.columnKeys),b)),this.activecomboboxOptionGroup.find('[data-els="content"]').html(jQuery(ax5.mustache.render(c.call(this,x.columnKeys),b))),this.activecomboboxQueueIndex=d,p.call(this,"append"),jQuery(window).bind("resize.ax5combobox-"+this.instanceId,function(){p.call(this)}.bind(this)),x.selected&&x.selected.length>0&&(u=this.activecomboboxOptionGroup.find('[data-option-index="'+x.selected[0]["@index"]+'"]'),u.get(0)&&(l=u.position().top-this.activecomboboxOptionGroup.height()/3,this.activecomboboxOptionGroup.find('[data-els="content"]').stop().animate({scrollTop:l},x.animateTime,"swing",function(){}))),jQuery(window).bind("keyup.ax5combobox-"+this.instanceId,function(e){e=e||window.event,h.call(this,e),o.stopEvent(e)}.bind(this)),jQuery(window).bind("click.ax5combobox-"+this.instanceId,function(e){e=e||window.event,r.call(this,e),o.stopEvent(e)}.bind(this)),n.call(this,x,{self:this,state:"open",item:x}),x.onExpand&&(this.waitOptionsCallback=!0,t.call(this,x)),b=null,l=null,u=null,this))}}(),this.update=function(e){return this.bind(e),this},this.val=function(){var e={index:function(e,t,n,a){var s=this.queue[e];o.isString(t.index.gindex)?"undefined"!=typeof s.options[t.index.gindex]&&(s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected]=I(s,s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected],n),i.activecomboboxOptionGroup.find('[data-option-group-index="'+t.index.gindex+'"][data-option-index="'+t.index.index+'"]').attr("data-option-Selected",s.options[t.index.gindex].options[t.index.index][s.columnKeys.optionSelected].toString())):"undefined"!=typeof s.options[t.index.index]&&(s.options[t.index.index][s.columnKeys.optionSelected]=I(s,s.options[t.index.index][s.columnKeys.optionSelected],n),i.activecomboboxOptionGroup.find('[data-option-index="'+t.index.index+'"]').attr("data-option-Selected",s.options[t.index.index][s.columnKeys.optionSelected].toString())),("undefined"==typeof a||"justSetValue"!==a)&&(q.call(this,e,s.options),b.call(this,e),p.call(this),o.selectRange(s.$displayLabel,"end"))},arr:function(t,n,a){n.forEach(function(n){if(o.isString(n)||o.isNumber(n))e.value.call(i,t,n,a,"justSetValue");else for(var s in e)if(n[s]){e[s].call(i,t,n,a,"justSetValue");break}}),q.call(this,t,this.queue[t].options),b.call(this,t),p.call(this),o.selectRange(this.queue[t].$displayLabel,"end")},value:function(e,t,i,n){var a,s=this.queue[e],l=o.search(s.options,function(){return this[s.columnKeys.optionValue]==t});l>-1?s.options[l][s.columnKeys.optionSelected]=I(s,s.options[l][s.columnKeys.optionSelected],i):(l=s.options.length,a={"@index":l,hide:!0,addedOption:!0},a[s.columnKeys.optionValue]=t,a[s.columnKeys.optionText]=t,s.options.push(a),s.options[l][s.columnKeys.optionSelected]=I(s,s.options[l][s.columnKeys.optionSelected],i)),("undefined"==typeof n||"justSetValue"!==n)&&(q.call(this,e,this.queue[e].options),b.call(this,e),p.call(this),o.selectRange(this.queue[e].$displayLabel,"end"))},text:function(e,t,o,i){},clear:function(e){w.call(this,e),q.call(this,e,this.queue[e].options),m.call(this,e),g.call(this,e),this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.find("[data-option-index]").attr("data-option-Selected","false"),this.queue[e].optionSelectedIndex=-1}};return function(t,i,a,s){var l=o.isNumber(t)?t:S.call(this,t);if(-1===l)return void console.log(ax5.info.getError("ax5combobox","402","val"));if("undefined"==typeof i)return this.queue[l].selected;if(o.isArray(i))e.clear.call(this,l),e.arr.call(this,l,this.queue[l].multiple||0==i.length?i:[i[i.length-1]],a);else if(o.isString(i)||o.isNumber(i))"undefined"==typeof i||null===i||this.queue[l].multiple||w.call(this,l),e.value.call(this,l,i,a),b.call(this,l);else if(null===i)e.clear.call(this,l),b.call(this,l);else{this.queue[l].multiple||w.call(this,l);for(var c in e)if(i[c]){e[c].call(this,l,i,a);break}b.call(this,l)}return"undefined"!=typeof i&&n.call(this,this.queue[l],{self:this,item:this.queue[l],state:s?"changeValue":"setValue",value:this.queue[l].selected,internal:s}),t=null,this}}(),this.close=function(t){return this.closeTimer&&clearTimeout(this.closeTimer),this.activecomboboxOptionGroup?(t=this.queue[this.activecomboboxQueueIndex],t.optionFocusIndex=-1,t.$display.removeAttr("data-combobox-option-group-opened").trigger("focus"),this.activecomboboxOptionGroup.addClass("destroy"),jQuery(window).unbind("resize.ax5combobox-"+this.instanceId).unbind("click.ax5combobox-"+this.instanceId).unbind("keyup.ax5combobox-"+this.instanceId),this.closeTimer=setTimeout(function(){this.activecomboboxOptionGroup&&this.activecomboboxOptionGroup.remove(),this.activecomboboxOptionGroup=null,this.activecomboboxQueueIndex=-1,n.call(this,t,{self:this,state:"close"})}.bind(this),e.animateTime),this.waitOptionsCallback=null,this):this},this.enable=function(e){var t=S.call(this,e);return this.queue[t].$display.removeAttr("disabled"),this.queue[t].$input.removeAttr("disabled"),n.call(this,this.queue[t],{self:this,state:"enable"}),this},this.disable=function(e){var t=S.call(this,e);return this.queue[t].$display.attr("disabled","disabled"),this.queue[t].$input.attr("disabled","disabled"),n.call(this,this.queue[t],{self:this,state:"disable"}),this},this.main=function(){arguments&&o.isObject(arguments[0])?this.setConfig(arguments[0]):this.init()}.apply(this,arguments)};e.combobox=function(){return o.isFunction(t)&&(i.prototype=new t),i}()}(ax5.ui,ax5.ui.root),ax5.ui.combobox_instance=new ax5.ui.combobox,jQuery.fn.ax5combobox=function(){return function(e){if(ax5.util.isString(arguments[0])){var t=arguments[0];switch(t){case"open":return ax5.ui.combobox_instance.open(this);case"close":return ax5.ui.combobox_instance.close(this);case"setValue":return ax5.ui.combobox_instance.val(this,arguments[1],arguments[2]);case"getValue":return ax5.ui.combobox_instance.val(this);case"enable":return ax5.ui.combobox_instance.enable(this);case"disable":return ax5.ui.combobox_instance.disable(this);default:return this}}else"undefined"==typeof e&&(e={}),jQuery.each(this,function(){var t={target:this};e=jQuery.extend({},e,t),ax5.ui.combobox_instance.bind(e)});return this}}(); |
{ | ||
"name": "ax5ui-combobox", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"description": "A combobox plugin that works with Bootstrap & jQuery", | ||
@@ -5,0 +5,0 @@ "license": "LGPLv3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251600
2954