selectpage.min.js 31 KB

1
  1. !function(e){"use strict";function t(t){return e(t).closest("div.sp_container").find("input.sp_input")}var a={data:void 0,lang:"cn",multiple:!1,pagination:!0,dropButton:!0,listSize:10,multipleControlbar:!0,maxSelectLimit:0,selectToCloseList:!1,initRecord:void 0,dbTable:"tbl",keyField:"id",showField:"name",searchField:void 0,andOr:"OR",separator:",",orderBy:void 0,pageSize:10,params:void 0,formatItem:void 0,autoFillResult:!1,autoSelectFirst:!1,noResultClean:!0,selectOnly:!1,inputDelay:.5,eSelect:void 0,eOpen:void 0,eAjaxSuccess:void 0,eTagRemove:void 0,eClear:void 0},o=function(t,a){e.each({data:"source",keyField:"primaryKey",showField:"field",pageSize:"perPage"},function(e,t){void 0!==a[t]&&(a[e]=a[t],delete a[t])}),this.setOption(a),this.setLanguage(),this.setCssClass(),this.setProp(),this.setElem(t),this.setButtonAttrDefault(),this.setInitRecord(),this.eDropdownButton(),this.eInput(),this.eWhole()};o.version="2.19",o.dataKey="selectPageObject",o.prototype.setOption=function(t){t.searchField=t.searchField||t.showField,t.andOr=t.andOr.toUpperCase(),"AND"!==t.andOr&&"OR"!==t.andOr&&(t.andOr="AND");for(var a=["searchField"],o=0;o<a.length;o++)t[a[o]]=this.strToArray(t[a[o]]);if(t.orderBy=t.orderBy||t.showField,!1!==t.orderBy&&(t.orderBy=this.setOrderbyOption(t.orderBy,t.showField)),t.multiple&&!t.selectToCloseList&&(t.autoFillResult=!1,t.autoSelectFirst=!1),t.pagination||(t.pageSize=200),("number"!==e.type(t.listSize)||t.listSize<0)&&(t.listSize=10),"string"==typeof t.formatItem){var n=t.formatItem;t.formatItem=function(e){return"function"==typeof Template&&n.match(/\#([a-zA-Z0-9_\-]+)$/)?Template(n.substring(1),e):n.replace(/\{(.*?)\}/gi,function(t){return t=t.substring(1,t.length-1),void 0!==e[t]?e[t]:""})}}this.option=t},o.prototype.strToArray=function(e){return e?e.replace(/[\s ]+/g,"").split(","):""},o.prototype.setOrderbyOption=function(t,a){var o=[],n=[];if("object"==typeof t)for(var i=0;i<t.length;i++)(n=e.trim(t[i]).split(" ")).length&&o.push(2===n.length?n.concat():[n[0],"ASC"]);else n=e.trim(t).split(" "),o[0]=2===n.length?n.concat():n[0].toUpperCase().match(/^(ASC|DESC)$/i)?[a,n[0].toUpperCase()]:[n[0],"ASC"];return o},o.prototype.setLanguage=function(){var e,t=this.option;switch(t.lang){case"en":e={add_btn:"Add button",add_title:"add a box",del_btn:"Del button",del_title:"delete a box",next:"Next",next_title:"Next"+t.pageSize+" (Right key)",prev:"Prev",prev_title:"Prev"+t.pageSize+" (Left key)",first_title:"First (Shift + Left key)",last_title:"Last (Shift + Right key)",get_all_btn:"Get All (Down key)",get_all_alt:"(button)",close_btn:"Close (Tab key)",close_alt:"(button)",loading:"loading...",loading_alt:"(loading)",page_info:"page_num of page_count",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.",clear:"Clear content",select_all:"Select current page",unselect_all:"Clear current page",clear_all:"Clear all selected",max_selected:"You can only select up to max_selected_limit items"};break;case"cn":default:e={add_btn:"添加按钮",add_title:"添加区域",del_btn:"删除按钮",del_title:"删除区域",next:"下一页",next_title:"下"+t.pageSize+" (→)",prev:"上一页",prev_title:"上"+t.pageSize+" (←)",first_title:"首页 (Shift + ←)",last_title:"尾页 (Shift + →)",get_all_btn:"获得全部 (↓)",get_all_alt:"(按钮)",close_btn:"关闭 (Tab键)",close_alt:"(按钮)",loading:"读取中...",loading_alt:"(读取中)",page_info:"第 page_num 页(共page_count页)",select_ng:"请注意:请从列表中选择.",select_ok:"OK : 已经选择.",not_found:"无查询结果",ajax_error:"连接到服务器时发生错误!",clear:"清除内容",select_all:"选择当前页项目",unselect_all:"取消选择当前页项目",clear_all:"清除全部已选择项目",max_selected:"最多只能选择 max_selected_limit 个项目"}}this.message=e},o.prototype.setCssClass=function(){var e={container:"sp_container",container_open:"sp_container_open",re_area:"sp_result_area",result_open:"sp_result_area_open",control_box:"sp_control_box",element_box:"sp_element_box",navi:"sp_navi",results:"sp_results",re_off:"sp_results_off",select:"sp_over",select_ok:"sp_select_ok",select_ng:"sp_select_ng",selected:"sp_selected",input_off:"sp_input_off",message_box:"sp_message_box",disabled:"sp_disabled",button:"sp_button",caret_open:"sp_caret_open",btn_on:"sp_btn_on",btn_out:"sp_btn_out",input:"sp_input",clear_btn:"sp_clear_btn",align_right:"sp_align_right"};this.css_class=e},o.prototype.setProp=function(){this.prop={disabled:!1,current_page:1,max_page:1,is_loading:!1,xhr:!1,key_paging:!1,key_select:!1,prev_value:"",selected_text:"",last_input_time:void 0,init_set:!1},this.template={tag:{content:'<li class="selected_tag" itemvalue="#item_value#">#item_text#<span class="tag_close"><i class="spfont sp-close"></i></span></li>',textKey:"#item_text#",valueKey:"#item_value#"},page:{current:"page_num",total:"page_count"},msg:{maxSelectLimit:"max_selected_limit"}}},o.prototype.elementRealSize=function(t,a){var o,n,i={absolute:!1,clone:!1,includeMargin:!1,display:"block"},l=t.eq(0),s=[],r="";o=function(){n.each(function(t){var a=e(this),o=s[t];void 0===o?a.removeAttr("style"):a.attr("style",o)})},function(){n=l.parents().addBack().filter(":hidden"),r+="visibility: hidden !important; display: "+i.display+" !important; ",!0===i.absolute&&(r+="position: absolute !important;"),n.each(function(){var t=e(this),a=t.attr("style");s.push(a),t.attr("style",a?a+";"+r:r)})}();var p=/(outer)/.test(a)?l[a](i.includeMargin):l[a]();return o(),p},o.prototype.setElem=function(t){var a={},o=this.option,n=this.css_class,i=this.message,l=e(t),s=l.css("width"),r=l.outerWidth();s.indexOf("%")>-1||l.parent().size()>0&&l.parent().width()==r?r="100%":(r<=0&&(r=this.elementRealSize(l,"outerWidth")),r<150&&(r=150)),a.combo_input=l.attr({autocomplete:"off"}).addClass(n.input).wrap("<div>"),o.selectOnly&&a.combo_input.prop("readonly",!0),a.container=a.combo_input.parent().addClass(n.container),a.combo_input.prop("disabled")&&(o.multiple?a.container.addClass(n.disabled):a.combo_input.addClass(n.input_off)),a.container.width(r),a.button=e("<div>").addClass(n.button),a.dropdown=e('<span class="sp_caret"></span>'),a.clear_btn=e("<div>").html(e("<i>").addClass("spfont sp-close")).addClass(n.clear_btn).attr("title",i.clear),o.dropButton||a.clear_btn.addClass(n.align_right),a.element_box=e("<ul>").addClass(n.element_box),o.multiple&&o.multipleControlbar&&(a.control=e("<div>").addClass(n.control_box)),a.result_area=e("<div>").addClass(n.re_area),o.pagination&&(a.navi=e("<div>").addClass("sp_pagination").append("<ul>")),a.results=e("<ul>").addClass(n.results);var p=a.combo_input.attr("id")||a.combo_input.attr("name"),c=a.combo_input.attr("name")||"selectPage",u=c,d=p;if(a.hidden=e('<input type="hidden" class="sp_hidden" />').attr({name:u,id:d}).val(""),a.combo_input.attr({name:void 0!==l.data("name")?l.data("name"):c+"_text",id:p+"_text"}),a.hidden.attr("data-rule",a.combo_input.data("rule")||""),a.combo_input.attr("novalidate","novalidate"),a.container.append(a.hidden),o.dropButton&&(a.container.append(a.button),a.button.append(a.dropdown)),e(document.body).append(a.result_area),a.result_area.append(a.results),o.pagination&&a.result_area.append(a.navi),o.multiple){o.multipleControlbar&&(a.control.append('<button type="button" class="btn btn-default sp_clear_all" ><i class="spfont sp-clear"></i></button>'),a.control.append('<button type="button" class="btn btn-default sp_unselect_all" ><i class="spfont sp-unselect-all"></i></button>'),a.control.append('<button type="button" class="btn btn-default sp_select_all" ><i class="spfont sp-select-all"></i></button>'),a.control_text=e("<p>"),a.control.append(a.control_text),a.result_area.prepend(a.control)),a.container.addClass("sp_container_combo"),a.combo_input.addClass("sp_combo_input").before(a.element_box);var m=e("<li>").addClass("input_box");m.append(a.combo_input),a.element_box.append(m),a.combo_input.attr("placeholder")&&a.combo_input.attr("placeholder_bak",a.combo_input.attr("placeholder"))}this.elem=a},o.prototype.setButtonAttrDefault=function(){this.option.dropButton&&this.elem.button.attr("title",this.message.close_btn)},o.prototype.setInitRecord=function(t){var a=this,o=a.option,n=a.elem,i="";if("undefined"!=e.type(n.combo_input.data("init"))&&(o.initRecord=String(n.combo_input.data("init"))),t||o.initRecord||!n.combo_input.val()||(o.initRecord=n.combo_input.val()),n.combo_input.val(""),t||n.hidden.val(o.initRecord),i=t&&n.hidden.val()?n.hidden.val():o.initRecord)if("object"==typeof o.data){var l=new Array,s=i.split(",");e.each(s,function(e,t){for(var a=0;a<o.data.length;a++)if(o.data[a][o.keyField]==t){l.push(o.data[a]);break}}),!o.multiple&&l.length>1&&(l=[l[0]]),a.afterInit(a,l)}else{var r=o.params,p={},c=(o.searchField,{searchTable:o.dbTable,searchKey:o.keyField,searchValue:i,orderBy:o.orderBy,showField:o.showField,keyField:o.keyField,keyValue:i,searchField:o.searchField});if(r){var u=e.isFunction(r)?r(a):r;p=u&&e.isPlainObject(u)?e.extend({},c,u):c}else p=c;e.ajax({dataType:"json",type:"POST",url:o.data,data:p,success:function(t){var n=null;o.eAjaxSuccess&&e.isFunction(o.eAjaxSuccess)&&(n=o.eAjaxSuccess(t)),a.afterInit(a,n.list)},error:function(e,t,o){a.ajaxErrorNotify(a,o)}})}},o.prototype.afterInit=function(t,a){if(a&&(!e.isArray(a)||0!==a.length)){e.isArray(a)||(a=[a]);var o=t.option,n=t.css_class;if(t.data=a,o.multiple)t.prop.init_set=!0,t.clearAll(t),e.each(a,function(e,a){var n=a[o.keyField],i={text:a[o.showField],value:n};t.isAlreadySelected(t,i)||t.addNewTag(t,a,i)}),t.tagValuesSet(t),t.inputResize(t),t.elem.hidden.blur(),t.prop.init_set=!1;else{var i=a[0],l=i[o.keyField],s=i[o.showField];t.elem.combo_input.val(s),t.elem.hidden.val(l),t.prop.prev_value=s,t.prop.selected_text=s,o.selectOnly&&t.elem.combo_input.attr("title",t.message.select_ok).removeClass(n.select_ng).addClass(n.select_ok),t.putClearButton()}}},o.prototype.eDropdownButton=function(){var e=this;e.option.dropButton&&e.elem.button.mouseup(function(t){t.stopPropagation(),e.elem.result_area.is(":hidden")&&!e.elem.combo_input.prop("disabled")?e.elem.combo_input.focus():e.hideResults(e)})},o.prototype.eInput=function(){var t=this,a=t.option,o=t.elem,n=t.message,i=function(){t.prop.page_move=!1,t.suggest(t),t.setCssFocusedInput(t)};o.combo_input.keyup(function(e){t.processKey(t,e)}).keydown(function(e){t.processControl(t,e)}).focus(function(e){o.result_area.is(":hidden")&&(e.stopPropagation(),t.prop.first_show=!0,i())}),o.container.on("click.SelectPage","div."+t.css_class.clear_btn,function(o){o.stopPropagation(),t.disabled(t)||(t.clearAll(t,!0),t.elem.hidden.change(),a.eClear&&e.isFunction(a.eClear)&&a.eClear(t))}),o.result_area.on("mousedown.SelectPage",function(e){e.stopPropagation()}),a.multiple&&(a.multipleControlbar&&(o.control.find(".sp_select_all").on("click.SelectPage",function(e){t.selectAllLine(t)}).hover(function(){o.control_text.html(n.select_all)},function(){o.control_text.html("")}),o.control.find(".sp_unselect_all").on("click.SelectPage",function(e){t.unSelectAllLine(t)}).hover(function(){o.control_text.html(n.unselect_all)},function(){o.control_text.html("")}),o.control.find(".sp_clear_all").on("click.SelectPage",function(e){t.clearAll(t,!0)}).hover(function(){o.control_text.html(n.clear_all)},function(){o.control_text.html("")})),o.element_box.on("click.SelectPage",function(t){var a=t.target||t.srcElement;e(a).is("ul")&&o.combo_input.focus()}),o.element_box.on("click.SelectPage","span.tag_close",function(){var o=e(this).closest("li"),n=o.data("dataObj");t.removeTag(t,o),i(),a.eTagRemove&&e.isFunction(a.eTagRemove)&&a.eTagRemove([n])}),t.inputResize(t))},o.prototype.eWhole=function(){var t=this.css_class,a=function(e){e.elem.combo_input.val(""),e.option.multiple||e.elem.hidden.val(""),e.prop.selected_text=""};e(document.body).off("mousedown.selectPage").on("mousedown.selectPage",function(n){var i=n.target||n.srcElement,l=e(i).closest("div."+t.container);e("div."+t.container+"."+t.container_open).each(function(){if(this!=l[0]){var n=e(this).find("input."+t.input).data(o.dataKey);if(!n.elem.combo_input.val()&&n.elem.hidden.val()&&!n.option.multiple)return n.prop.current_page=1,a(n),n.hideResults(n),!0;n.elem.results.find("li").not("."+t.message_box).length?n.option.autoFillResult?n.elem.hidden.val()?n.hideResults(n):n.elem.results.find("li.sp_over").length?n.selectCurrentLine(n,!0):n.option.autoSelectFirst?(n.nextLine(n),n.selectCurrentLine(n,!0)):n.hideResults(n):n.hideResults(n):(n.option.noResultClean?a(n):n.option.multiple||n.elem.hidden.val(""),n.hideResults(n))}})})},o.prototype.eResultList=function(){var t=this,a=this.css_class;t.elem.results.children("li").hover(function(){t.prop.key_select?t.prop.key_select=!1:e(this).hasClass(a.selected)||e(this).hasClass(a.message_box)||(e(this).addClass(a.select),t.setCssFocusedResults(t))},function(){e(this).removeClass(a.select)}).click(function(o){t.prop.key_select?t.prop.key_select=!1:(o.preventDefault(),o.stopPropagation(),e(this).hasClass(a.selected)||t.selectCurrentLine(t,!1))})},o.prototype.eScroll=function(){var t=this.css_class;e(window).on("scroll.SelectPage",function(a){e("div."+t.container+"."+t.container_open).each(function(){var a=e(this).find("input."+t.input).data(o.dataKey),n=a.elem.result_area.offset(),i=e(window).scrollTop(),l=e(document).height(),s=e(window).height(),r=a.elem.result_area.outerHeight(),p=n.top+r,c=l>s,u=a.elem.result_area.hasClass("shadowDown");c&&(u?p>s+i&&a.calcResultsSize(a):n.top<i&&a.calcResultsSize(a))})})},o.prototype.ePaging=function(){var e=this;e.option.pagination&&(e.elem.navi.find("li.csFirstPage").off("click").on("click",function(t){t.preventDefault(),e.firstPage(e)}),e.elem.navi.find("li.csPreviousPage").off("click").on("click",function(t){t.preventDefault(),e.prevPage(e)}),e.elem.navi.find("li.csNextPage").off("click").on("click",function(t){t.preventDefault(),e.nextPage(e)}),e.elem.navi.find("li.csLastPage").off("click").on("click",function(t){t.preventDefault(),e.lastPage(e)}))},o.prototype.ajaxErrorNotify=function(e,t){e.showMessage(e.message.ajax_error)},o.prototype.showMessage=function(e,t){if(t){var a='<li class="'+e.css_class.message_box+'"><i class="spfont sp-warning"></i> '+t+"</li>";e.elem.results.empty().append(a).show(),e.calcResultsSize(e),e.setOpenStatus(e,!0),e.elem.control.hide(),e.option.pagination&&e.elem.navi.hide()}},o.prototype.scrollWindow=function(t,a){var o,n=t.getCurrentLine(t),i=n&&!a?n.offset().top:t.elem.container.offset().top;t.prop.size_li=t.elem.results.children("li:first").outerHeight(),o=t.prop.size_li;var l,s=e(window).height(),r=e(window).scrollTop(),p=r+s-o;if(n.length)if(i<r||o>s)l=i-r;else{if(!(i>p))return;l=i-p}else i<r&&(l=i-r);window.scrollBy(0,l)},o.prototype.setOpenStatus=function(e,t){var a=e.elem,o=e.css_class;t?(a.container.addClass(o.container_open),a.result_area.addClass(o.result_open)):(a.container.removeClass(o.container_open),a.result_area.removeClass(o.result_open))},o.prototype.setCssFocusedInput=function(e){},o.prototype.setCssFocusedResults=function(e){},o.prototype.checkValue=function(e){var t=e.elem.combo_input.val();t!=e.prop.prev_value&&(e.prop.prev_value=t,e.prop.first_show=!1,e.option.selectOnly&&e.setButtonAttrDefault(),e.option.multiple||t||(e.elem.combo_input.val(""),e.elem.hidden.val(""),e.elem.clear_btn.remove()),e.suggest(e))},o.prototype.processKey=function(t,a){-1===e.inArray(a.keyCode,[37,38,39,40,27,9,13])&&(16!=a.keyCode&&t.setCssFocusedInput(t),t.inputResize(t),"string"===e.type(t.option.data)?(t.prop.last_input_time=a.timeStamp,setTimeout(function(){a.timeStamp-t.prop.last_input_time==0&&t.checkValue(t)},1e3*t.option.inputDelay)):t.checkValue(t))},o.prototype.processControl=function(t,a){if(e.inArray(a.keyCode,[37,38,39,40,27,9])>-1&&t.elem.result_area.is(":visible")||e.inArray(a.keyCode,[13,9])>-1&&t.getCurrentLine(t))switch(a.preventDefault(),a.stopPropagation(),a.cancelBubble=!0,a.returnValue=!1,a.keyCode){case 37:a.shiftKey?t.firstPage(t):t.prevPage(t);break;case 38:t.prop.key_select=!0,t.prevLine(t);break;case 39:a.shiftKey?t.lastPage(t):t.nextPage(t);break;case 40:t.elem.results.children("li").length?(t.prop.key_select=!0,t.nextLine(t)):t.suggest(t);break;case 9:t.prop.key_paging=!0,t.selectCurrentLine(t,!0);break;case 13:t.selectCurrentLine(t,!0);break;case 27:t.prop.key_paging=!0,t.hideResults(t)}},o.prototype.abortAjax=function(e){e.prop.xhr&&(e.prop.xhr.abort(),e.prop.xhr=!1)},o.prototype.suggest=function(t){var a,o=e.trim(t.elem.combo_input.val());a=(a=t.option.multiple?o:o&&o===t.prop.selected_text?"":o).split(t.option.separator),t.option.eOpen&&e.isFunction(t.option.eOpen)&&t.option.eOpen.call(t),t.abortAjax(t);var n=t.prop.current_page||1;"object"==typeof t.option.data?t.searchForJson(t,a,n):t.searchForDb(t,a,n)},o.prototype.setLoading=function(e){""===e.elem.results.html()&&e.setOpenStatus(e,!0)},o.prototype.searchForDb=function(t,a,o){var n=t.option;n.eAjaxSuccess&&e.isFunction(n.eAjaxSuccess)||t.hideResults(t);var i=n.params,l={},s=n.searchField;a.length&&a[0]&&a.join(t.option.separator)!==t.prop.prev_value&&(o=1);var r={q_word:a,pageNumber:o,pageSize:n.pageSize,andOr:n.andOr,orderBy:n.orderBy,searchTable:n.dbTable,showField:t.option.showField,keyField:t.option.keyField,searchField:t.option.searchField};if(!1!==n.orderBy&&(r.orderBy=n.orderBy),r[s]=a[0],i){var p=e.isFunction(i)?i(t):i;l=p&&e.isPlainObject(p)?e.extend({},r,p):r}else l=r;t.prop.xhr=e.ajax({dataType:"json",url:n.data,type:"POST",data:l,success:function(i){if(!i||!e.isPlainObject(i))return t.hideResults(t),void t.ajaxErrorNotify(t,errorThrown);var l={},s={};try{l=n.eAjaxSuccess(i),s.originalResult=l.list,s.cnt_whole=l.totalRow}catch(e){return void t.showMessage(t,t.message.ajax_error)}if(t.elem.navi&&e(t.elem.navi).toggleClass("hide",s.cnt_whole<=s.originalResult.length),s.candidate=[],s.keyField=[],"object"!=typeof s.originalResult)return t.prop.xhr=null,void t.notFoundSearch(t);s.cnt_page=s.originalResult.length;for(var r=0;r<s.cnt_page;r++)for(var p in s.originalResult[r])p==n.keyField&&s.keyField.push(s.originalResult[r][p]),p==n.showField&&s.candidate.push(s.originalResult[r][p]);t.prepareResults(t,s,a,o)},error:function(e,a,o){"abort"!=a&&(t.hideResults(t),t.ajaxErrorNotify(t,o))},complete:function(){t.prop.xhr=null}})},o.prototype.searchForJson=function(t,a,o){var n=t.option,i=[],l=[],s=[],r={},p=0,c=[];do{l[p]=a[p].replace(/\W/g,"\\$&").toString(),c[p]=new RegExp(l[p],"gi"),p++}while(p<a.length);for(p=0;p<n.data.length;p++){for(var u,d=!1,m=n.data[p],_=0;_<c.length;_++)if(u=m[n.searchField],n.formatItem&&e.isFunction(n.formatItem)&&(u=n.formatItem(m)),u.match(c[_])){if(d=!0,"OR"==n.andOr)break}else if(d=!1,"AND"==n.andOr)break;d&&i.push(m)}if(!1===n.orderBy)s=i.concat();else{for(var f=new RegExp("^"+l[0]+"$","gi"),h=new RegExp("^"+l[0],"gi"),g=[],v=[],y=[],p=0;p<i.length;p++){var b=n.orderBy[0][0],x=String(i[p][b]);x.match(f)?g.push(i[p]):x.match(h)?v.push(i[p]):y.push(i[p])}n.orderBy[0][1].match(/^asc$/i)?(g=t.sortAsc(t,g),v=t.sortAsc(t,v),y=t.sortAsc(t,y)):(g=t.sortDesc(t,g),v=t.sortDesc(t,v),y=t.sortDesc(t,y)),s=s.concat(g).concat(v).concat(y)}if(r.cnt_whole=s.length,t.prop.page_move)s.length<=(o-1)*n.pageSize&&(o=1,t.prop.current_page=1);else if(!n.multiple){var C=t.elem.hidden.val();if("undefined"!==e.type(C)&&""!==e.trim(C)){var S=0;e.each(s,function(e,t){if(t[n.keyField]==C)return S=e+1,!1}),(o=Math.ceil(S/n.pageSize))<1&&(o=1),t.prop.current_page=o}}var w=(o-1)*n.pageSize,k=w+n.pageSize;r.originalResult=[];for(p=w;p<k&&void 0!==s[p];p++){r.originalResult.push(s[p]);for(var F in s[p])F==n.keyField&&(void 0===r.keyField&&(r.keyField=[]),r.keyField.push(s[p][F])),F==n.showField&&(void 0===r.candidate&&(r.candidate=[]),r.candidate.push(s[p][F]))}void 0===r.candidate&&(r.candidate=[]),r.cnt_page=r.candidate.length,t.prepareResults(t,r,a,o)},o.prototype.sortAsc=function(t,a){return a.sort(function(a,o){var n=a[t.option.orderBy[0][0]],i=o[t.option.orderBy[0][0]];return"number"===e.type(n)?n-i:String(n).localeCompare(String(i))}),a},o.prototype.sortDesc=function(t,a){return a.sort(function(a,o){var n=a[t.option.orderBy[0][0]],i=o[t.option.orderBy[0][0]];return"number"===e.type(n)?i-n:String(i).localeCompare(String(n))}),a},o.prototype.notFoundSearch=function(e){e.elem.results.empty(),e.calcResultsSize(e),e.setOpenStatus(e,!0),e.setCssFocusedInput(e)},o.prototype.prepareResults=function(e,t,a,o){e.data=t.originalResult,e.option.pagination&&e.setNavi(e,t.cnt_whole,t.cnt_page,o),t.keyField||(t.keyField=!1),e.option.selectOnly&&1===t.candidate.length&&t.candidate[0]==a[0]&&(e.elem.hidden.val(t.keyField[0]),this.setButtonAttrDefault());var n=!1;a&&a.length&&a[0]&&(n=!0),e.displayResults(e,t,n)},o.prototype.setNavi=function(e,t,a,o){var n=e.message,i=e.elem.navi.find("ul"),l=Math.ceil(t/e.option.pageSize);0===l?o=0:l<o?o=l:0===o&&(o=1),e.prop.current_page=o,e.prop.max_page=l,function(e,t,a,o){var i=function(){return n.page_info.replace(e.template.page.current,a).replace(e.template.page.total,o)};if(0===t.find("li").length){t.hide().empty();t.append('<li class="csFirstPage" title="'+n.first_title+'" ><a href="javascript:void(0);"> <i class="spfont sp-first"></i> </a></li>'),t.append('<li class="csPreviousPage" title="'+n.prev_title+'" ><a href="javascript:void(0);"><i class="spfont sp-previous"></i></a></li>'),t.append('<li class="pageInfoBox"><a href="javascript:void(0);"> '+i()+" </a></li>"),t.append('<li class="csNextPage" title="'+n.next_title+'" ><a href="javascript:void(0);"><i class="spfont sp-next"></i></a></li>'),t.append('<li class="csLastPage" title="'+n.last_title+'" ><a href="javascript:void(0);"> <i class="spfont sp-last"></i> </a></li>'),t.show()}else t.find("li.pageInfoBox a").html(i())}(e,i,o,l);var s="disabled",r=i.find("li.csFirstPage"),p=i.find("li.csPreviousPage"),c=i.find("li.csNextPage"),u=i.find("li.csLastPage");1===o||0===o?(r.hasClass(s)||r.addClass(s),p.hasClass(s)||p.addClass(s)):(r.hasClass(s)&&r.removeClass(s),p.hasClass(s)&&p.removeClass(s)),o===l||0===l?(c.hasClass(s)||c.addClass(s),u.hasClass(s)||u.addClass(s)):(c.hasClass(s)&&c.removeClass(s),u.hasClass(s)&&u.removeClass(s)),l>1&&e.ePaging()},o.prototype.displayResults=function(t,a,o){var n=t.option,i=t.elem;if(i.results.hide().empty(),n.multiple&&"number"===e.type(n.maxSelectLimit)&&n.maxSelectLimit>0){var l=i.element_box.find("li.selected_tag").length;if(l>0&&l>=n.maxSelectLimit){var s=t.message.max_selected;return void t.showMessage(t,s.replace(t.template.msg.maxSelectLimit,n.maxSelectLimit))}}if(a.candidate.length)for(var r=a.candidate,p=a.keyField,c=i.hidden.val(),u=c?c.split(","):new Array,d="",m=0;m<r.length;m++){if(n.formatItem&&e.isFunction(n.formatItem))try{d=n.formatItem(a.originalResult[m])}catch(e){console.error("formatItem内容格式化函数内容设置不正确!"),d=r[m]}else d=r[m];var _=e("<li>").html(d).attr({pkey:p[m],index:m});n.formatItem||_.attr("title",d),-1!==e.inArray(p[m].toString(),u)&&_.addClass(t.css_class.selected),_.data("dataObj",a.originalResult[m]),i.results.append(_)}else{var f='<li class="'+t.css_class.message_box+'"><i class="spfont sp-warning"></i> '+t.message.not_found+"</li>";i.results.append(f)}i.results.show(),n.multiple&&n.multipleControlbar&&i.control.show(),n.pagination&&i.navi.show(),t.calcResultsSize(t),t.setOpenStatus(t,!0),t.eResultList(),t.eScroll(),o&&a.candidate.length&&n.autoSelectFirst&&t.nextLine(t)},o.prototype.calcResultsSize=function(t){var a=t.option,o=t.elem,n=function(){if("static"!==o.container.css("position")){if(!a.pagination){p=o.results.find("li:first").outerHeight(!0)*a.listSize;o.results.css({"max-height":p,"overflow-y":"auto"})}var t=e(document).width(),n=e(document).height(),i=e(window).height(),l=o.container.offset(),s=e(window).scrollTop(),r=o.result_area.outerWidth(),p=o.result_area.outerHeight(),c=l.left,u=o.container.outerHeight(),d=l.left+r>t?c-(r-o.container.outerWidth()):c,m=l.top,_=0,f=m+u+p+5,h=m+p+5,g=n>i;return m-s-5>p&&g&&f>i+s||!g&&f>i&&m>=h?(_=l.top-p-5,o.result_area.removeClass("shadowUp shadowDown").addClass("shadowUp")):(_=l.top+(a.multiple?o.container.outerHeight():u),o.result_area.removeClass("shadowUp shadowDown").addClass("shadowDown"),_+=5),{top:_+"px",left:d+"px"}}l=o.combo_input.offset();o.result_area.css({top:l.top+o.combo_input.outerHeight()+"px",left:l.left+"px"})};if(o.result_area.is(":visible"))o.result_area.css(n());else{var i=n();o.result_area.css(i).show(1,function(){var e=n();i.top===e.top&&i.left===e.left||o.result_area.css(e)})}},o.prototype.hideResults=function(t){t.prop.key_paging&&(t.scrollWindow(t,!0),t.prop.key_paging=!1),t.setCssFocusedInput(t),t.option.autoFillResult,t.elem.results.empty(),t.elem.result_area.hide(),t.setOpenStatus(t,!1),e(window).off("scroll.SelectPage"),t.abortAjax(t),t.setButtonAttrDefault()},o.prototype.disabled=function(t,a){t.option;var o=t.elem;if("undefined"===e.type(a))return o.combo_input.prop("disabled");"boolean"===e.type(a)&&(o.combo_input.prop("disabled",a),a?o.container.addClass(t.css_class.disabled):o.container.removeClass(t.css_class.disabled))},o.prototype.firstPage=function(e){e.prop.current_page>1&&(e.prop.current_page=1,e.prop.page_move=!0,e.suggest(e))},o.prototype.prevPage=function(e){e.prop.current_page>1&&(e.prop.current_page--,e.prop.page_move=!0,e.suggest(e))},o.prototype.nextPage=function(e){e.prop.current_page<e.prop.max_page&&(e.prop.current_page++,e.prop.page_move=!0,e.suggest(e))},o.prototype.lastPage=function(e){e.prop.current_page<e.prop.max_page&&(e.prop.current_page=e.prop.max_page,e.prop.page_move=!0,e.suggest(e))},o.prototype.afterAction=function(e,t){e.inputResize(e),e.elem.combo_input.change(),e.setCssFocusedInput(e),e.prop.init_set||(e.option.multiple?(e.option.selectToCloseList&&(e.hideResults(e),e.elem.combo_input.blur()),!e.option.selectToCloseList&&t&&(e.suggest(e),e.elem.combo_input.focus())):(e.hideResults(e),e.elem.combo_input.blur()))},o.prototype.selectCurrentLine=function(t,a){t.scrollWindow(t,!0);var o=t.option,n=t.getCurrentLine(t);if(n){var i=n.data("dataObj"),l=i[o.showField]||n.text(),s=n.attr("pkey");if(o.multiple){t.elem.combo_input.val("");var r={text:l,value:s};t.isAlreadySelected(t,r)||(t.addNewTag(t,i,r),t.tagValuesSet(t))}else t.elem.combo_input.val(l),t.elem.hidden.val(s);o.selectOnly&&t.setButtonAttrDefault(),o.eSelect&&e.isFunction(o.eSelect)&&o.eSelect(i,t),t.prop.prev_value=t.elem.combo_input.val(),t.prop.selected_text=t.elem.combo_input.val(),t.putClearButton()}t.afterAction(t,!0)},o.prototype.putClearButton=function(){this.option.multiple||this.elem.combo_input.prop("disabled")||this.elem.container.append(this.elem.clear_btn)},o.prototype.selectAllLine=function(t){var a=t.option,o=new Array;t.elem.results.find("li").each(function(n,i){var l=e(i),s=l.data("dataObj"),r={text:s[a.showField]||l.text(),value:l.attr("pkey")};if(t.isAlreadySelected(t,r)||(t.addNewTag(t,s,r),t.tagValuesSet(t)),o.push(s),"number"===e.type(a.maxSelectLimit)&&a.maxSelectLimit>0&&a.maxSelectLimit===t.elem.element_box.find("li.selected_tag").length)return!1}),a.eSelect&&e.isFunction(a.eSelect)&&a.eSelect(o,t),t.afterAction(t,!0)},o.prototype.unSelectAllLine=function(t){var a=t.option,o=(t.elem.results.find("li").length,[]);t.elem.results.find("li").each(function(a,n){var i=e(n).attr("pkey"),l=t.elem.element_box.find('li.selected_tag[itemvalue="'+i+'"]');l.length&&o.push(l.data("dataObj")),t.removeTag(t,l)}),t.afterAction(t,!0),a.eTagRemove&&e.isFunction(a.eTagRemove)&&a.eTagRemove(o)},o.prototype.clearAll=function(t,a){var o=t.option,n=[];o.multiple&&(t.elem.element_box.find("li.selected_tag").each(function(t,a){n.push(e(a).data("dataObj")),a.remove()}),t.elem.element_box.find("li.selected_tag").remove()),t.reset(t),t.afterAction(t,a),o.multiple?o.eTagRemove&&e.isFunction(o.eTagRemove)&&o.eTagRemove(n):t.elem.clear_btn.remove()},o.prototype.reset=function(e){e.elem.combo_input.val(""),e.elem.hidden.val(""),e.prop.prev_value="",e.prop.selected_text="",e.prop.current_page=1},o.prototype.getCurrentLine=function(e){if(e.elem.result_area.is(":hidden"))return!1;var t=e.elem.results.find("li."+e.css_class.select);return!!t.length&&t},o.prototype.isAlreadySelected=function(t,a){var o=!1;if(a.value){var n=t.elem.hidden.val();if(n){var i=n.split(",");i&&i.length&&-1!=e.inArray(a.value,i)&&(o=!0)}}return o},o.prototype.addNewTag=function(t,a,o){if(t.option.multiple&&a&&o){var n,i=t.template.tag.content;i=(i=i.replace(t.template.tag.textKey,o.text)).replace(t.template.tag.valueKey,o.value),(n=e(i)).data("dataObj",a),t.elem.combo_input.prop("disabled")&&n.find("span.tag_close").hide(),t.elem.combo_input.closest("li").before(n)}},o.prototype.removeTag=function(t,a){var o=e(a).attr("itemvalue"),n=t.elem.hidden.val();if("undefined"!=e.type(o)&&n){var i=n.split(","),l=e.inArray(o.toString(),i);-1!=l&&(i.splice(l,1),t.elem.hidden.val(i.toString()).trigger("change"))}e(a).remove(),t.inputResize(t)},o.prototype.tagValuesSet=function(t){if(t.option.multiple){var a=t.elem.element_box.find("li.selected_tag");if(a&&a.length){var o=new Array;e.each(a,function(t,a){var n=e(a).attr("itemvalue");"undefined"!==e.type(n)&&o.push(n)}),o.length&&t.elem.hidden.val(o.join(",")).trigger("change")}}},o.prototype.inputResize=function(e){if(e.option.multiple){var t=e.elem.combo_input.closest("li");0===e.elem.element_box.find("li.selected_tag").length?(t.hasClass("full_width")||t.addClass("full_width"),e.elem.combo_input.attr("placeholder_bak")&&e.elem.combo_input.attr("placeholder",e.elem.combo_input.attr("placeholder_bak")).removeAttr("style")):function(e,t){t.removeClass("full_width");var a=.75*(e.elem.combo_input.val().length+1)+"em";e.elem.combo_input.css("width",a).removeAttr("placeholder")}(e,t)}},o.prototype.nextLine=function(e){var t,a=e.getCurrentLine(e);a?(t=e.elem.results.children("li").index(a),a.removeClass(e.css_class.select)):t=-1,++t<e.elem.results.children("li").length?(e.elem.results.children("li").eq(t).addClass(e.css_class.select),e.setCssFocusedResults(e)):e.setCssFocusedInput(e),e.scrollWindow(e,!1)},o.prototype.prevLine=function(e){var t,a=e.getCurrentLine(e);a?(t=e.elem.results.children("li").index(a),a.removeClass(e.css_class.select)):t=e.elem.results.children("li").length,--t>-1?(e.elem.results.children("li").eq(t).addClass(e.css_class.select),e.setCssFocusedResults(e)):e.setCssFocusedInput(e),e.scrollWindow(e,!1)};var n=e.fn.selectPage;e.fn.selectPage=function(t){return this.each(function(){var n=e(this),i=n.data(o.dataKey),l=e.extend({},a,n.data(),i&&i.option,"object"==typeof t&&t);i||n.data(o.dataKey,i=new o(this,l))})},e.fn.selectPage.Constructor=o,e.fn.selectPageClear=function(){return this.each(function(){var e=t(this).data(o.dataKey);e&&(e.prop.init_set=!0,e.clearAll(e),e.prop.init_set=!1)})},e.fn.selectPageRefresh=function(){return this.each(function(){var e=t(this).data(o.dataKey);e&&e.elem.hidden.val()&&e.setInitRecord(!0)})},e.fn.selectPageData=function(a){return this.each(function(){if(a&&e.isArray(a)){var n=t(this).data(o.dataKey);n&&(n.clearAll(n),n.option.data=a)}})},e.fn.selectPageDisabled=function(a){var n=!1;return this.each(function(){var i=t(this).data(o.dataKey);i&&("undefined"!==e.type(a)?i.disabled(i,a):n=i.disabled(i))}),n},e.fn.selectPageText=function(){var a="";return this.each(function(){var n=t(this).data(o.dataKey);if(n)if(n.option.multiple){var i=[];n.elem.element_box.find("li.selected_tag").each(function(t,a){i.push(e(a).text())}),a+=i.toString()}else a+=n.elem.combo_input.val()}),a},e.fn.selectPage.noConflict=function(){return e.fn.selectPage=n,this}}(window.jQuery);