-
Notifications
You must be signed in to change notification settings - Fork 49
/
selectmenu.min.js
1 lines (1 loc) · 26.1 KB
/
selectmenu.min.js
1
(function(f){var i;i=function(k){function j(){}j.generate=function(){var l=j._getRandomInt,m=j._hexAligner;return m(l(32),8)+"-"+m(l(16),4)+"-"+m(16384|l(12),4)+"-"+m(32768|l(14),4)+"-"+m(l(48),12)};j._getRandomInt=function(l){if(0>l||53<l){return NaN}var m=0|1073741824*Math.random();return 30<l?m+1073741824*(0|Math.random()*(1<<l-30)):m>>>30-l};j._hexAligner=function(l,p){for(var m=l.toString(16),o=p-m.length,n="0";0<o;o>>>=1,n+=n){o&1&&(m=n+m)}return m};j.overwrittenUUID=k;"undefined"!==typeof module&&module&&module.exports&&(module.exports=j);return j}(i);var e={data:undefined,search:true,title:"SelectMenu",regular:false,rightClick:false,arrow:false,position:"left",embed:false,lang:"cn",multiple:false,listSize:10,maxSelectLimit:0,selectToCloseList:false,initSelected:undefined,keyField:"id",showField:"name",searchField:undefined,andOr:"AND",orderBy:undefined,pageSize:100,formatItem:undefined,eSelect:undefined,eTabSwitch:undefined,eHidden:undefined};var a=function(j,k){this.target=j;this.setOption(k);if(this.option.embed&&!f(j).is("div")){console.warn('SelectMenu embed mode need a "div" container element!');return}this.setLanguage();this.setCssClass();this.setProp();if(k.regular){this.setRegularMenu()}else{this.setElem()}if(!k.rightClick){this.populate()}this.eInput();if(!k.embed){this.eWhole()}this.atLast()};a.version="2.1";a.dataKey="selectMenuObject";a.dataTypeList="SelectMenuList";a.dataTypeGroup="SelectMenuGroup";a.dataTypeMenu="SelectMenuMenu";a.prototype.setOption=function(j){j.searchField=j.searchField||j.showField;if(j.regular&&j.title===e.title){j.title=false}if(j.embed||j.rightClick){j.arrow=false}j.andOr=j.andOr.toUpperCase();if(j.andOr!=="AND"&&j.andOr!=="OR"){j.andOr="AND"}j.orderBy=(j.orderBy===undefined)?j.showField:j.orderBy;j.orderBy=this.setOrderbyOption(j.orderBy,j.showField);if(f.type(j.data)==="string"){j.autoSelectFirst=false}if(f.type(j.listSize)!=="number"||j.listSize<0){j.listSize=12}this.option=j};a.prototype.setOrderbyOption=function(k,n){var j=[],m=[];if(typeof k=="object"){for(var l=0;l<k.length;l++){m=f.trim(k[l]).split(" ");j[l]=(m.length==2)?m:[m[0],"ASC"]}}else{m=f.trim(k).split(" ");j[0]=(m.length==2)?m:(m[0].match(/^(ASC|DESC)$/i))?[n,m[0]]:[m[0],"ASC"]}return j};a.prototype.setLanguage=function(){var j;switch(this.option.lang){case"cn":j={select_all_btn:"选择所有 (或当前页签) 项目",remove_all_btn:"清除所有选中的项目",close_btn:"关闭菜单 (Esc键)",loading:"读取中...",select_ng:"请注意:请从列表中选择.",select_ok:"OK : 已经选择.",not_found:"无查询结果",ajax_error:"连接到服务器时发生错误!",max_selected:"最多只能选择 max_selected_limit 个项目"};break;case"en":j={select_all_btn:"Select All (Tabs) items",remove_all_btn:"Clear all selected items",close_btn:"Close Menu (Esc key)",loading:"loading...",select_ng:"Attention : Please choose from among the list.",select_ok:"OK : Correctly selected.",not_found:"not found",ajax_error:"An error occurred while connecting to server.",max_selected:"You can only select up to max_selected_limit items"};break;case"ja":j={select_all_btn:"すべての (または現在のタブ) 項目を選択",remove_all_btn:"選択したすべての項目をクリアする",close_btn:"閉じる (Tabキー)",loading:"読み込み中...",select_ng:"注意 : リストの中から選択してください",select_ok:"OK : 正しく選択されました。",not_found:"(0 件)",ajax_error:"サーバとの通信でエラーが発生しました。",max_selected:"最多で max_selected_limit のプロジェクトを選ぶことしかできません"};break;case"de":j={select_all_btn:"Wählen Sie alle (oder aktuellen Registerkarten) aus",remove_all_btn:"Alle ausgewählten Elemente löschen",close_btn:"Schließen (Tab)",loading:"lade...",select_ng:"Achtung: Bitte wählen Sie aus der Liste aus.",select_ok:"OK : Richtig ausgewählt.",not_found:"nicht gefunden",ajax_error:"Bei der Verbindung zum Server ist ein Fehler aufgetreten.",max_selected:"Sie können nur bis zu max_selected_limit Elemente auswählen"};break;case"es":j={select_all_btn:"Seleccionar todos los elementos (o la pestaña actual)",remove_all_btn:"Borrar todos los elementos seleccionados",close_btn:"Cerrar (tecla TAB)",loading:"Cargando...",select_ng:"Atencion: Elija una opcion de la lista.",select_ok:"OK: Correctamente seleccionado.",not_found:"no encuentre",ajax_error:"Un error ocurrió mientras conectando al servidor.",max_selected:"Solo puedes seleccionar hasta max_selected_limit elementos"};break;case"pt-br":j={select_all_btn:"Selecione todos os itens (ou guia atual)",remove_all_btn:"Limpe todos os itens selecionados",close_btn:"Fechar (tecla TAB)",loading:"Carregando...",select_ng:"Atenção: Escolha uma opção da lista.",select_ok:"OK: Selecionado Corretamente.",not_found:"não encontrado",ajax_error:"Um erro aconteceu enquanto conectando a servidor.",max_selected:"Você só pode selecionar até max_selected_limit itens"};break}this.message=j};a.prototype.setCssClass=function(){var j={target_clicked:"sm_target_clicked",container:"sm_container",container_open:"sm_container_open",container_embed:"sm_embed",header:"sm_header",re_area:"sm_result_area",re_tabs:"sm_result_tabs",re_list:"sm_list_mode",control_box:"sm_control_box",two_btn:"sm_two_btn",element_box:"sm_element_box",results:"sm_results",re_off:"sm_results_off",select:"sm_over",selected_icon:"sm_selected_icon",item_text:"sm_item_text",select_ok:"sm_select_ok",select_ng:"sm_select_ng",selected:"sm_selected",input_off:"sm_input_off",message_box:"sm_message_box",btn_close:"sm_close_button",btn_selectall:"sm_selectall_button",btn_removeall:"sm_removeall_button",btn_on:"sm_btn_on",btn_out:"sm_btn_out",btn_back:"sm_sub_back",input:"sm_input",input_area:"sm_input_area",clear_btn:"sm_clear_btn",menu_root:"sm_menu_root",menu_divider:"sm_divider",menu_regular:"sm_regular",menu_arrow:"sm_arrow",menu_arrow_have_title:"sm_have_title",menu_disabled:"sm_disabled",menu_header:"sm_header",menu_caret:"sm_caret",menu_sub_menu:"sm_sub_menu",menu_sub_item:"sm_sub_item",menu_sub_header:"sm_sub_header",direction_top:"sm_arrow_top",direction_bottom:"sm_arrow_bottom"};this.css_class=j;this.template={msg:{maxSelectLimit:"max_selected_limit"}}};a.prototype.setProp=function(){this.prop={values:[],data:undefined,data_index:0,key_select:false,prev_value:"",selected_text:"",last_input_time:undefined,data_type:a.dataTypeList,menu_tab_id_prefix:"selectmenu_tab_",menu_code_prefix:"selectmenu_",x:undefined,y:undefined}};a.prototype.checkDataType=function(m){var j=this,k=this.option;if(m&&f.isArray(m)&&m.length){if(k.regular){return a.dataTypeMenu}else{var l=m[0];if(l.hasOwnProperty("title")&&l.hasOwnProperty("list")&&f.isArray(l.list)){return a.dataTypeGroup}else{return a.dataTypeList}}}else{return null}};a.prototype.setElem=function(){var j=this,m=this.option,k=this.css_class;var l={};l.container=m.embed?f(j.target).addClass(k.container_embed):f("<div>");l.container.addClass(k.container).addClass(k.direction_bottom);if(m.title){l.header=f("<div>").addClass(k.header);l.header.append("<h3>"+m.title+"</h3>");if(m.multiple){l.selectAllButton=f('<button type="button"><i class="iconfont icon-selectall"></i></button>').attr("title",this.message.select_all_btn).addClass(k.btn_selectall);l.removeAllButton=f('<button type="button"><i class="iconfont icon-removeall"></i></button>').attr("title",this.message.remove_all_btn).addClass(k.btn_removeall);l.header.append(l.selectAllButton);l.header.append(l.removeAllButton)}if(!m.embed){l.closeButton=f('<button type="button">×</button>').attr("title",j.message.close_btn).addClass(k.btn_close);l.header.append(l.closeButton)}}l.inputArea=f("<div>").addClass(k.input_area);l.input=f('<input type="text" autocomplete="off">').addClass(k.input);l.resultArea=f("<div>").addClass(k.re_area);l.resultTabs=f("<div>").addClass(k.re_tabs);l.results=f("<ul>").addClass(k.results);l.selectedIcon=f('<i class="iconfont icon-selected">');if(m.arrow){l.arrow=f("<div>").addClass(k.menu_arrow);if(m.title){l.arrow.addClass(k.menu_arrow_have_title)}l.container.append(l.arrow)}if(m.title){l.container.append(l.header)}if(m.search){l.container.append(l.inputArea);l.inputArea.append(l.input)}l.container.append(l.resultTabs).append(l.resultArea);l.resultArea.append(l.results);if(!m.embed){f(document.body).append(l.container)}this.elem=l};a.prototype.setRegularMenu=function(){var m=this.option,j=this,k=this.css_class;var l={};l.container=m.embed?f(j.target).addClass(k.container_embed):f("<div>");l.container.addClass(k.container).addClass(k.direction_bottom).addClass(k.menu_regular);if(m.title){l.header=f("<div>").addClass(k.header);l.header.append("<h3>"+m.title+"</h3>");if(!m.embed){l.closeButton=f('<button type="button">×</button>').attr("title",j.message.close_btn).addClass(k.btn_close)}}l.resultArea=f("<div>").addClass(k.re_area);l.results=f("<ul>").addClass(k.results).addClass(k.menu_root);if(m.arrow){l.arrow=f("<div>").addClass(k.menu_arrow);if(m.title){l.arrow.addClass(k.menu_arrow_have_title)}l.container.append(l.arrow)}if(m.title){l.container.append(l.header);if(!m.embed){l.header.append(l.closeButton)}}l.container.append(l.resultArea);l.resultArea.append(l.results);if(!m.embed){f(document.body).append(l.container)}this.elem=l};a.prototype.regularMenuInit=function(){var q=this.prop.data,o=this.option,j=this,m=this.css_class,n=j.elem;var k=function(){if(!o.embed){this.calcResultsSize(this);n.container.addClass(m.container_open)}};if(n.results.find("li").size()&&!f.isFunction(o.data)){k.call(j);return}if(q&&f.isArray(q)&&q.length){var l=function(r,p){if(p.hasClass(m.menu_root)){p.empty().hide()}f.each(r,function(w,x){if(!x.content||(!x.header&&!x.url&&!x.callback&&!x.menus&&x.content!==m.menu_divider)){return true}var s=f("<li>");if(x.content===m.menu_divider){s.addClass(m.menu_divider)}else{var t=f("<a>").html(x.content).attr("href",(x.url&&!x.disabled)?x.url:"javascript:void(0);");if(x.callback&&f.isFunction(x.callback)&&!x.url){t.on("click.selectMenu",function(A){A.stopPropagation();if(x.disabled){return}x.callback();j.hideResults(j)})}if(x.menus&&f.isArray(x.menus)&&x.menus.length){var z=j.prop.menu_code_prefix+i.generate();t.attr({"href":"javascript:void(0);","item_code":z}).append(f("<span>").addClass(m.menu_caret)).addClass(m.menu_sub_item);var u=f("<ul>").attr("id",z).addClass(m.results).addClass(m.menu_sub_menu);var v=f('<button type="button">').addClass(m.btn_back).append('<i class="iconfont icon-back"></i>');var y=f("<li>").append(v).append(f("<p>").html(x.content)).addClass(m.menu_sub_header);u.append(y).append(f("<li>").addClass(m.menu_divider));n.resultArea.append(u);l(x.menus,u)}s.prepend(t);if(x.disabled){s.addClass(m.menu_disabled)}if(x.header){s.addClass(m.menu_header)}}p.append(s)});if(!p.hasClass(m.menu_sub_menu)){p.show()}};n.resultArea.find("ul."+m.results+":not(."+m.menu_root+")").remove();l(q,n.results);n.resultArea.find("a."+m.menu_sub_item).off("click.SelectMenu").on("click.SelectMenu",function(s){s.preventDefault();s.stopPropagation();var r=f(this),p=r.closest("ul."+m.results),t=f("#"+r.attr("item_code"));if(t.size()){p.hide();t.addClass("vivify fadeInRight").show()}});n.resultArea.find("button."+m.btn_back).off("click.SelectMenu").on("click.SelectMenu",function(t){var s=f(this),r=s.closest("ul"),p=f('a[item_code="'+r.attr("id")+'"]').closest("ul");r.hide();p.addClass("vivify fadeInLeft").show()});k.call(j)}};a.prototype.showMenu=function(j){j.populate();if(f(j.target).is("button")){f(j.target).addClass(j.css_class.target_clicked)}};a.prototype.setInitSelected=function(k,l){var m=k.option;if(f.type(m.initSelected)!=="undefined"&&!m.regular&&l&&f.isArray(l)&&l.length){var n=String(m.initSelected),j=n.split(",");var o=function(p){f.each(p,function(q,r){var s=String(r[m.keyField]);if(s&&f.inArray(s,j)!==-1){k.prop.values.push(r)}})};if(k.prop.data_type===a.dataTypeList){o(l)}else{if(k.prop.data_type===a.dataTypeGroup){f.each(l,function(p,q){q&&q.list&&q.list.length&&o(q.list)})}}m.initSelected=undefined}};a.prototype.eInput=function(){var j=this,l=this.option,k=j.elem;if(!l.regular&&l.search){k.input.keyup(function(m){j.processKey(j,m)}).keydown(function(m){j.processControl(j,m)})}if(l.title){if(!l.embed){k.closeButton.click(function(m){j.hideResults(j)})}if(!l.regular){if(l.multiple){k.selectAllButton.click(function(m){m.stopPropagation();j.selectAllLine(j)});k.removeAllButton.click(function(m){m.stopPropagation();j.clearAll(j)})}}}if(!l.regular&&j.prop.data_type===a.dataTypeGroup){k.resultTabs.off("click.selectMenu").on("click.selectMenu","a",function(o){o.stopPropagation();if(!f(this).hasClass("active")){var m=f(this).closest("li");m.siblings().children("a").removeClass("active");f(this).addClass("active");j.prop.data_index=parseInt(f(this).attr("data_index"));j.populate();if(l.eTabSwitch&&f.isFunction(l.eTabSwitch)){var n=f.extend({},j.prop.data[j.prop.data_index]);delete n.list;l.eTabSwitch.call(this,j.prop.data_index,n)}}})}if(l.rightClick){f(j.target).on("contextmenu",function(n){n.preventDefault();n.stopPropagation();n.cancelBubble=true;n.returnValue=false;var o=document.documentElement.scrollLeft||document.body.scrollLeft,m=document.documentElement.scrollTop||document.body.scrollTop;j.prop.x=n.pageX||n.clientX+o;j.prop.y=n.pageY||n.clientY+m;if(!j.isVisible(j)){j.populate()}else{j.calcResultsSize(j)}return false}).mouseup(function(m){if(m.button!=2){j.hideResults(j)}});j.hideResults(j)}};a.prototype.eWhole=function(){var j=this,k=this.css_class;f(document).off("mouseup.selectMenu").on("mouseup.selectMenu",function(m){var l=m.target||m.srcElement,n=f(l).closest("div."+k.container);f("div."+k.container+"."+k.container_open).each(function(){var o=f(this).data(a.dataKey);if(this==n[0]||o.target==l||f(l).closest(o.target).size()){return}o.hideResults(o)})})};a.prototype.eResultList=function(){var j=this,l=this.option,k=j.elem;j.elem.results.children("li").mouseenter(function(){if(j.prop.key_select){j.prop.key_select=false;return}if(!f(this).hasClass("sm_message_box")){f(this).addClass(j.css_class.select)}}).mouseleave(function(){f(this).removeClass(j.css_class.select)}).click(function(m){if(j.prop.key_select){j.prop.key_select=false;return}m.preventDefault();m.stopPropagation();j.selectCurrentLine(j,false)})};a.prototype.eScroll=function(){var j=this,k=this.css_class;f(window).on("scroll.SelectMenu",function(l){f("div."+k.container+"."+k.container_open).each(function(){var s=f(this).data(a.dataKey),r=s.elem.container.offset(),p=f(window).scrollTop(),u=f(document).height(),n=f(window).height(),m=s.elem.container.outerHeight(),q=r.top+m,o=u>n,t=s.elem.container.hasClass(k.direction_bottom);if(o){if(t){if(q>(n+p)){s.calcResultsSize(s)}}else{if(r.top<p){s.calcResultsSize(s)}}}})})};a.prototype.atLast=function(j){if(!j){j=this}var k=j.option;if(k.search&&!k.regular&&!k.embed&&!k.rightClick){j.elem.input.focus()}j.elem.container.data(a.dataKey,j);if(f(j.target).is("button,.btn")&&!k.embed&&!k.rightClick){f(j.target).addClass(j.css_class.target_clicked)}};a.prototype.ajaxErrorNotify=function(j,k){j.showMessage(j.message.ajax_error)};a.prototype.showMessage=function(j,l){if(!l){return}var k='<li class="sm_message_box"><i class="iconfont icon-warn"></i> '+l+"</li>";j.elem.results.empty().append(k);j.calcResultsSize(j);j.elem.container.addClass(j.css_class.container_open);j.elem.control.hide()};a.prototype.checkValue=function(k){var j=k.elem.input.val();if(j!=k.prop.prev_value){k.prop.prev_value=j;k.suggest(k)}};a.prototype.processKey=function(j,k){if(f.inArray(k.keyCode,[38,40,27,9,13])===-1){if(f.type(j.option.data)==="string"){j.prop.last_input_time=k.timeStamp;setTimeout(function(){if((k.timeStamp-j.prop.last_input_time)===0){j.checkValue(j)}},j.option.inputDelay*1000)}else{j.checkValue(j)}}};a.prototype.processControl=function(j,k){if((f.inArray(k.keyCode,[38,40,27,9])>-1&&j.elem.container.is(":visible"))||(f.inArray(k.keyCode,[13,9])>-1&&j.getCurrentLine(j))){k.preventDefault();k.stopPropagation();k.cancelBubble=true;k.returnValue=false;switch(k.keyCode){case 38:j.prop.key_select=true;j.prevLine(j);break;case 40:if(j.elem.results.children("li").length){j.prop.key_select=true;j.nextLine(j)}else{j.suggest(j)}break;case 9:j.selectCurrentLine(j,true);break;case 13:j.selectCurrentLine(j,true);break;case 27:j.hideResults(j);break}}};a.prototype.populate=function(){var j=this,k=this.option;if(!k.regular){j.elem.input.val("")}if(k.data){if(f.type(k.data)==="array"){j.prop.data=k.data}else{if(f.type(k.data)==="function"){j.prop.data=k.data()}}}if(f.type(j.prop.data)==="array"){this.prop.data_type=this.checkDataType(j.prop.data)}if(f.type(k.data)!=="string"){j.setInitSelected(j,j.prop.data)}if(k.regular){j.regularMenuInit()}else{j.suggest(j)}if(!k.embed){j.eScroll()}};a.prototype.suggest=function(j){var k,l=j.option,m=f.trim(j.elem.input.val());if(l.multiple){k=m}else{if(m&&m===j.prop.selected_text){k=""}else{k=m}}k=k.split(/[\s ]+/);j.setLoading(j);if(f.type(l.data)==="array"||f.type(l.data)==="function"){j.search(j,k)}};a.prototype.setLoading=function(j){if(j.elem.results.html()===""){if(!j.option.embed){j.elem.container.addClass(j.css_class.container_open)}}};a.prototype.search=function(u,n){var v=u.option,x=u.prop.data,r=[],m=[],k=[],D={},z=0,t=[];do{m[z]=n[z].replace(/\W/g,"\\$&").toString();t[z]=new RegExp(m[z],"gi");z++}while(z<n.length);var F=[];if(u.prop.data_index>(x.length-1)||u.prop.data_index<0){u.prop.data_index=0}if(u.prop.data_type===a.dataTypeGroup){F=x[u.prop.data_index].list}else{F=x}for(z=0;z<F.length;z++){var y=false;var o=F[z];for(var w=0;w<t.length;w++){var q=o[v.searchField];if(v.formatItem&&f.isFunction(v.formatItem)){q=v.formatItem(o)}if(q.match(t[w])){y=true;if(v.andOr=="OR"){break}}else{y=false;if(v.andOr=="AND"){break}}}if(y){r.push(o)}}var G=new RegExp("^"+m[0]+"$","gi"),E=new RegExp("^"+m[0],"gi"),C=[],B=[],A=[];for(z=0;z<r.length;z++){var s=v.orderBy[0][0],l=String(r[z][s]);if(l.match(G)){C.push(r[z])}else{if(l.match(E)){B.push(r[z])}else{A.push(r[z])}}}if(v.orderBy[0][1].match(/^asc$/i)){C=u.sortAsc(u,C);B=u.sortAsc(u,B);A=u.sortAsc(u,A)}else{C=u.sortDesc(u,C);B=u.sortDesc(u,B);A=u.sortDesc(u,A)}k=k.concat(C).concat(B).concat(A);D.originalResult=[];if(D.keyField===undefined){D.keyField=[]}if(D.candidate===undefined){D.candidate=[]}f.each(k,function(j,p){if(p===undefined||f.type(p)!=="object"){return true}D.originalResult.push(p);if(p.hasOwnProperty(v.keyField)&&p.hasOwnProperty(v.showField)){D.keyField.push(p[v.keyField]);D.candidate.push(p[v.showField])}});u.prepareResults(u,D,n)};a.prototype.sortAsc=function(k,j){j.sort(function(n,l){var o=n[k.option.orderBy[0][0]],m=l[k.option.orderBy[0][0]];return f.type(o)==="number"?o-m:String(o).localeCompare(String(m))});return j};a.prototype.sortDesc=function(k,j){j.sort(function(n,l){var o=n[k.option.orderBy[0][0]],m=l[k.option.orderBy[0][0]];return f.type(o)==="number"?m-o:String(m).localeCompare(String(o))});return j};a.prototype.notFoundSearch=function(j){j.elem.results.empty();j.calcResultsSize(j);j.elem.container.addClass(j.css_class.container_open);j.setCssFocusedInput(j)};a.prototype.prepareResults=function(k,l,m){if(!l.keyField){l.keyField=false}if(k.option.selectOnly&&l.candidate.length===1&&l.candidate[0]==m[0]){k.elem.hidden.val(l.keyField[0]);this.setButtonAttrDefault()}var j=false;if(m&&m.length&&m[0]){j=true}k.displayResults(k,l,j)};a.prototype.displayResults=function(t,A,z){var v=t.option,k=t.elem,o=t.css_class;k.results.hide().empty();if(t.prop.data_type===a.dataTypeGroup){var s=f("<ul>");f.each(t.prop.data,function(E,F){var D=f('<a href="javascript:void(0);">').html(F.title).attr({"tab_id":t.prop.menu_tab_id_prefix+(E+1),"data_index":E});if(E===t.prop.data_index){D.addClass("active")}var p=f("<li>").append(D);s.append(p)});k.resultTabs.empty().append(s)}else{k.resultTabs.hide();if(v.title||v.search){k.resultArea.addClass(this.css_class.re_list)}}if(v.multiple&&f.type(v.maxSelectLimit)==="number"&&v.maxSelectLimit){var w=t.prop.results.length;if(w&&w>=v.maxSelectLimit){var l=t.message.max_selected;t.showMessage(t,l.replace(t.template.msg.maxSelectLimit,v.maxSelectLimit));return}}if(A.candidate.length){var y=A.candidate,u=A.keyField;for(var x=0;x<y.length;x++){var n="",j=false,m=A.originalResult[x];if(v.formatItem&&f.isFunction(v.formatItem)){try{n=v.formatItem(m);j=true}catch(C){console.error("formatItem 内容格式化函数内容设置不正确!");n=y[x]}}else{n=y[x]}var B=f("<div>").html('<i class="iconfont icon-selected">').addClass(o.selected_icon),r=f("<div>").html(n).addClass(o.item_text),q=f("<li>").append(B).append(r).attr("pkey",u[x]);if(!j){q.attr("title",n)}if(f.inArray(m,t.prop.values)!==-1){q.addClass(o.selected)}q.data("dataObj",m);k.results.append(q)}}else{var q='<li class="sm_message_box"><i class="iconfont icon-warn"></i> '+t.message.not_found+"</li>";k.results.append(q)}k.results.show();t.calcResultsSize(t);if(!v.embed){k.container.addClass(o.container_open)}t.eResultList();t.atLast(t)};a.prototype.calcResultsSize=function(m){var r=m.option,o=m.elem,n=m.css_class,q=function(){return f(document).height()>f(window).height()};var j=function(){if(!r.regular){var s=o.results.find("li:first").outerHeight(),p=s*r.listSize;o.results.css({"max-height":p})}};var l=q();var k=function(){var p=o.container.outerHeight(),v=f(window).scrollTop(),s=f(window).height();if(r.rightClick){var y=m.prop.y;if((m.prop.y+p)>(v+s)){y=m.prop.y-p}return{top:y,left:m.prop.x}}var A=f(m.target).offset(),B=A.top,w=o.container.outerWidth(),z=Math.round(f(m.target)[0].getBoundingClientRect().width),x=5;B+=f(m.target).outerHeight()+x;if(r.arrow&&!r.embed){B+=o.arrow.outerHeight(true)}if((B+p)>(v+s)){B=A.top-x-p;if(r.arrow&&!r.embed){B-=o.arrow.outerHeight(true)}o.container.removeClass(n.direction_bottom).addClass(n.direction_top)}else{if(o.container.hasClass(n.direction_top)){o.container.removeClass(n.direction_top).addClass(n.direction_bottom)}}var u=A.left;switch(r.position){case"right":u=u+z-w;if(r.arrow){o.arrow.css("left",w-(z/2))}break;case"center":u=u+(z/2)-(w/2);break;case"left":default:if(r.arrow){o.arrow.css("left",z/2)}break}return{top:B,left:u}};if(o.container.is(":visible")){j();if(!r.embed){o.container.offset(k())}}else{o.container.show(1,function(){j();f(this).offset(k())})}if(l!==q()){o.container.offset(k())}};a.prototype.subMenuPosition=function(n,o){var m=f(n).offset();var k=m.top,j=m.left+f(n).outerWidth()+5};a.prototype.hideResults=function(j){var k=j.option;if(k.autoFillResult){}if(!k.regular){j.elem.results.empty()}if(!k.embed){j.elem.container.removeClass(j.css_class.container_open).hide();if(f(j.target).is("button,.btn")){f(j.target).removeClass(j.css_class.target_clicked)}}j.elem.resultArea.find("ul."+j.css_class.results).not("."+j.css_class.menu_root).hide();j.elem.results.removeClass("vivify").removeClass("fadeInLeft").show();f(window).off("scroll.SelectMenu");if(!k.regular&&k.eHidden&&f.isFunction(k.eHidden)){k.eHidden.call(j,j.prop.values.concat())}};a.prototype.afterAction=function(j){if(j.option.multiple){if(j.option.selectToCloseList){j.hideResults(j);j.elem.input.blur()}else{j.elem.input.focus()}}else{j.hideResults(j);j.elem.input.blur()}};a.prototype.getCurrentLine=function(j){if(j.elem.container.is(":hidden")){return false}var k=j.elem.results.find("li."+j.css_class.select);if(k.size()){return k}else{return false}};a.prototype.getSelectedLine=function(j){if(j.elem.container.is(":hidden")){return false}var k=j.elem.results.find("li."+j.css_class.selected);if(k.size()){return k}else{return false}};a.prototype.selectCurrentLine=function(j,k){var n=j.getCurrentLine(j),m=j.option;if(n){var l=n.data("dataObj"),o=String(l[m.keyField]);if(f.inArray(l,j.prop.values)===-1){if(!m.multiple){j.prop.values.splice(0,j.prop.values.length)}j.prop.values.push(l);if(!m.multiple){j.elem.results.find("li."+j.css_class.selected).removeClass(j.css_class.selected)}n.addClass(j.css_class.selected)}else{j.prop.values.splice(f.inArray(l,j.prop.values),1);n.removeClass(j.css_class.selected)}if(m.eSelect&&f.isFunction(m.eSelect)){if(m.multiple){m.eSelect.call(j,j.prop.values.concat())}else{m.eSelect.call(j,[l])}}j.prop.prev_value=j.elem.input.val();j.prop.selected_text=j.elem.input.val()}if(!m.embed){j.afterAction(j)}};a.prototype.selectAllLine=function(j){j.elem.results.find("li").each(function(k,m){var l=f(m).data("dataObj");if(f.inArray(l,j.prop.values)===-1){j.prop.values.push(l)}f(this).addClass(j.css_class.selected)});if(j.option.eSelect&&f.isFunction(j.option.eSelect)){j.option.eSelect.call(j,j.prop.values.concat())}j.afterAction(j)};a.prototype.clearAll=function(j){var l=j.option,k=j.elem;k.input.val("");k.results.find("li").each(function(m,n){f(this).removeClass(j.css_class.selected)});j.prop.values.splice(0,j.prop.values.length);j.afterAction(j);if(l.eSelect&&f.isFunction(l.eSelect)){l.eSelect.call(j,[])}};a.prototype.nextLine=function(s){var o=s.getCurrentLine(s),k=s.elem,r;if(!o){r=-1}else{r=k.results.children("li").index(o);o.removeClass(s.css_class.select)}r++;var t=k.results.find("li").size();if(r===t){r=t-1}if(r<t){var p=k.results.children("li").eq(r);p.addClass(s.css_class.select);var n=k.results.find("li:first").outerHeight(),m=p.position().top,j=k.resultArea.scrollTop(),l=k.resultArea.outerHeight(),q=m+n-l;if((m+n)>l){k.resultArea.scrollTop(j+q)}}};a.prototype.prevLine=function(r){var k=r.elem,q,p=r.getCurrentLine(r);if(!p){q=k.results.children("li").length}else{q=k.results.children("li").index(p);p.removeClass(r.css_class.select)}q--;if(q<0){q=0}if(q>-1){var o=k.results.children("li").eq(q),n=k.results.find("li:first").outerHeight(),m=o.position().top,j=k.resultArea.scrollTop(),l=k.resultArea.outerHeight();o.addClass(r.css_class.select);if((m>(j+l))||(m<j)){k.resultArea.scrollTop(j-(0-m))}}};a.prototype.isVisible=function(j){return j.elem.container.hasClass(j.css_class.container_open)};function h(j){return this.each(function(){var l=f(this),k=l.data(a.dataKey),m=f.extend({},e,l.data(),k&&k.option,typeof j==="object"&&j);if(!k){l.data(a.dataKey,(k=new a(this,m)))}else{if(k.isVisible(k)){k.hideResults(k)}else{k.showMenu(k)}}})}function g(){return this.each(function(){var k=f(this),j=k.data(a.dataKey);if(j){j.hideResults(j)}})}function b(){return this.each(function(){var k=f(this),j=k.data(a.dataKey);if(j){j.clearAll(j)}})}function d(){var j=new Array();this.each(function(){var l=f(this),k=l.data(a.dataKey);if(k){j=k.prop.values.concat()}});return j}var c=f.fn.selectMenu;f.fn.selectMenu=h;f.fn.selectMenu.Constructor=a;f.fn.selectMenuHide=g;f.fn.selectMenuClear=b;f.fn.selectMenuValues=d;f.fn.selectMenu.noConflict=function(){f.fn.selectMenu=c;return this}})(window.jQuery);