|
2 | 2 | * @summary SelectPage |
3 | 3 | * @desc Simple and powerful selection plugin |
4 | 4 | * @file selectpage.js |
5 | | - * @version 2.12 |
| 5 | + * @version 2.14 |
6 | 6 | * @author TerryZeng |
7 | 7 | * @contact https://terryz.github.io/ |
8 | 8 | * @license MIT License |
|
37 | 37 | * @type boolean 默认值 true |
38 | 38 | */ |
39 | 39 | pagination: true, |
| 40 | + /** |
| 41 | + * 是否显示下拉按钮 |
| 42 | + * @type boolean 默认 true |
| 43 | + */ |
| 44 | + dropButton: true, |
40 | 45 | /** |
41 | 46 | * @desc 关闭分页的状态下,列表显示的项目个数,其它的项目以滚动条滚动方式展现 |
42 | 47 | * @type number 默认值 10 |
|
116 | 121 | * @return string |
117 | 122 | */ |
118 | 123 | formatItem : undefined, |
119 | | - /** |
120 | | - * 是否在输入框获得焦点时,展开下拉窗口 |
121 | | - * @type boolean 默认值true |
122 | | - */ |
123 | | - focusDropList : true, |
124 | 124 | /** |
125 | 125 | * 是否自动选择列表中的第一项内容(输入关键字查询模式,直接使用鼠标下拉并不触发) |
126 | 126 | * @type boolean 默认值false |
|
216 | 216 | /** |
217 | 217 | * Plugin version number |
218 | 218 | */ |
219 | | - SelectPage.version = '2.12'; |
| 219 | + SelectPage.version = '2.14'; |
220 | 220 | /** |
221 | 221 | * Plugin object cache key |
222 | 222 | */ |
|
227 | 227 | */ |
228 | 228 | SelectPage.prototype.setOption = function(option) { |
229 | 229 | //若没有设置搜索字段,则使用显示字段作为搜索字段 |
230 | | - option.searchField = (option.searchField === undefined) ? option.showField: option.searchField; |
| 230 | + option.searchField = option.searchField || option.showField; |
231 | 231 |
|
232 | 232 | //统一大写 |
233 | 233 | option.andOr = option.andOr.toUpperCase(); |
|
240 | 240 | } |
241 | 241 |
|
242 | 242 | //设置排序字段 |
243 | | - option.orderBy = (option.orderBy === undefined) ? option.searchField: option.orderBy; |
| 243 | + option.orderBy = option.orderBy|| option.searchField; |
244 | 244 |
|
245 | 245 | //设置多字段排序 |
246 | 246 | //例: [ ['id', 'ASC'], ['name', 'DESC'] ] |
|
494 | 494 | btn_on: 'sp_btn_on', |
495 | 495 | btn_out: 'sp_btn_out', |
496 | 496 | input: 'sp_input', |
497 | | - clear_btn : 'sp_clear_btn' |
| 497 | + clear_btn : 'sp_clear_btn', |
| 498 | + align_right : 'sp_align_right' |
498 | 499 | }; |
499 | 500 | this.css_class = css_class; |
500 | 501 | }; |
|
526 | 527 | }; |
527 | 528 | this.template = { |
528 | 529 | tag : { |
529 | | - content : '<li class="selected_tag" itemvalue="#item_value#">#item_text#<span class="tag_close">×</span></li>', |
| 530 | + content : '<li class="selected_tag" itemvalue="#item_value#">#item_text#<span class="tag_close"><i class="iconfont if-close"></i></span></li>', |
530 | 531 | textKey : '#item_text#', |
531 | 532 | valueKey : '#item_value#' |
532 | 533 | } |
|
558 | 559 | //bootstrap风格的向下三角箭头 |
559 | 560 | elem.dropdown = $('<span class="bs-caret"><span class="caret"></span></span>'); |
560 | 561 | //单选模式下清除的按钮X |
561 | | - elem.clear_btn = $('<div>').append('×').addClass(css.clear_btn).attr('title','清除内容'); |
| 562 | + elem.clear_btn = $('<div>').html($('<i>').addClass('iconfont if-close')).addClass(css.clear_btn).attr('title','清除内容'); |
| 563 | + if(!p.dropButton) elem.clear_btn.addClass(css.align_right); |
562 | 564 |
|
563 | 565 | //多选模式下带标签显示及文本输入的组合框 |
564 | 566 | elem.element_box = $('<ul>').addClass(css.element_box); |
|
575 | 577 | */ |
576 | 578 | var namePrefix = '_text', |
577 | 579 | //将keyField的值放入"input:hidden" |
578 | | - input_id = (elem.combo_input.attr('id') !== undefined) ? elem.combo_input.attr('id') : elem.combo_input.attr('name'), |
579 | | - input_name = (elem.combo_input.attr('name') !== undefined) ? elem.combo_input.attr('name') : 'selectPage', |
| 580 | + input_id = elem.combo_input.attr('id') || elem.combo_input.attr('name'), |
| 581 | + input_name = elem.combo_input.attr('name') || 'selectPage', |
580 | 582 | hidden_name = input_name, |
581 | 583 | hidden_id = input_id; |
582 | 584 |
|
|
591 | 593 | }); |
592 | 594 |
|
593 | 595 | // 2. DOM element put |
594 | | - elem.container.append(elem.button).append(elem.hidden); |
| 596 | + elem.container.append(elem.hidden); |
| 597 | + if(p.dropButton){ |
| 598 | + elem.container.append(elem.button) |
| 599 | + elem.button.append(elem.dropdown); |
| 600 | + } |
595 | 601 | $(document.body).append(elem.result_area); |
596 | | - elem.button.append(elem.dropdown); |
597 | 602 | elem.result_area.append(elem.results); |
598 | 603 | if(p.pagination) elem.result_area.append(elem.navi); |
599 | 604 |
|
|
637 | 642 | } |
638 | 643 | */ |
639 | 644 | //this.elem.button.attr('title', this.message.get_all_btn); |
640 | | - this.elem.button.attr('title', this.message.close_btn); |
| 645 | + if(this.option.dropButton) |
| 646 | + this.elem.button.attr('title', this.message.close_btn); |
641 | 647 | }; |
642 | 648 |
|
643 | 649 | /** |
|
742 | 748 | */ |
743 | 749 | SelectPage.prototype.eDropdownButton = function() { |
744 | 750 | var self = this; |
745 | | - self.elem.button.mouseup(function(ev) { |
746 | | - ev.stopPropagation(); |
747 | | - if (self.elem.result_area.is(':hidden') && !self.elem.combo_input.prop('disabled')) { |
748 | | - self.elem.combo_input.focus(); |
749 | | - } else self.hideResults(self); |
750 | | - }).mouseout(); |
| 751 | + if(self.option.dropButton){ |
| 752 | + self.elem.button.mouseup(function(ev) { |
| 753 | + ev.stopPropagation(); |
| 754 | + if (self.elem.result_area.is(':hidden') && !self.elem.combo_input.prop('disabled')) { |
| 755 | + self.elem.combo_input.focus(); |
| 756 | + } else self.hideResults(self); |
| 757 | + }); |
| 758 | + } |
751 | 759 | }; |
752 | 760 |
|
753 | 761 | /** |
|
825 | 833 | }; |
826 | 834 |
|
827 | 835 | //Out of plugin area |
828 | | - $(document).off('mousedown.selectPage').on('mousedown.selectPage',function(e) { |
| 836 | + $(document.body).off('mousedown.selectPage').on('mousedown.selectPage',function(e) { |
829 | 837 | var ele = e.target || e.srcElement; |
830 | 838 | var sp = $(ele).closest('div.' + css.container); |
831 | | - |
832 | 839 | //Open status result list |
833 | 840 | $('div.' + css.container + '.' + css.container_open).each(function(){ |
834 | 841 | if(this == sp[0]) return; |
|
1172 | 1179 |
|
1173 | 1180 | self.abortAjax(self); |
1174 | 1181 | //self.setLoading(self); |
1175 | | - var which_page_num = self.prop.current_page > 0 ? self.prop.current_page : 1; |
| 1182 | + var which_page_num = self.prop.current_page || 1; |
1176 | 1183 |
|
1177 | 1184 | // 数据查询 |
1178 | 1185 | if (typeof self.option.data == 'object') self.searchForJson(self, q_word, which_page_num); |
|
1228 | 1235 | self.ajaxErrorNotify(self, errorThrown); |
1229 | 1236 | return; |
1230 | 1237 | } |
1231 | | - var data = p.eAjaxSuccess(returnData), json = {}; |
1232 | | - json.originalResult = data.list; |
1233 | | - json.cnt_whole = data.totalRow; |
| 1238 | + var data = {}, json = {}; |
| 1239 | + try{ |
| 1240 | + data = p.eAjaxSuccess(returnData); |
| 1241 | + json.originalResult = data.list; |
| 1242 | + json.cnt_whole = data.totalRow; |
| 1243 | + }catch(e){ |
| 1244 | + self.showMessage(self, self.message.ajax_error); |
| 1245 | + return; |
| 1246 | + } |
1234 | 1247 |
|
1235 | 1248 | json.candidate = []; |
1236 | 1249 | json.keyField = []; |
|
0 commit comments