From d5e41a538bacbaa4971efa3575fe15071aa62106 Mon Sep 17 00:00:00 2001 From: sampsonliu Date: Thu, 15 Aug 2019 20:30:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E6=8B=89=E6=A1=86=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E4=BE=9D=E8=B5=96=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selectpage.css | 2 +- selectpage.js | 1811 +++++++++++++++++++++++---------------------- selectpage.min.js | 10 +- 3 files changed, 922 insertions(+), 901 deletions(-) diff --git a/selectpage.css b/selectpage.css index 6c4e57e..308f299 100644 --- a/selectpage.css +++ b/selectpage.css @@ -136,7 +136,7 @@ div.sp_clear_btn.sp_align_right { margin: 0; padding: 0; position: absolute; - z-index: 100; + z-index: 1040; width: 300px; border-radius: 2px; } diff --git a/selectpage.js b/selectpage.js index 053b3df..1be8f82 100644 --- a/selectpage.js +++ b/selectpage.js @@ -17,7 +17,7 @@ /** * Data source * @type {string|Object} - * + * * string:server side request url address * Object:JSON array,format:[{a:1,b:2,c:3},{...}] */ @@ -25,54 +25,54 @@ /** * Language ('cn', 'en', 'ja', 'es', 'pt-br') * @type string - * @default 'cn' + * @default 'cn' */ lang: 'cn', /** - * Multiple select mode(tags) + * Multiple select mode(tags) * @type boolean - * @default false + * @default false */ multiple: false, - /** - * pagination or not - * @type boolean - * @default true - */ - pagination: true, - /** - * Show up menu button - * @type boolean - * @default true - */ - dropButton: true, - /** - * Result list visible size in pagination bar close - * @type number - * @default 10 - */ - listSize : 10, + /** + * pagination or not + * @type boolean + * @default true + */ + pagination: true, + /** + * Show up menu button + * @type boolean + * @default true + */ + dropButton: true, + /** + * Result list visible size in pagination bar close + * @type number + * @default 10 + */ + listSize : 10, /** * Show control bar in multiple select mode * @type boolean - * @default true + * @default true */ multipleControlbar: true, /** - * Max selected item limited in multiple select mode + * Max selected item limited in multiple select mode * @type number - * @default 0(unlimited) + * @default 0(unlimited) */ maxSelectLimit: 0, /** * Select result item to close list, work on multiple select mode * @type boolean - * @default false + * @default false */ selectToCloseList: false, /** - * Init selected item key, the result will match to option.keyField option - * @type string + * Init selected item key, the result will match to option.keyField option + * @type string */ initRecord: undefined, /** @@ -81,72 +81,72 @@ */ dbTable: 'tbl', /** - * The value field, the value will fill to hidden element + * The value field, the value will fill to hidden element * @type string - * @default 'id' + * @default 'id' */ keyField: 'id', /** - * The show text field, the text will show to input element or tags(multiple mode) + * The show text field, the text will show to input element or tags(multiple mode) * @type string - * @default 'name' + * @default 'name' */ showField: 'name', /** - * Actually used to search field + * Actually used to search field * @type string */ searchField : undefined, /** * Search type ('AND' or 'OR') * @type string - * @default 'AND' + * @default 'AND' */ andOr: 'AND', - /** - * Result sort type - * @type array|boolean - * @example - * orderBy : ['id desc'] - */ - orderBy: false, + /** + * Result sort type + * @type array|boolean + * @example + * orderBy : ['id desc'] + */ + orderBy: false, /** * Page size * @type number - * @default 10 + * @default 10 */ pageSize: 10, /** - * Server side request parameters + * Server side request parameters * @type function * @return object * @example params : function(){return {'name':'aa','sex':1};} */ params : undefined, /** - * Custom result list item show text + * Custom result list item show text * @type function * @param data {object} row data * @return string */ formatItem : undefined, - /** - * Have some highlight item and lost focus, auto select the highlight item - * @type boolean - * @default false - */ - autoFillResult: false, /** - * Auto select first item in show up result list or search result - * depend on `autoFillResult` option set to true + * Have some highlight item and lost focus, auto select the highlight item + * @type boolean + * @default false + */ + autoFillResult: false, + /** + * Auto select first item in show up result list or search result + * depend on `autoFillResult` option set to true * @type boolean - * @default false + * @default false */ autoSelectFirst: false, /** - * Whether clear input element text when enter some keywords to search and no result return + * Whether clear input element text when enter some keywords to search and no result return * @type boolean - * @default true + * @default true */ noResultClean: true, /** @@ -154,34 +154,34 @@ * @type boolean */ selectOnly: false, - /** - * Input to search delay time, work on ajax data source - * @type number - * @default 0.5 - */ - inputDelay: 0.5, + /** + * Input to search delay time, work on ajax data source + * @type number + * @default 0.5 + */ + inputDelay: 0.5, /** * -----------------------------------------Callback-------------------------------------------- */ /** * Result list item selected callback - * @type function + * @type function * @param object - selected item json data * @param self - plugin object */ eSelect : undefined, - /** - * Before result list show up callback, you can do anything prepared - * @param self - plugin object - */ - eOpen : undefined, /** - * Server side return data convert callback + * Before result list show up callback, you can do anything prepared + * @param self - plugin object + */ + eOpen : undefined, + /** + * Server side return data convert callback * @type function * @param data {object} server side return data - * @param self {object} plugin object + * @param self {object} plugin object * @return {object} return data format: - * @example + * @example * { * list : [{name:'aa',sex:1},{name:'bb',sex:1}...], * totalRow : 100 @@ -189,23 +189,23 @@ */ eAjaxSuccess : undefined, /** - * Close selected item tag callback (multiple mode) + * Close selected item tag callback (multiple mode) * @type function * @param removeCount {number} remove item count - * @param self {object} plugin object + * @param self {object} plugin object */ eTagRemove : undefined, - /** - * Clear selected item callback(single select mode) - * @type function - * @param self {object} plugin object - */ - eClear : undefined + /** + * Clear selected item callback(single select mode) + * @type function + * @param self {object} plugin object + */ + eClear : undefined }; /** - * SelectPage class definition + * SelectPage class definition * @constructor * @param {Object} input - input element * @param {Object} option @@ -239,7 +239,7 @@ SelectPage.prototype.setOption = function(option) { //use showField to default option.searchField = option.searchField || option.showField; - + option.andOr = option.andOr.toUpperCase(); if(option.andOr!=='AND' && option.andOr!=='OR') option.andOr = 'AND'; @@ -252,13 +252,13 @@ //set multiple order field //example: [ ['id ASC'], ['name DESC'] ] if(option.orderBy !== false) option.orderBy = this.setOrderbyOption(option.orderBy, option.showField); - //close auto fill result and auto select first in multiple mode and select item not close list + //close auto fill result and auto select first in multiple mode and select item not close list if(option.multiple && !option.selectToCloseList){ option.autoFillResult = false; option.autoSelectFirst = false; } - //show all item when pagination bar close, limited 200 - if(!option.pagination) option.pageSize = 200; + //show all item when pagination bar close, limited 200 + if(!option.pagination) option.pageSize = 200; if($.type(option.listSize) !== 'number' || option.listSize < 0) option.listSize = 10; this.option = option; @@ -284,7 +284,8 @@ if (typeof arg_order === 'object') { for (var i = 0; i < arg_order.length; i++) { orders = $.trim(arg_order[i]).split(' '); - if(orders.length) arr.push((orders.length === 2) ? orders.concat(): [orders[0], 'ASC']); + if(orders.length) + arr.push((orders.length === 2) ? orders.concat(): [orders[0], 'ASC']); } } else { orders = $.trim(arg_order).split(' '); @@ -299,197 +300,197 @@ SelectPage.prototype.setLanguage = function() { var message, p = this.option; switch (p.lang) { - // German - case 'de': - message = { - add_btn: 'Hinzufügen-Button', - add_title: 'Box hinzufügen', - del_btn: 'Löschen-Button', - del_title: 'Box löschen', - next: 'Nächsten', - next_title: 'Nächsten' + p.pageSize + ' (Pfeil-rechts)', - prev: 'Vorherigen', - prev_title: 'Vorherigen' + p.pageSize + ' (Pfeil-links)', - first_title: 'Ersten (Umschalt + Pfeil-links)', - last_title: 'Letzten (Umschalt + Pfeil-rechts)', - get_all_btn: 'alle (Pfeil-runter)', - get_all_alt: '(Button)', - close_btn: 'Schließen (Tab)', - close_alt: '(Button)', - loading: 'lade...', - loading_alt: '(lade)', - page_info: 'page_num von page_count', - 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.', - clear: 'Löschen Sie den Inhalt', - select_all: 'Wähle diese Seite', - unselect_all: 'Diese Seite entfernen', - clear_all: 'Alles löschen', - max_selected: 'Sie können nur bis zu max_selected_limit Elemente auswählen' - }; - break; - - // English - case 'en': - message = { - add_btn: 'Add button', - add_title: 'add a box', - del_btn: 'Del button', - del_title: 'delete a box', - next: 'Next', - next_title: 'Next' + p.pageSize + ' (Right key)', - prev: 'Prev', - prev_title: 'Prev' + p.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 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; - - // Spanish - case 'es': - message = { - add_btn: 'Agregar boton', - add_title: 'Agregar una opcion', - del_btn: 'Borrar boton', - del_title: 'Borrar una opcion', - next: 'Siguiente', - next_title: 'Proximas ' + p.pageSize + ' (tecla derecha)', - prev: 'Anterior', - prev_title: 'Anteriores ' + p.pageSize + ' (tecla izquierda)', - first_title: 'Primera (Shift + Left)', - last_title: 'Ultima (Shift + Right)', - get_all_btn: 'Ver todos (tecla abajo)', - get_all_alt: '(boton)', - close_btn: 'Cerrar (tecla TAB)', - close_alt: '(boton)', - loading: 'Cargando...', - loading_alt: '(Cargando)', - page_info: 'page_num de page_count', - 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.', - clear: 'Borrar el contenido', - select_all: 'Elija esta página', - unselect_all: 'Borrar esta página', - clear_all: 'Borrar todo marcado', - max_selected: 'Solo puedes seleccionar hasta max_selected_limit elementos' - }; - break; - - // Brazilian Portuguese - case 'pt-br': - message = { - add_btn: 'Adicionar botão', - add_title: 'Adicionar uma caixa', - del_btn: 'Apagar botão', - del_title: 'Apagar uma caixa', - next: 'Próxima', - next_title: 'Próxima ' + p.pageSize + ' (tecla direita)', - prev: 'Anterior', - prev_title: 'Anterior ' + p.pageSize + ' (tecla esquerda)', - first_title: 'Primeira (Shift + Left)', - last_title: 'Última (Shift + Right)', - get_all_btn: 'Ver todos (Seta para baixo)', - get_all_alt: '(botão)', - close_btn: 'Fechar (tecla TAB)', - close_alt: '(botão)', - loading: 'Carregando...', - loading_alt: '(Carregando)', - page_info: 'page_num de page_count', - 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.', - clear: 'Limpe o conteúdo', - select_all: 'Selecione a página atual', - unselect_all: 'Remova a página atual', - clear_all: 'Limpar tudo', - max_selected: 'Você só pode selecionar até max_selected_limit itens' - }; - break; - - // Japanese - case 'ja': - message = { - add_btn: '追加ボタン', - add_title: '入力ボックスを追加します', - del_btn: '削除ボタン', - del_title: '入力ボックスを削除します', - next: '次へ', - next_title: '次の' + p.pageSize + '件 (右キー)', - prev: '前へ', - prev_title: '前の' + p.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: '(0 件)', - ajax_error: 'サーバとの通信でエラーが発生しました。', - clear: 'コンテンツをクリアする', - select_all: '当ページを選びます', - unselect_all: '移して当ページを割ります', - clear_all: '選択した項目をクリアする', - max_selected: '最多で max_selected_limit のプロジェクトを選ぶことしかできません' - }; - break; - // 中文 - case 'cn': - default: - message = { - add_btn: '添加按钮', - add_title: '添加区域', - del_btn: '删除按钮', - del_title: '删除区域', - next: '下一页', - next_title: '下' + p.pageSize + ' (→)', - prev: '上一页', - prev_title: '上' + p.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 个项目' - }; - break; + // German + case 'de': + message = { + add_btn: 'Hinzufügen-Button', + add_title: 'Box hinzufügen', + del_btn: 'Löschen-Button', + del_title: 'Box löschen', + next: 'Nächsten', + next_title: 'Nächsten' + p.pageSize + ' (Pfeil-rechts)', + prev: 'Vorherigen', + prev_title: 'Vorherigen' + p.pageSize + ' (Pfeil-links)', + first_title: 'Ersten (Umschalt + Pfeil-links)', + last_title: 'Letzten (Umschalt + Pfeil-rechts)', + get_all_btn: 'alle (Pfeil-runter)', + get_all_alt: '(Button)', + close_btn: 'Schließen (Tab)', + close_alt: '(Button)', + loading: 'lade...', + loading_alt: '(lade)', + page_info: 'page_num von page_count', + 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.', + clear: 'Löschen Sie den Inhalt', + select_all: 'Wähle diese Seite', + unselect_all: 'Diese Seite entfernen', + clear_all: 'Alles löschen', + max_selected: 'Sie können nur bis zu max_selected_limit Elemente auswählen' + }; + break; + + // English + case 'en': + message = { + add_btn: 'Add button', + add_title: 'add a box', + del_btn: 'Del button', + del_title: 'delete a box', + next: 'Next', + next_title: 'Next' + p.pageSize + ' (Right key)', + prev: 'Prev', + prev_title: 'Prev' + p.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 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; + + // Spanish + case 'es': + message = { + add_btn: 'Agregar boton', + add_title: 'Agregar una opcion', + del_btn: 'Borrar boton', + del_title: 'Borrar una opcion', + next: 'Siguiente', + next_title: 'Proximas ' + p.pageSize + ' (tecla derecha)', + prev: 'Anterior', + prev_title: 'Anteriores ' + p.pageSize + ' (tecla izquierda)', + first_title: 'Primera (Shift + Left)', + last_title: 'Ultima (Shift + Right)', + get_all_btn: 'Ver todos (tecla abajo)', + get_all_alt: '(boton)', + close_btn: 'Cerrar (tecla TAB)', + close_alt: '(boton)', + loading: 'Cargando...', + loading_alt: '(Cargando)', + page_info: 'page_num de page_count', + 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.', + clear: 'Borrar el contenido', + select_all: 'Elija esta página', + unselect_all: 'Borrar esta página', + clear_all: 'Borrar todo marcado', + max_selected: 'Solo puedes seleccionar hasta max_selected_limit elementos' + }; + break; + + // Brazilian Portuguese + case 'pt-br': + message = { + add_btn: 'Adicionar botão', + add_title: 'Adicionar uma caixa', + del_btn: 'Apagar botão', + del_title: 'Apagar uma caixa', + next: 'Próxima', + next_title: 'Próxima ' + p.pageSize + ' (tecla direita)', + prev: 'Anterior', + prev_title: 'Anterior ' + p.pageSize + ' (tecla esquerda)', + first_title: 'Primeira (Shift + Left)', + last_title: 'Última (Shift + Right)', + get_all_btn: 'Ver todos (Seta para baixo)', + get_all_alt: '(botão)', + close_btn: 'Fechar (tecla TAB)', + close_alt: '(botão)', + loading: 'Carregando...', + loading_alt: '(Carregando)', + page_info: 'page_num de page_count', + 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.', + clear: 'Limpe o conteúdo', + select_all: 'Selecione a página atual', + unselect_all: 'Remova a página atual', + clear_all: 'Limpar tudo', + max_selected: 'Você só pode selecionar até max_selected_limit itens' + }; + break; + + // Japanese + case 'ja': + message = { + add_btn: '追加ボタン', + add_title: '入力ボックスを追加します', + del_btn: '削除ボタン', + del_title: '入力ボックスを削除します', + next: '次へ', + next_title: '次の' + p.pageSize + '件 (右キー)', + prev: '前へ', + prev_title: '前の' + p.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: '(0 件)', + ajax_error: 'サーバとの通信でエラーが発生しました。', + clear: 'コンテンツをクリアする', + select_all: '当ページを選びます', + unselect_all: '移して当ページを割ります', + clear_all: '選択した項目をクリアする', + max_selected: '最多で max_selected_limit のプロジェクトを選ぶことしかできません' + }; + break; + // 中文 + case 'cn': + default: + message = { + add_btn: '添加按钮', + add_title: '添加区域', + del_btn: '删除按钮', + del_title: '删除区域', + next: '下一页', + next_title: '下' + p.pageSize + ' (→)', + prev: '上一页', + prev_title: '上' + p.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 个项目' + }; + break; } this.message = message; }; @@ -502,7 +503,7 @@ container: 'sp_container', container_open: 'sp_container_open', re_area: 'sp_result_area', - result_open: 'sp_result_area_open', + result_open: 'sp_result_area_open', control_box: 'sp_control_box', //multiple select mode element_box: 'sp_element_box', @@ -513,18 +514,18 @@ select: 'sp_over', select_ok: 'sp_select_ok', select_ng: 'sp_select_ng', - selected: 'sp_selected', + selected: 'sp_selected', input_off: 'sp_input_off', message_box: 'sp_message_box', - disabled: 'sp_disabled', - + disabled: 'sp_disabled', + button: 'sp_button', - caret_open: 'sp_caret_open', + 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' + clear_btn : 'sp_clear_btn', + align_right : 'sp_align_right' }; this.css_class = css_class; }; @@ -534,8 +535,8 @@ */ SelectPage.prototype.setProp = function() { this.prop = { - //input disabled status - disabled : false, + //input disabled status + disabled : false, current_page: 1, //total page max_page: 1, @@ -546,10 +547,10 @@ key_select: false, //last selected item value prev_value: '', - //last selected item text - selected_text : '', + //last selected item text + selected_text : '', last_input_time: undefined, - init_set: false + init_set: false }; this.template = { tag: { @@ -557,72 +558,72 @@ textKey : '#item_text#', valueKey : '#item_value#' }, - page: { - current: 'page_num', - total: 'page_count' - }, - msg: { - maxSelectLimit: 'max_selected_limit' - } + page: { + current: 'page_num', + total: 'page_count' + }, + msg :{ + maxSelectLimit: 'max_selected_limit' + } }; }; - /** - * Get the actual width/height of invisible DOM elements with jQuery. - * Source code come from dreamerslab/jquery.actual - * @param element - * @param method - * @returns {*} - */ - SelectPage.prototype.elementRealSize = function(element, method){ - var defaults = { - absolute : false, - clone : false, - includeMargin : false, - display : 'block' - }; - var configs = defaults, $target = element.eq( 0 ),fix, restore,tmp = [], style = '', $hidden; - - fix = function (){ - // get all hidden parents - $hidden = $target.parents().addBack().filter( ':hidden' ); - style += 'visibility: hidden !important; display: ' + configs.display + ' !important; '; - - if( configs.absolute === true ) style += 'position: absolute !important;'; - - // save the origin style props - // set the hidden el css to be got the actual value later - $hidden.each( function (){ - // Save original style. If no style was set, attr() returns undefined - var $this = $( this ), thisStyle = $this.attr( 'style' ); - tmp.push( thisStyle ); - // Retain as much of the original style as possible, if there is one - $this.attr( 'style', thisStyle ? thisStyle + ';' + style : style ); - }); - }; - - restore = function (){ - // restore origin style values - $hidden.each( function ( i ){ - var $this = $( this ), _tmp = tmp[ i ]; - - if( _tmp === undefined ) $this.removeAttr( 'style' ); - else $this.attr( 'style', _tmp ); - }); - }; - - fix(); - // get the actual value with user specific methed - // it can be 'width', 'height', 'outerWidth', 'innerWidth'... etc - // configs.includeMargin only works for 'outerWidth' and 'outerHeight' - var actual = /(outer)/.test( method ) ? - $target[ method ]( configs.includeMargin ) : - $target[ method ](); - - restore(); - // IMPORTANT, this plugin only return the value of the first element - return actual; - }; + /** + * Get the actual width/height of invisible DOM elements with jQuery. + * Source code come from dreamerslab/jquery.actual + * @param element + * @param method + * @returns {*} + */ + SelectPage.prototype.elementRealSize = function(element, method){ + var defaults = { + absolute : false, + clone : false, + includeMargin : false, + display : 'block' + }; + var configs = defaults, $target = element.eq( 0 ),fix, restore,tmp = [], style = '', $hidden; + + fix = function (){ + // get all hidden parents + $hidden = $target.parents().addBack().filter( ':hidden' ); + style += 'visibility: hidden !important; display: ' + configs.display + ' !important; '; + + if( configs.absolute === true ) style += 'position: absolute !important;'; + + // save the origin style props + // set the hidden el css to be got the actual value later + $hidden.each( function (){ + // Save original style. If no style was set, attr() returns undefined + var $this = $( this ), thisStyle = $this.attr( 'style' ); + tmp.push( thisStyle ); + // Retain as much of the original style as possible, if there is one + $this.attr( 'style', thisStyle ? thisStyle + ';' + style : style ); + }); + }; + + restore = function (){ + // restore origin style values + $hidden.each( function ( i ){ + var $this = $( this ), _tmp = tmp[ i ]; + + if( _tmp === undefined ) $this.removeAttr( 'style' ); + else $this.attr( 'style', _tmp ); + }); + }; + + fix(); + // get the actual value with user specific methed + // it can be 'width', 'height', 'outerWidth', 'innerWidth'... etc + // configs.includeMargin only works for 'outerWidth' and 'outerHeight' + var actual = /(outer)/.test( method ) ? + $target[ method ]( configs.includeMargin ) : + $target[ method ](); + + restore(); + // IMPORTANT, this plugin only return the value of the first element + return actual; + }; /** * Dom building @@ -638,13 +639,13 @@ elem.combo_input = input.attr({'autocomplete':'off'}).addClass(css.input).wrap('
'); if(p.selectOnly) elem.combo_input.prop('readonly',true); - elem.container = elem.combo_input.parent().addClass(css.container); + elem.container = elem.combo_input.parent().addClass(css.container); if(elem.combo_input.prop('disabled')) { - if(p.multiple) elem.container.addClass(css.disabled); - else elem.combo_input.addClass(css.input_off); - } + if(p.multiple) elem.container.addClass(css.disabled); + else elem.combo_input.addClass(css.input_off); + } - // set outer box width + // set outer box width elem.container.width(orgWidth); elem.button = $('
').addClass(css.button); @@ -653,24 +654,28 @@ //clear button 'X' in single mode elem.clear_btn = $('
').html($('').addClass('sp-iconfont if-close')).addClass(css.clear_btn).attr('title', msg.clear); if(!p.dropButton) elem.clear_btn.addClass(css.align_right); - + //main box in multiple mode elem.element_box = $('
    ').addClass(css.element_box); if(p.multiple && p.multipleControlbar) elem.control = $('
    ').addClass(css.control_box); //result list box - elem.result_area = $('
    ').addClass(css.re_area); + if(orgWidth > 300){ + elem.result_area = $('
    ').addClass(css.re_area); + } else { + elem.result_area = $('
    ').addClass(css.re_area); + } //pagination bar - if(p.pagination) elem.navi = $('
    ').addClass('sp_pagination').append('
      '); + if(p.pagination) elem.navi = $('
      ').addClass('sp_pagination').append('
        '); elem.results = $('
          ').addClass(css.results); - + var namePrefix = '_text', - input_id = elem.combo_input.attr('id') || elem.combo_input.attr('name'), - input_name = elem.combo_input.attr('name') || 'selectPage', - hidden_name = input_name, - hidden_id = input_id; + input_id = elem.combo_input.attr('id') || elem.combo_input.attr('name'), + input_name = elem.combo_input.attr('name') || 'selectPage', + hidden_name = input_name, + hidden_id = input_id; - //switch the id and name attributes of input/hidden element + //switch the id and name attributes of input/hidden element elem.hidden = $('').attr({ name: hidden_name, id: hidden_id @@ -683,13 +688,13 @@ // 2. DOM element put elem.container.append(elem.hidden); if(p.dropButton){ - elem.container.append(elem.button) - elem.button.append(elem.dropdown); - } + elem.container.append(elem.button) + elem.button.append(elem.dropdown); + } $(document.body).append(elem.result_area); elem.result_area.append(elem.results); - if(p.pagination) elem.result_area.append(elem.navi); - + if(p.pagination) elem.result_area.append(elem.navi); + //Multiple select mode if(p.multiple){ if(p.multipleControlbar){ @@ -697,9 +702,9 @@ elem.control.append(''); elem.control.append(''); elem.control_text = $('

          '); - elem.control.append(elem.control_text); + elem.control.append(elem.control_text); elem.result_area.prepend(elem.control); - } + } elem.container.addClass('sp_container_combo'); elem.combo_input.addClass('sp_combo_input').before(elem.element_box); var li = $('

        • ').addClass('input_box'); @@ -715,43 +720,44 @@ * Drop down button set to default */ SelectPage.prototype.setButtonAttrDefault = function() { - /* - if (this.option.selectOnly) { - if ($(this.elem.combo_input).val() !== '') { - if ($(this.elem.hidden).val() !== '') { - //选择条件 - $(this.elem.combo_input).attr('title', this.message.select_ok).removeClass(this.css_class.select_ng).addClass(this.css_class.select_ok); - } else { - //输入方式 - $(this.elem.combo_input).attr('title', this.message.select_ng).removeClass(this.css_class.select_ok).addClass(this.css_class.select_ng); - } - } else { - $(this.elem.hidden).val(''); - $(this.elem.combo_input).removeAttr('title').removeClass(this.css_class.select_ng); - } - } - */ + /* + if (this.option.selectOnly) { + if ($(this.elem.combo_input).val() !== '') { + if ($(this.elem.hidden).val() !== '') { + //选择条件 + $(this.elem.combo_input).attr('title', this.message.select_ok).removeClass(this.css_class.select_ng).addClass(this.css_class.select_ok); + } else { + //输入方式 + $(this.elem.combo_input).attr('title', this.message.select_ng).removeClass(this.css_class.select_ok).addClass(this.css_class.select_ng); + } + } else { + $(this.elem.hidden).val(''); + $(this.elem.combo_input).removeAttr('title').removeClass(this.css_class.select_ng); + } + } + */ //this.elem.button.attr('title', this.message.get_all_btn); - if(this.option.dropButton) this.elem.button.attr('title', this.message.close_btn); + if(this.option.dropButton) + this.elem.button.attr('title', this.message.close_btn); }; /** * Set item need selected after init - * set selected item ways: - * - * + * set selected item ways: + * + * */ SelectPage.prototype.setInitRecord = function(refresh) { var self = this, p = self.option, el = self.elem, key = ''; - if($.type(el.combo_input.data('init')) != 'undefined') - p.initRecord = String(el.combo_input.data('init')); - //data-init and value attribute can be init plugin selected item - //but, if set data-init and value attribute in the same time, plugin will choose data-init attribute first - if(!refresh && !p.initRecord && el.combo_input.val()) - p.initRecord = el.combo_input.val(); - el.combo_input.val(''); - if(!refresh) el.hidden.val(p.initRecord); - key = refresh && el.hidden.val() ? el.hidden.val() : p.initRecord; + if($.type(el.combo_input.data('init')) != 'undefined') + p.initRecord = String(el.combo_input.data('init')); + //data-init and value attribute can be init plugin selected item + //but, if set data-init and value attribute in the same time, plugin will choose data-init attribute first + if(!refresh && !p.initRecord && el.combo_input.val()) + p.initRecord = el.combo_input.val(); + el.combo_input.val(''); + if(!refresh) el.hidden.val(p.initRecord); + key = refresh && el.hidden.val() ? el.hidden.val() : p.initRecord; if(key){ if (typeof p.data === 'object') { var data = new Array(); @@ -769,7 +775,7 @@ } else {//ajax data source mode to init selected item $.ajax({ dataType: 'json', - type: 'POST', + type: 'POST', url: p.data, data: { searchTable: p.dbTable, @@ -777,12 +783,13 @@ searchValue: key }, success: function(json) { - var d = null; - if(p.eAjaxSuccess && $.isFunction(p.eAjaxSuccess)) d = p.eAjaxSuccess(json); - self.afterInit(self, d.list); + var d = null; + if(p.eAjaxSuccess && $.isFunction(p.eAjaxSuccess)) + d = p.eAjaxSuccess(json); + self.afterInit(self, d.list); }, - error: function() { - self.ajaxErrorNotify(self); + error: function(jqXHR, textStatus, errorThrown) { + self.ajaxErrorNotify(self, errorThrown); } }); } @@ -800,31 +807,31 @@ var p = self.option, css = self.css_class; var getText = function(row){ - var text = row[p.showField]; - if(p.formatItem && $.isFunction(p.formatItem)){ - try{ - text = p.formatItem(row); - }catch(e){} - } - return text; - }; - + var text = row[p.showField]; + if(p.formatItem && $.isFunction(p.formatItem)){ + try{ + text = p.formatItem(row); + }catch(e){} + } + return text; + }; + if(p.multiple){ - self.prop.init_set = true; - self.clearAll(self); + self.prop.init_set = true; + self.clearAll(self); $.each(data,function(i,row){ var item = {text:getText(row),value:row[p.keyField]}; if(!self.isAlreadySelected(self,item)) self.addNewTag(self, row, item); }); self.tagValuesSet(self); self.inputResize(self); - self.prop.init_set = false; + self.prop.init_set = false; }else{ var row = data[0]; self.elem.combo_input.val(getText(row)); self.elem.hidden.val(row[p.keyField]); self.prop.prev_value = getText(row); - self.prop.selected_text = getText(row); + self.prop.selected_text = getText(row); if (p.selectOnly) { self.elem.combo_input.attr('title', self.message.select_ok).removeClass(css.select_ng).addClass(css.select_ok); } @@ -838,13 +845,13 @@ SelectPage.prototype.eDropdownButton = function() { var self = this; if(self.option.dropButton){ - self.elem.button.mouseup(function(ev) { - ev.stopPropagation(); - if (self.elem.result_area.is(':hidden') && !self.elem.combo_input.prop('disabled')) { - self.elem.combo_input.focus(); - } else self.hideResults(self); - }); - } + self.elem.button.mouseup(function(ev) { + ev.stopPropagation(); + if (self.elem.result_area.is(':hidden') && !self.elem.combo_input.prop('disabled')) { + self.elem.combo_input.focus(); + } else self.hideResults(self); + }); + } }; /** @@ -860,8 +867,8 @@ el.combo_input.keyup(function(e) { self.processKey(self, e); }).keydown(function(e) { - self.processControl(self, e); - }).focus(function(e) { + self.processControl(self, e); + }).focus(function(e) { //When focus on input, show the result list if (el.result_area.is(':hidden')) { e.stopPropagation(); @@ -870,41 +877,41 @@ } }); el.container.on('click.SelectPage','div.'+self.css_class.clear_btn,function(e){ - e.stopPropagation(); - if(!self.disabled(self)){ - self.clearAll(self, true); - if(p.eClear && $.isFunction(p.eClear)) p.eClear(self); - } - }); + e.stopPropagation(); + if(!self.disabled(self)){ + self.clearAll(self, true); + if(p.eClear && $.isFunction(p.eClear)) p.eClear(self); + } + }); el.result_area.on('mousedown.SelectPage',function(e){ - e.stopPropagation(); - }); + e.stopPropagation(); + }); if(p.multiple){ if(p.multipleControlbar){ //Select all item of current page - el.control.find('.sp_select_all').on('click.SelectPage',function(){ + el.control.find('.sp_select_all').on('click.SelectPage',function(e){ self.selectAllLine(self); }).hover(function(){ - el.control_text.html(msg.select_all); - },function(){ - el.control_text.html(''); - }); + el.control_text.html(msg.select_all); + },function(){ + el.control_text.html(''); + }); //Cancel select all item of current page - el.control.find('.sp_unselect_all').on('click.SelectPage',function(){ + el.control.find('.sp_unselect_all').on('click.SelectPage',function(e){ self.unSelectAllLine(self); }).hover(function(){ - el.control_text.html(msg.unselect_all); - },function(){ - el.control_text.html(''); - }); + el.control_text.html(msg.unselect_all); + },function(){ + el.control_text.html(''); + }); //Clear all selected item - el.control.find('.sp_clear_all').on('click.SelectPage',function(){ + el.control.find('.sp_clear_all').on('click.SelectPage',function(e){ self.clearAll(self, true); }).hover(function(){ - el.control_text.html(msg.clear_all); - },function(){ - el.control_text.html(''); - }); + el.control_text.html(msg.clear_all); + },function(){ + el.control_text.html(''); + }); } el.element_box.on('click.SelectPage',function(e){ var srcEl = e.target || e.srcElement; @@ -926,49 +933,49 @@ */ SelectPage.prototype.eWhole = function() { var self = this, css = self.css_class; - var cleanContent = function(obj){ - obj.elem.combo_input.val(''); - if(!obj.option.multiple) obj.elem.hidden.val(''); - obj.prop.selected_text = ''; - }; + var cleanContent = function(obj){ + obj.elem.combo_input.val(''); + if(!obj.option.multiple) obj.elem.hidden.val(''); + obj.prop.selected_text = ''; + }; //Out of plugin area $(document.body).off('mousedown.selectPage').on('mousedown.selectPage',function(e) { - var ele = e.target || e.srcElement; - var sp = $(ele).closest('div.' + css.container); - //Open status result list - $('div.' + css.container + '.' + css.container_open).each(function(){ - if(this == sp[0]) return; - var $this = $(this), d = $this.find('input.' + css.input).data(SelectPage.dataKey); - - if(!d.elem.combo_input.val() && d.elem.hidden.val() && !d.option.multiple){ - d.prop.current_page = 1;//reset page to 1 - cleanContent(d); - d.hideResults(d); - return true; - } - if (d.elem.results.find('li').not('.'+css.message_box).length) { - if(d.option.autoFillResult) { - //have selected item, then hide result list - if (d.elem.hidden.val()) d.hideResults(d); - else if(d.elem.results.find('li.sp_over').length){ - //no one selected and have highlight item, select the highlight item - d.selectCurrentLine(d); - }else if(d.option.autoSelectFirst){ - //no one selected, no one highlight, select the first item - d.nextLine(d); - d.selectCurrentLine(d); - }else d.hideResults(d); - }else d.hideResults(d); - } else { - //when no one item match, clear search keywords - if (d.option.noResultClean) cleanContent(d); - else{ - if(!d.option.multiple) d.elem.hidden.val(''); - } - d.hideResults(d); - } - }); + var ele = e.target || e.srcElement; + var sp = $(ele).closest('div.' + css.container); + //Open status result list + $('div.' + css.container + '.' + css.container_open).each(function(){ + if(this == sp[0]) return; + var $this = $(this), d = $this.find('input.' + css.input).data(SelectPage.dataKey); + + if(!d.elem.combo_input.val() && d.elem.hidden.val() && !d.option.multiple){ + d.prop.current_page = 1;//reset page to 1 + cleanContent(d); + d.hideResults(d); + return true; + } + if (d.elem.results.find('li').not('.'+css.message_box).length) { + if(d.option.autoFillResult) { + //have selected item, then hide result list + if (d.elem.hidden.val()) d.hideResults(d); + else if(d.elem.results.find('li.sp_over').length){ + //no one selected and have highlight item, select the highlight item + d.selectCurrentLine(d, true); + }else if(d.option.autoSelectFirst){ + //no one selected, no one highlight, select the first item + d.nextLine(d); + d.selectCurrentLine(d, true); + }else d.hideResults(d); + }else d.hideResults(d); + } else { + //when no one item match, clear search keywords + if (d.option.noResultClean) cleanContent(d); + else{ + if(!d.option.multiple) d.elem.hidden.val(''); + } + d.hideResults(d); + } + }); }); }; @@ -983,12 +990,12 @@ return; } if(!$(this).hasClass(css.selected) && !$(this).hasClass(css.message_box)){ - $(this).addClass(css.select); - self.setCssFocusedResults(self); - } + $(this).addClass(css.select); + self.setCssFocusedResults(self); + } },function(){ - $(this).removeClass(css.select); - }).click(function(e) { + $(this).removeClass(css.select); + }).click(function(e) { if (self.prop.key_select) { self.prop.key_select = false; return; @@ -996,36 +1003,36 @@ e.preventDefault(); e.stopPropagation(); - if(!$(this).hasClass(css.selected)) self.selectCurrentLine(self); + if(!$(this).hasClass(css.selected)) self.selectCurrentLine(self, false); }); }; - /** - * Reposition result list when list beyond the visible area - */ + /** + * Reposition result list when list beyond the visible area + */ SelectPage.prototype.eScroll = function(){ - var css = this.css_class; - $(window).on('scroll.SelectPage',function(){ - $('div.' + css.container + '.' + css.container_open).each(function(){ - var $this = $(this), d = $this.find('input.'+css.input).data(SelectPage.dataKey), - offset = d.elem.result_area.offset(), - screenScrollTop = $(window).scrollTop(), - docHeight = $(document).height(), - viewHeight = $(window).height(), - listHeight = d.elem.result_area.outerHeight(), - listBottom = offset.top + listHeight, - hasOverflow = docHeight > viewHeight, - down = d.elem.result_area.hasClass('shadowDown'); - if(hasOverflow){ - if(down){//open down - if(listBottom > (viewHeight + screenScrollTop)) d.calcResultsSize(d); - }else{//open up - if(offset.top < screenScrollTop) d.calcResultsSize(d); - } - } - }); - }); - }; + var self = this, css = this.css_class; + $(window).on('scroll.SelectPage',function(e){ + $('div.' + css.container + '.' + css.container_open).each(function(){ + var $this = $(this), d = $this.find('input.'+css.input).data(SelectPage.dataKey), + offset = d.elem.result_area.offset(), + screenScrollTop = $(window).scrollTop(), + docHeight = $(document).height(), + viewHeight = $(window).height(), + listHeight = d.elem.result_area.outerHeight(), + listBottom = offset.top + listHeight, + hasOverflow = docHeight > viewHeight, + down = d.elem.result_area.hasClass('shadowDown'); + if(hasOverflow){ + if(down){//open down + if(listBottom > (viewHeight + screenScrollTop)) d.calcResultsSize(d); + }else{//open up + if(offset.top < screenScrollTop) d.calcResultsSize(d); + } + } + }); + }); + }; /** * Page bar button event bind @@ -1033,25 +1040,25 @@ SelectPage.prototype.ePaging = function() { var self = this; if(!self.option.pagination) return; - self.elem.navi.find('li.csFirstPage').off('click').on('click',function(ev) { + self.elem.navi.find('li.csFirstPage').off('click').on('click',function(ev) { //$(self.elem.combo_input).focus(); ev.preventDefault(); self.firstPage(self); }); - self.elem.navi.find('li.csPreviousPage').off('click').on('click',function(ev) { + self.elem.navi.find('li.csPreviousPage').off('click').on('click',function(ev) { //$(self.elem.combo_input).focus(); ev.preventDefault(); self.prevPage(self); }); - self.elem.navi.find('li.csNextPage').off('click').on('click',function(ev) { + self.elem.navi.find('li.csNextPage').off('click').on('click',function(ev) { //$(self.elem.combo_input).focus(); ev.preventDefault(); self.nextPage(self); }); - self.elem.navi.find('li.csLastPage').off('click').on('click',function(ev) { + self.elem.navi.find('li.csLastPage').off('click').on('click',function(ev) { //$(self.elem.combo_input).focus(); ev.preventDefault(); self.lastPage(self); @@ -1061,11 +1068,12 @@ /** * Ajax request fail * @param {Object} self + * @param {string} errorThrown */ - SelectPage.prototype.ajaxErrorNotify = function(self) { + SelectPage.prototype.ajaxErrorNotify = function(self, errorThrown) { self.showMessage(self.message.ajax_error); }; - + /** * Message box * @param {Object} self @@ -1088,15 +1096,15 @@ */ SelectPage.prototype.scrollWindow = function(self, enforce) { var current_result = self.getCurrentLine(self), - target_top = (current_result && !enforce) ? current_result.offset().top: self.elem.container.offset().top, - target_size; + target_top = (current_result && !enforce) ? current_result.offset().top: self.elem.container.offset().top, + target_size; self.prop.size_li = self.elem.results.children('li:first').outerHeight(); target_size = self.prop.size_li; - + var gap, client_height = $(window).height(), - scroll_top = $(window).scrollTop(), - scroll_bottom = scroll_top + client_height - target_size; + scroll_top = $(window).scrollTop(), + scroll_bottom = scroll_top + client_height - target_size; if (current_result.length) { if (target_top < scroll_top || target_size > client_height) { //scroll to top @@ -1108,21 +1116,21 @@ } else if (target_top < scroll_top) gap = target_top - scroll_top; window.scrollBy(0, gap); }; - /** - * change css class by status - * @param self - * @param status {boolean} true: open, false: close - */ + /** + * change css class by status + * @param self + * @param status {boolean} true: open, false: close + */ SelectPage.prototype.setOpenStatus = function(self, status){ - var el = self.elem, css = self.css_class; - if(status){ - el.container.addClass(css.container_open); - el.result_area.addClass(css.result_open); - }else{ - el.container.removeClass(css.container_open); - el.result_area.removeClass(css.result_open); - } - }; + var el = self.elem, css = self.css_class; + if(status){ + el.container.addClass(css.container_open); + el.result_area.addClass(css.result_open); + }else{ + el.container.removeClass(css.container_open); + el.result_area.removeClass(css.result_open); + } + }; /** * input element in focus css class set @@ -1134,7 +1142,7 @@ }; /** - * set result list get focus and input element lost focus + * set result list get focus and input element lost focus * @param {Object} self */ SelectPage.prototype.setCssFocusedResults = function(self) { @@ -1153,36 +1161,36 @@ self.prop.first_show = false; if(self.option.selectOnly) self.setButtonAttrDefault(); - if(!self.option.multiple && !now_value){ - self.elem.combo_input.val(''); - self.elem.hidden.val(''); - self.elem.clear_btn.remove(); - } + if(!self.option.multiple && !now_value){ + self.elem.combo_input.val(''); + self.elem.hidden.val(''); + self.elem.clear_btn.remove(); + } self.suggest(self); } }; - /** - * Input handle(regular input) - * @param {Object} self - * @param {Object} e - event object - */ - SelectPage.prototype.processKey = function(self, e) { - if($.inArray(e.keyCode, [37, 38, 39, 40, 27, 9, 13]) === -1){ - if(e.keyCode != 16) self.setCssFocusedInput(self); // except Shift(16) - self.inputResize(self); - if($.type(self.option.data) === 'string'){ - self.prop.last_input_time = e.timeStamp; - setTimeout(function(){ - if((e.timeStamp - self.prop.last_input_time) === 0) - self.checkValue(self); - },self.option.inputDelay * 1000); - }else{ - self.checkValue(self); - } - } - } + /** + * Input handle(regular input) + * @param {Object} self + * @param {Object} e - event object + */ + SelectPage.prototype.processKey = function(self, e) { + if($.inArray(e.keyCode, [37, 38, 39, 40, 27, 9, 13]) === -1){ + if(e.keyCode != 16) self.setCssFocusedInput(self); // except Shift(16) + self.inputResize(self); + if($.type(self.option.data) === 'string'){ + self.prop.last_input_time = e.timeStamp; + setTimeout(function(){ + if((e.timeStamp - self.prop.last_input_time) === 0) + self.checkValue(self); + },self.option.inputDelay * 1000); + }else{ + self.checkValue(self); + } + } + } /** * Input handle(control key) @@ -1197,36 +1205,36 @@ e.cancelBubble = true; e.returnValue = false; switch (e.keyCode) { - case 37:// left - if (e.shiftKey) self.firstPage(self); - else self.prevPage(self); - break; - case 38:// up - self.prop.key_select = true; - self.prevLine(self); - break; - case 39:// right - if (e.shiftKey) self.lastPage(self); - else self.nextPage(self); - break; - case 40:// down - if (self.elem.results.children('li').length) { + case 37:// left + if (e.shiftKey) self.firstPage(self); + else self.prevPage(self); + break; + case 38:// up self.prop.key_select = true; - self.nextLine(self); - } else self.suggest(self); - break; - case 9:// tab - self.prop.key_paging = true; - self.selectCurrentLine(self); - //self.hideResults(self); - break; - case 13:// return - self.selectCurrentLine(self); - break; - case 27:// escape - self.prop.key_paging = true; - self.hideResults(self); - break; + self.prevLine(self); + break; + case 39:// right + if (e.shiftKey) self.lastPage(self); + else self.nextPage(self); + break; + case 40:// down + if (self.elem.results.children('li').length) { + self.prop.key_select = true; + self.nextLine(self); + } else self.suggest(self); + break; + case 9:// tab + self.prop.key_paging = true; + self.selectCurrentLine(self, true); + //self.hideResults(self); + break; + case 13:// return + self.selectCurrentLine(self, true); + break; + case 27:// escape + self.prop.key_paging = true; + self.hideResults(self); + break; } } }; @@ -1248,21 +1256,21 @@ */ SelectPage.prototype.suggest = function(self) { var q_word, val = $.trim(self.elem.combo_input.val()); - if(self.option.multiple) q_word = val; - else{ - if(val && val === self.prop.selected_text) q_word = ''; - else q_word = val; - } + if(self.option.multiple) q_word = val; + else{ + if(val && val === self.prop.selected_text) q_word = ''; + else q_word = val; + } q_word = q_word.split(/[\s ]+/); - //Before show up result list callback - if(self.option.eOpen && $.isFunction(self.option.eOpen)) - self.option.eOpen.call(self); + //Before show up result list callback + if(self.option.eOpen && $.isFunction(self.option.eOpen)) + self.option.eOpen.call(self); self.abortAjax(self); //self.setLoading(self); var which_page_num = self.prop.current_page || 1; - + if (typeof self.option.data == 'object') self.searchForJson(self, q_word, which_page_num); else self.searchForDb(self, q_word, which_page_num); }; @@ -1285,7 +1293,7 @@ * @param {number} which_page_num - target page number */ SelectPage.prototype.searchForDb = function(self, q_word, which_page_num) { - var p = self.option; + var p = self.option; if(!p.eAjaxSuccess || !$.isFunction(p.eAjaxSuccess)) self.hideResults(self); var _paramsFunc = p.params, _params = {}, searchKey = p.searchField; //when have new query keyword, then reset page number to 1. @@ -1298,7 +1306,7 @@ searchTable: p.dbTable }; if(p.orderBy !== false) _orgParams.orderBy = p.orderBy; - _orgParams[searchKey] = q_word[0]; + _orgParams[searchKey] = q_word[0]; if (_paramsFunc && $.isFunction(_paramsFunc)) { var result = _paramsFunc.call(self); if (result && $.isPlainObject(result)) { @@ -1313,18 +1321,18 @@ success: function(returnData) { if (!returnData || !$.isPlainObject(returnData)) { self.hideResults(self); - self.ajaxErrorNotify(self); + self.ajaxErrorNotify(self, errorThrown); return; } var data = {}, json = {}; try{ - data = p.eAjaxSuccess(returnData); - json.originalResult = data.list; - json.cnt_whole = data.totalRow; - }catch(e){ - self.showMessage(self, self.message.ajax_error); - return; - } + data = p.eAjaxSuccess(returnData); + json.originalResult = data.list; + json.cnt_whole = data.totalRow; + }catch(e){ + self.showMessage(self, self.message.ajax_error); + return; + } json.candidate = []; json.keyField = []; @@ -1346,10 +1354,10 @@ } self.prepareResults(self, json, q_word, which_page_num); }, - error: function(jqXHR, textStatus) { + error: function(jqXHR, textStatus, errorThrown) { if (textStatus != 'abort') { self.hideResults(self); - self.ajaxErrorNotify(self); + self.ajaxErrorNotify(self, errorThrown); } }, complete: function() { @@ -1366,7 +1374,7 @@ */ SelectPage.prototype.searchForJson = function(self, q_word, which_page_num) { var p = self.option, matched = [], esc_q = [], sorted = [], json = {}, i = 0, arr_reg = []; - + //query keyword filter do { //'/\W/g'正则代表全部不是字母,数字,下划线,汉字的字符 @@ -1377,9 +1385,9 @@ } while ( i < q_word.length ); // SELECT * FROM data WHERE field LIKE q_word; - for ( i = 0; i < p.data.length; i++) { + for (var i = 0; i < p.data.length; i++) { var flag = false, row = p.data[i], itemText; - for (var j = 0; j < arr_reg.length; j++) { + for (var j = 0; j < arr_reg.length; j++) { itemText = row[p.searchField]; if(p.formatItem && $.isFunction(p.formatItem)) itemText = p.formatItem(row); @@ -1393,49 +1401,49 @@ } if (flag) matched.push(row); } - + // (CASE WHEN ...) then く order some column - if(p.orderBy === false) sorted = matched.concat(); - else{ - var reg1 = new RegExp('^' + esc_q[0] + '$', 'gi'), - reg2 = new RegExp('^' + esc_q[0], 'gi'), - matched1 = [], matched2 = [], matched3 = []; - for ( i = 0; i < matched.length; i++) { - var orderField = p.orderBy[0][0]; - var orderValue = String(matched[i][orderField]); - if (orderValue.match(reg1)) { - matched1.push(matched[i]); - } else if (orderValue.match(reg2)) { - matched2.push(matched[i]); - } else { - matched3.push(matched[i]); - } - } + if(p.orderBy === false) sorted = matched.concat(); + else{ + var reg1 = new RegExp('^' + esc_q[0] + '$', 'gi'), + reg2 = new RegExp('^' + esc_q[0], 'gi'), + matched1 = [], matched2 = [], matched3 = []; + for (var i = 0; i < matched.length; i++) { + var orderField = p.orderBy[0][0]; + var orderValue = String(matched[i][orderField]); + if (orderValue.match(reg1)) { + matched1.push(matched[i]); + } else if (orderValue.match(reg2)) { + matched2.push(matched[i]); + } else { + matched3.push(matched[i]); + } + } - if (p.orderBy[0][1].match(/^asc$/i)) { - matched1 = self.sortAsc(self, matched1); - matched2 = self.sortAsc(self, matched2); - matched3 = self.sortAsc(self, matched3); - } else { - matched1 = self.sortDesc(self, matched1); - matched2 = self.sortDesc(self, matched2); - matched3 = self.sortDesc(self, matched3); - } - sorted = sorted.concat(matched1).concat(matched2).concat(matched3); - } + if (p.orderBy[0][1].match(/^asc$/i)) { + matched1 = self.sortAsc(self, matched1); + matched2 = self.sortAsc(self, matched2); + matched3 = self.sortAsc(self, matched3); + } else { + matched1 = self.sortDesc(self, matched1); + matched2 = self.sortDesc(self, matched2); + matched3 = self.sortDesc(self, matched3); + } + sorted = sorted.concat(matched1).concat(matched2).concat(matched3); + } - /* + /* if (sorted.length === undefined || sorted.length === 0 ) { self.notFoundSearch(self); return; } */ - json.cnt_whole = sorted.length; - //page_move used to distinguish between init plugin or page moving + json.cnt_whole = sorted.length; + //page_move used to distinguish between init plugin or page moving if(!self.prop.page_move){ //only single mode can be used page number relocation if(!p.multiple){ - //get selected item belong page number + //get selected item belong page number var currentValue = self.elem.hidden.val(); if($.type(currentValue) !== 'undefined' && $.trim(currentValue) !== ''){ var index = 0; @@ -1451,19 +1459,19 @@ } } }else{ - //set page number to 1 when result number less then page size + //set page number to 1 when result number less then page size if(sorted.length <= ((which_page_num - 1) * p.pageSize)){ which_page_num = 1; self.prop.current_page = 1; } } - + //LIMIT xx OFFSET xx var start = (which_page_num - 1) * p.pageSize, end = start + p.pageSize; //save original data json.originalResult = []; //after data filter handle - for ( i = start; i < end; i++) { + for (var i = start; i < end; i++) { if (sorted[i] === undefined) break; json.originalResult.push(sorted[i]); for (var key in sorted[i]) { @@ -1484,14 +1492,14 @@ }; /** - * Set order asc + * Set order asc * @param {Object} self * @param {Array} arr - result array */ SelectPage.prototype.sortAsc = function(self, arr) { arr.sort(function(a, b) { - var valA = a[self.option.orderBy[0][0]], valB = b[self.option.orderBy[0][0]]; - return $.type(valA) === 'number' ? valA - valB : String(valA).localeCompare(String(valB)); + var valA = a[self.option.orderBy[0][0]], valB = b[self.option.orderBy[0][0]]; + return $.type(valA) === 'number' ? valA - valB : String(valA).localeCompare(String(valB)); }); return arr; }; @@ -1503,8 +1511,8 @@ */ SelectPage.prototype.sortDesc = function(self, arr) { arr.sort(function(a, b) { - var valA = a[self.option.orderBy[0][0]], valB = b[self.option.orderBy[0][0]]; - return $.type(valA) === 'number' ? valB - valA : String(valB).localeCompare(String(valA)); + var valA = a[self.option.orderBy[0][0]], valB = b[self.option.orderBy[0][0]]; + return $.type(valA) === 'number' ? valB - valA : String(valB).localeCompare(String(valA)); }); return arr; }; @@ -1549,52 +1557,56 @@ * @param {number} page_num - current page number */ SelectPage.prototype.setNavi = function(self, cnt_whole, cnt_page, page_num) { - var msg = self.message; + var msg = self.message; /** * build pagination bar */ var buildPageNav = function(self, pagebar, page_num, last_page) { - var updatePageInfo = function(){ - var pageInfo = msg.page_info; - return pageInfo.replace(self.template.page.current, page_num).replace(self.template.page.total, last_page); - }; + var updatePageInfo = function(){ + var pageInfo = msg.page_info; + return pageInfo.replace(self.template.page.current, page_num).replace(self.template.page.total, last_page); + }; if (pagebar.find('li').length === 0) { + var fpnl_page_width = ($(pagebar).parent().parent().width()-178)/4; + if(fpnl_page_width < 30){ + fpnl_page_width = 30; + } pagebar.hide().empty(); var iconFist='sp-iconfont if-first', - iconPrev='sp-iconfont if-previous', - iconNext='sp-iconfont if-next', - iconLast='sp-iconfont if-last'; + iconPrev='sp-iconfont if-previous', + iconNext='sp-iconfont if-next', + iconLast='sp-iconfont if-last'; - pagebar.append('
        • '); - pagebar.append('
        • '); + pagebar.append('
        • '); + pagebar.append('
        • '); //pagination information pagebar.append('
        • ' + updatePageInfo() + '
        • '); - pagebar.append('
        • '); - pagebar.append('
        • '); - pagebar.show(); + pagebar.append('
        • '); + pagebar.append('
        • '); + pagebar.show(); }else{ - pagebar.find('li.pageInfoBox a').html(updatePageInfo()); - } + pagebar.find('li.pageInfoBox a').html(updatePageInfo()); + } }; var pagebar = self.elem.navi.find('ul'), - last_page = Math.ceil(cnt_whole / self.option.pageSize); //calculate total page + last_page = Math.ceil(cnt_whole / self.option.pageSize); //calculate total page if(last_page === 0) page_num = 0; else{ if(last_page < page_num) page_num = last_page; else if(page_num === 0) page_num = 1; } self.prop.current_page = page_num;//update current page number - self.prop.max_page = last_page;//update page count + self.prop.max_page = last_page;//update page count buildPageNav(self, pagebar, page_num, last_page); //update paging status var dClass = 'disabled', - first = pagebar.find('li.csFirstPage'), - previous = pagebar.find('li.csPreviousPage'), - next = pagebar.find('li.csNextPage'), - last = pagebar.find('li.csLastPage'); + first = pagebar.find('li.csFirstPage'), + previous = pagebar.find('li.csPreviousPage'), + next = pagebar.find('li.csNextPage'), + last = pagebar.find('li.csLastPage'); //first and previous if (page_num === 1 || page_num === 0) { if (!first.hasClass(dClass)) first.addClass(dClass); @@ -1622,63 +1634,62 @@ * @param {boolean} is_query - used to different from search to open and just click to open */ SelectPage.prototype.displayResults = function(self, json, is_query) { - var p = self.option, el = self.elem; + var p = self.option, el = self.elem; el.results.hide().empty(); if(p.multiple && $.type(p.maxSelectLimit) === 'number' && p.maxSelectLimit > 0){ var selectedSize = el.element_box.find('li.selected_tag').length; if(selectedSize > 0 && selectedSize >= p.maxSelectLimit){ - var msg = self.message.max_selected; + var msg = self.message.max_selected; self.showMessage(self, msg.replace(self.template.msg.maxSelectLimit, p.maxSelectLimit)); return; } } if(json.candidate.length){ - var arr_candidate = json.candidate, - arr_primary_key = json.keyField, - keystr = el.hidden.val(), - keyArr = keystr ? keystr.split(',') : new Array(), - itemText = ''; - for (var i = 0; i < arr_candidate.length; i++) { - if(p.formatItem && $.isFunction(p.formatItem)){ - try { - itemText = p.formatItem(json.originalResult[i]); - } catch (e) { - /*eslint no-console: ["error", { allow: ["warn", "error"] }] */ - console.error('formatItem内容格式化函数内容设置不正确!'); - itemText = arr_candidate[i]; - } - }else itemText = arr_candidate[i]; - var list = $('
        • ').html(itemText).attr({ - pkey: arr_primary_key[i] - }); - if(!p.formatItem) list.attr('title', itemText); - - //Set selected item highlight - if ($.inArray(arr_primary_key[i].toString(),keyArr) !== -1) { - list.addClass(self.css_class.selected); - } - //cache item data - list.data('dataObj',json.originalResult[i]); - el.results.append(list); - } - }else{ - var li = '
        • '+ - self.message.not_found + '
        • '; - el.results.append(li); - } - el.results.show(); + var arr_candidate = json.candidate, + arr_primary_key = json.keyField, + keystr = el.hidden.val(), + keyArr = keystr ? keystr.split(',') : new Array(), + itemText = ''; + for (var i = 0; i < arr_candidate.length; i++) { + if(p.formatItem && $.isFunction(p.formatItem)){ + try { + itemText = p.formatItem(json.originalResult[i]); + } catch (e) { + console.error('formatItem内容格式化函数内容设置不正确!'); + itemText = arr_candidate[i]; + } + }else itemText = arr_candidate[i]; + var list = $('
        • ').html(itemText).attr({ + pkey: arr_primary_key[i] + }); + if(!p.formatItem) list.attr('title', itemText); - if(p.multiple && p.multipleControlbar) el.control.show(); + //Set selected item highlight + if ($.inArray(arr_primary_key[i].toString(),keyArr) !== -1) { + list.addClass(self.css_class.selected); + } + //cache item data + list.data('dataObj',json.originalResult[i]); + el.results.append(list); + } + }else{ + var li = '
        • '+ + self.message.not_found + '
        • '; + el.results.append(li); + } + el.results.show(); + + if(p.multiple && p.multipleControlbar) el.control.show(); if(p.pagination) el.navi.show(); self.calcResultsSize(self); self.setOpenStatus(self, true); - + //Result item event bind self.eResultList(); //scrolling listen self.eScroll(); - //auto highlight first item in search, have result and set autoSelectFirst to true situation + //auto highlight first item in search, have result and set autoSelectFirst to true situation if (is_query && json.candidate.length && p.autoSelectFirst) self.nextLine(self); }; @@ -1687,76 +1698,74 @@ * @param {Object} self */ SelectPage.prototype.calcResultsSize = function(self) { - var p = self.option, el = self.elem; - var rePosition = function(){ - if (el.container.css('position') === 'static') { - // position: static - var st_offset = el.combo_input.offset(); - el.result_area.css({ - top: st_offset.top + el.combo_input.outerHeight() + 'px', - left: st_offset.left + 'px' - }); - } else { - var listHeight; - if(!p.pagination){ - var itemHeight = el.results.find('li:first').outerHeight(true); - listHeight = itemHeight * p.listSize; - el.results.css({ - 'max-height':listHeight, - 'overflow-y':'auto' - }); - } + var p = self.option, el = self.elem; + var rePosition = function(){ + if (el.container.css('position') === 'static') { + // position: static + var offset = el.combo_input.offset(); + el.result_area.css({ + top: offset.top + el.combo_input.outerHeight() + 'px', + left: offset.left + 'px' + }); + } else { + if(!p.pagination){ + var itemHeight = el.results.find('li:first').outerHeight(true), + listHeight = itemHeight * p.listSize; + el.results.css({ + 'max-height':listHeight, + 'overflow-y':'auto' + }); + } - //handle result list show up side(left, right, up or down) - var docWidth = $(document).width(), - docHeight = $(document).height(),//the document full height - viewHeight = $(window).height(),//browser visible area height - offset = el.container.offset(), - screenScrollTop = $(window).scrollTop(), - listWidth = el.result_area.outerWidth(), - //default left used input element left - defaultLeft = offset.left,//p.multiple ? -1 : 0; - //input element height - inputHeight = el.container.outerHeight(), - left = (offset.left + listWidth) > docWidth ? - defaultLeft - (listWidth - el.container.outerWidth()) : - defaultLeft, - //the actual top coordinate of input element(outer div) - screenTop = offset.top,//$(el.container).scrollTop();//offset.top - screenScrollTop; - top = 0,dist = 5,//set distance between input element and result list - //the actual top coordinate of result list - listBottom = screenTop + inputHeight + listHeight + dist, - hasOverflow = docHeight > viewHeight; - - //result list height - listHeight = el.result_area.outerHeight(); - - if((screenTop - screenScrollTop - dist > listHeight) && - (hasOverflow && listBottom > (viewHeight + screenScrollTop)) || - (!hasOverflow && listBottom > viewHeight)){ - //open up - top = offset.top - listHeight - dist; - el.result_area.removeClass('shadowUp shadowDown').addClass('shadowUp'); - }else{ - //open down - top = offset.top + (p.multiple ? el.container.outerHeight() : inputHeight); - el.result_area.removeClass('shadowUp shadowDown').addClass('shadowDown'); - top += dist; - } - return { - top : top + 'px', left: left + 'px' - }; - } - }; - if(el.result_area.is(':visible')){ - el.result_area.css(rePosition()); - }else{ - var pss = rePosition(); - el.result_area.css(pss).show(1,function(){ - var repss = rePosition(); - if(pss.top !== repss.top || pss.left !== repss.left) el.result_area.css(repss); - }); - } + //handle result list show up side(left, right, up or down) + var docWidth = $(document).width(), + docHeight = $(document).height(),//the document full height + viewHeight = $(window).height(),//browser visible area height + offset = el.container.offset(), + screenScrollTop = $(window).scrollTop(), + listWidth = el.result_area.outerWidth(), + //result list height + listHeight = el.result_area.outerHeight(), + //default left used input element left + defaultLeft = offset.left,//p.multiple ? -1 : 0; + //input element height + inputHeight = el.container.outerHeight(), + left = (offset.left + listWidth) > docWidth ? + defaultLeft - (listWidth - el.container.outerWidth()) : + defaultLeft, + //the actual top coordinate of input element(outer div) + screenTop = offset.top,//$(el.container).scrollTop();//offset.top - screenScrollTop; + top = 0,dist = 5,//set distance between input element and result list + //the actual top coordinate of result list + listBottom = screenTop + inputHeight + listHeight + dist, + hasOverflow = docHeight > viewHeight; + + if((screenTop - screenScrollTop - dist > listHeight) && + (hasOverflow && listBottom > (viewHeight + screenScrollTop)) || + (!hasOverflow && listBottom > viewHeight)){ + //open up + top = offset.top - listHeight - dist; + el.result_area.removeClass('shadowUp shadowDown').addClass('shadowUp'); + }else{ + //open down + top = offset.top + (p.multiple ? el.container.outerHeight() : inputHeight); + el.result_area.removeClass('shadowUp shadowDown').addClass('shadowDown'); + top += dist; + } + return { + top : top + 'px', left: left + 'px' + }; + } + }; + if(el.result_area.is(':visible')){ + el.result_area.css(rePosition()); + }else{ + var pss = rePosition(); + el.result_area.css(pss).show(1,function(){ + var repss = rePosition(); + if(pss.top !== repss.top || pss.left !== repss.left) el.result_area.css(repss); + }); + } }; /** @@ -1777,27 +1786,27 @@ self.elem.results.empty(); self.elem.result_area.hide(); self.setOpenStatus(self, false); - //unbind window scroll listen - $(window).off('scroll.SelectPage'); + //unbind window scroll listen + $(window).off('scroll.SelectPage'); self.abortAjax(self); self.setButtonAttrDefault(); }; - /** - * set plugin to disabled / enabled - * @param self - * @param disabled - */ + /** + * set plugin to disabled / enabled + * @param self + * @param disabled + */ SelectPage.prototype.disabled = function(self, disabled){ - var el = self.elem; - if($.type(disabled) === 'undefined') return el.combo_input.prop('disabled'); - if($.type(disabled) === 'boolean'){ - el.combo_input.prop('disabled', disabled); - if(disabled) el.container.addClass(self.css_class.disabled); - else el.container.removeClass(self.css_class.disabled); - } - }; + var p = self.option, el = self.elem; + if($.type(disabled) === 'undefined') return el.combo_input.prop('disabled'); + if($.type(disabled) === 'boolean'){ + el.combo_input.prop('disabled', disabled); + if(disabled) el.container.addClass(self.css_class.disabled); + else el.container.removeClass(self.css_class.disabled); + } + }; /** * Go fist page @@ -1848,8 +1857,8 @@ }; /** * do something after select/unSelect action - * @param {Object} self - * @param {boolean} reOpen + * @param {Object} self + * @param {boolean} reOpen */ SelectPage.prototype.afterAction = function(self, reOpen){ self.inputResize(self); @@ -1861,7 +1870,7 @@ self.hideResults(self); self.elem.combo_input.blur(); } - if(!self.option.selectToCloseList && reOpen){ + if(!self.option.selectToCloseList && reOpen){ self.suggest(self); self.elem.combo_input.focus(); } @@ -1874,13 +1883,14 @@ /** * Select current list item * @param {Object} self + * @param {boolean} is_enter_key */ - SelectPage.prototype.selectCurrentLine = function(self) { + SelectPage.prototype.selectCurrentLine = function(self, is_enter_key) { self.scrollWindow(self, true); var p = self.option, current = self.getCurrentLine(self); if (current) { - var data = current.data('dataObj'); + var data = current.data('dataObj'); if(!p.multiple){ self.elem.combo_input.val(current.text()); self.elem.hidden.val(current.attr('pkey')); @@ -1895,10 +1905,10 @@ } if (p.selectOnly) self.setButtonAttrDefault(); - + //Select item callback if(p.eSelect && $.isFunction(p.eSelect)) p.eSelect(data, self); - + self.prop.prev_value = self.elem.combo_input.val(); self.prop.selected_text = self.elem.combo_input.val(); @@ -1906,32 +1916,32 @@ } self.afterAction(self, true); }; - /** - * Show clear button when item selected in single selection mode - */ + /** + * Show clear button when item selected in single selection mode + */ SelectPage.prototype.putClearButton = function(){ - if(!this.option.multiple && !this.elem.combo_input.prop('disabled')) this.elem.container.append(this.elem.clear_btn); - }; + if(!this.option.multiple && !this.elem.combo_input.prop('disabled')) this.elem.container.append(this.elem.clear_btn); + }; /** * Select all list item * @param {Object} self */ SelectPage.prototype.selectAllLine = function(self){ var p = self.option, jsonarr = new Array(); - self.elem.results.find('li').each(function(i,row){ - var $row = $(row), data = $row.data('dataObj'); + self.elem.results.find('li').each(function(i,row){ + var $row = $(row), data = $row.data('dataObj'); var item = {text:$row.text(),value:$row.attr('pkey')}; if(!self.isAlreadySelected(self,item)){ self.addNewTag(self, data, item); self.tagValuesSet(self); } jsonarr.push(data); - //limited max selected items + //limited max selected items if($.type(p.maxSelectLimit) === 'number' && - p.maxSelectLimit > 0 && - p.maxSelectLimit === self.elem.element_box.find('li.selected_tag').length){ - return false; - } + p.maxSelectLimit > 0 && + p.maxSelectLimit === self.elem.element_box.find('li.selected_tag').length){ + return false; + } }); if(p.eSelect && $.isFunction(p.eSelect)) p.eSelect(jsonarr, self); self.afterAction(self, true); @@ -1941,8 +1951,8 @@ * @param {Object} self */ SelectPage.prototype.unSelectAllLine = function(self){ - var p = self.option, ds = []; - self.elem.results.find('li').each(function(i, row){ + var p = self.option,size = self.elem.results.find('li').length, ds = []; + self.elem.results.find('li').each(function(i,row){ var key = $(row).attr('pkey'); var tag = self.elem.element_box.find('li.selected_tag[itemvalue="'+key+'"]'); if(tag.length) ds.push(tag.data('dataObj')); @@ -1954,35 +1964,35 @@ /** * Clear all selected items * @param {Object} self - * @param {boolean} open - open list after clear selected item + * @param {boolean} open - open list after clear selected item */ SelectPage.prototype.clearAll = function(self, open){ var p = self.option, ds = []; - if(p.multiple){ - self.elem.element_box.find('li.selected_tag').each(function(i, row){ - ds.push($(row).data('dataObj')); - row.remove(); - }); - self.elem.element_box.find('li.selected_tag').remove(); - } - self.reset(self); + if(p.multiple){ + self.elem.element_box.find('li.selected_tag').each(function(i, row){ + ds.push($(row).data('dataObj')); + row.remove(); + }); + self.elem.element_box.find('li.selected_tag').remove(); + } + self.reset(self); self.afterAction(self, open); - if(p.multiple) { - if (p.eTagRemove && $.isFunction(p.eTagRemove)) p.eTagRemove(ds); - }else self.elem.clear_btn.remove(); + if(p.multiple) { + if (p.eTagRemove && $.isFunction(p.eTagRemove)) p.eTagRemove(ds); + }else self.elem.clear_btn.remove(); }; - /** - * reset - */ + /** + * reset + */ SelectPage.prototype.reset = function(self){ - self.elem.combo_input.val(''); - self.elem.hidden.val(''); - self.prop.prev_value = ''; - self.prop.selected_text = ''; - self.prop.current_page = 1; - }; + self.elem.combo_input.val(''); + self.elem.hidden.val(''); + self.prop.prev_value = ''; + self.prop.selected_text = ''; + self.prop.current_page = 1; + }; /** * Get current highlight item @@ -1994,7 +2004,7 @@ if (obj.length) return obj; else return false; }; - + /** * Check the result item is already selected or not * @param {Object} self @@ -2011,11 +2021,11 @@ } return isExist; }; - + /** * Add a new tag in multiple selection mode * @param {Object} self - * @param {object} data - raw row data + * @param {object} data - raw row data * @param {Object} item */ SelectPage.prototype.addNewTag = function(self, data, item){ @@ -2038,7 +2048,7 @@ var keys = self.elem.hidden.val(); if($.type(key)!='undefined' && keys){ var keyarr = keys.split(','), - index = $.inArray(key.toString(),keyarr); + index = $.inArray(key.toString(),keyarr); if(index != -1){ keyarr.splice(index,1); self.elem.hidden.val(keyarr.toString()); @@ -2047,7 +2057,7 @@ $(item).remove(); self.inputResize(self); }; - + /** * Selected item value(keyField) put in to hidden element * @param {Object} self @@ -2066,18 +2076,19 @@ } } }; - + /** - * auto resize input element width in multiple select mode + * auto resize input element width in multiple select mode * @param {Object} self */ SelectPage.prototype.inputResize = function(self){ if(!self.option.multiple) return; - var inputLi = self.elem.combo_input.closest('li'); + var width = '', + inputLi = self.elem.combo_input.closest('li'); var setDefaultSize = function(self,inputLi){ inputLi.removeClass('full_width'); var minimumWidth = self.elem.combo_input.val().length + 1, - width = (minimumWidth * 0.75) + 'em'; + width = (minimumWidth * 0.75) + 'em'; self.elem.combo_input.css('width', width).removeAttr('placeholder'); }; if(self.elem.element_box.find('li.selected_tag').length === 0){ @@ -2109,7 +2120,7 @@ }; /** - * Move to previous line + * Move to previous line * @param {Object} self */ SelectPage.prototype.prevLine = function(self) { @@ -2145,8 +2156,8 @@ /** * Get plugin object - * @param {object} obj - * @returns + * @param {object} obj + * @returns */ function getPlugin(obj){ return $(obj).closest('div.sp_container').find('input.sp_input'); @@ -2160,18 +2171,18 @@ var $this = getPlugin(this), data = $this.data(SelectPage.dataKey); if(data){ - data.prop.init_set = true; - data.clearAll(data); - data.prop.init_set = false; - } + data.prop.init_set = true; + data.clearAll(data); + data.prop.init_set = false; + } }); } /** * Refresh result list - * use case: - * 1.use $(obj).val('xxx') to modify selectpage selected item key - * 2.refresh selected item show content/tag text + * use case: + * 1.use $(obj).val('xxx') to modify selectpage selected item key + * 2.refresh selected item show content/tag text */ function SelectedRefresh(){ return this.each(function(){ @@ -2181,7 +2192,7 @@ data.setInitRecord(true); }); } - + /** * Modify plugin datasource, only work on json datasource mode * @param {array} data - new datasource @@ -2201,24 +2212,24 @@ }); } - /** - * Get plugin disabled status or Modify plugin disabled status - * @param disabled {boolean} set disabled status - */ + /** + * Get plugin disabled status or Modify plugin disabled status + * @param disabled {boolean} set disabled status + */ function PluginDisabled(disabled){ - var status = false; - this.each(function(){ - var $this = getPlugin(this), - plugin = $this.data(SelectPage.dataKey); - if(plugin) { - if($.type(disabled) !== 'undefined') - plugin.disabled(plugin, disabled); - else - status = plugin.disabled(plugin); - } - }); - return status; - } + var status = false; + this.each(function(){ + var $this = getPlugin(this), + plugin = $this.data(SelectPage.dataKey); + if(plugin) { + if($.type(disabled) !== 'undefined') + plugin.disabled(plugin, disabled); + else + status = plugin.disabled(plugin); + } + }); + return status; + } /** * Get selected item text @@ -2229,17 +2240,19 @@ this.each(function(){ var $this = getPlugin(this),data = $this.data(SelectPage.dataKey); if(data){ - if(data.option.multiple){ - var tags = []; - data.elem.element_box.find('li.selected_tag').each(function(i, tag){ - tags.push($(tag).text()); - }); - str += tags.toString(); - }else str += data.elem.combo_input.val(); - } + if(data.option.multiple){ + var tags = []; + data.elem.element_box.find('li.selected_tag').each(function(i, tag){ + tags.push($(tag).text()); + }); + str += tags.toString(); + }else{ + str += data.elem.combo_input.val(); + } + } }); return str; - } + } var old = $.fn.selectPage; @@ -2250,7 +2263,7 @@ $.fn.selectPageData = ModifyDataSource; $.fn.selectPageDisabled = PluginDisabled; $.fn.selectPageText = GetInputText; - + // SelectPage no conflict // ================= $.fn.selectPage.noConflict = function () { diff --git a/selectpage.min.js b/selectpage.min.js index cbe8eb9..eb0ee26 100644 --- a/selectpage.min.js +++ b/selectpage.min.js @@ -1 +1,9 @@ -(function(g){var e={data:undefined,lang:"cn",multiple:false,pagination:true,dropButton:true,listSize:10,multipleControlbar:true,maxSelectLimit:0,selectToCloseList:false,initRecord:undefined,dbTable:"tbl",keyField:"id",showField:"name",searchField:undefined,andOr:"AND",orderBy:false,pageSize:10,params:undefined,formatItem:undefined,autoFillResult:false,autoSelectFirst:false,noResultClean:true,selectOnly:false,inputDelay:0.5,eSelect:undefined,eOpen:undefined,eAjaxSuccess:undefined,eTagRemove:undefined,eClear:undefined};var h=function(l,m){this.setOption(m);this.setLanguage();this.setCssClass();this.setProp();this.setElem(l);this.setButtonAttrDefault();this.setInitRecord();this.eDropdownButton();this.eInput();this.eWhole()};h.version="2.19";h.dataKey="selectPageObject";h.prototype.setOption=function(n){n.searchField=n.searchField||n.showField;n.andOr=n.andOr.toUpperCase();if(n.andOr!=="AND"&&n.andOr!=="OR"){n.andOr="AND"}var l=["searchField"];for(var m=0;m#item_text#',textKey:"#item_text#",valueKey:"#item_value#"},page:{current:"page_num",total:"page_count"},msg:{maxSelectLimit:"max_selected_limit"}}};h.prototype.elementRealSize=function(q,l){var p={absolute:false,clone:false,includeMargin:false,display:"block"};var t=p,o=q.eq(0),s,u,r=[],n="",m;s=function(){m=o.parents().addBack().filter(":hidden");n+="visibility: hidden !important; display: "+t.display+" !important; ";if(t.absolute===true){n+="position: absolute !important;"}m.each(function(){var w=g(this),x=w.attr("style");r.push(x);w.attr("style",x?x+";"+n:n)})};u=function(){m.each(function(w){var y=g(this),x=r[w];if(x===undefined){y.removeAttr("style")}else{y.attr("style",x)}})};s();var v=/(outer)/.test(l)?o[l](t.includeMargin):o[l]();u();return v};h.prototype.setElem=function(q){var o={},m=this.option,u=this.css_class,n=this.message,x=g(q);var s=x.outerWidth();if(s<=0){s=this.elementRealSize(x,"outerWidth")}if(s<150){s=150}o.combo_input=x.attr({"autocomplete":"off"}).addClass(u.input).wrap("
          ");if(m.selectOnly){o.combo_input.prop("readonly",true)}o.container=o.combo_input.parent().addClass(u.container);if(o.combo_input.prop("disabled")){if(m.multiple){o.container.addClass(u.disabled)}else{o.combo_input.addClass(u.input_off)}}o.container.width(s);o.button=g("
          ").addClass(u.button);o.dropdown=g('');o.clear_btn=g("
          ").html(g("").addClass("sp-iconfont if-close")).addClass(u.clear_btn).attr("title",n.clear);if(!m.dropButton){o.clear_btn.addClass(u.align_right)}o.element_box=g("
            ").addClass(u.element_box);if(m.multiple&&m.multipleControlbar){o.control=g("
            ").addClass(u.control_box)}o.result_area=g("
            ").addClass(u.re_area);if(m.pagination){o.navi=g("
            ").addClass("sp_pagination").append("
              ")}o.results=g("
                ").addClass(u.results);var l="_text",w=o.combo_input.attr("id")||o.combo_input.attr("name"),t=o.combo_input.attr("name")||"selectPage",v=t,r=w;o.hidden=g('').attr({name:v,id:r}).val("");o.combo_input.attr({name:t+l,id:w+l});o.container.append(o.hidden);if(m.dropButton){o.container.append(o.button);o.button.append(o.dropdown)}g(document.body).append(o.result_area);o.result_area.append(o.results);if(m.pagination){o.result_area.append(o.navi)}if(m.multiple){if(m.multipleControlbar){o.control.append('');o.control.append('');o.control.append('');o.control_text=g("

                ");o.control.append(o.control_text);o.result_area.prepend(o.control)}o.container.addClass("sp_container_combo");o.combo_input.addClass("sp_combo_input").before(o.element_box);var y=g("

              • ").addClass("input_box");y.append(o.combo_input);o.element_box.append(y);if(o.combo_input.attr("placeholder")){o.combo_input.attr("placeholder_bak",o.combo_input.attr("placeholder"))}}this.elem=o};h.prototype.setButtonAttrDefault=function(){if(this.option.dropButton){this.elem.button.attr("title",this.message.close_btn)}};h.prototype.setInitRecord=function(o){var l=this,s=l.option,n=l.elem,m="";if(g.type(n.combo_input.data("init"))!="undefined"){s.initRecord=String(n.combo_input.data("init"))}if(!o&&!s.initRecord&&n.combo_input.val()){s.initRecord=n.combo_input.val()}n.combo_input.val("");if(!o){n.hidden.val(s.initRecord)}m=o&&n.hidden.val()?n.hidden.val():s.initRecord;if(m){if(typeof s.data==="object"){var r=new Array();var q=m.split(",");g.each(q,function(p,u){for(var t=0;t1){r=[r[0]]}l.afterInit(l,r)}else{g.ajax({dataType:"json",type:"POST",url:s.data,data:{searchTable:s.dbTable,searchKey:s.keyField,searchValue:m},success:function(p){var t=null;if(s.eAjaxSuccess&&g.isFunction(s.eAjaxSuccess)){t=s.eAjaxSuccess(p)}l.afterInit(l,t.list)},error:function(){l.ajaxErrorNotify(l)}})}}};h.prototype.afterInit=function(m,o){if(!o||(g.isArray(o)&&o.length===0)){return}if(!g.isArray(o)){o=[o]}var q=m.option,n=m.css_class;var l=function(t){var s=t[q.showField];if(q.formatItem&&g.isFunction(q.formatItem)){try{s=q.formatItem(t)}catch(p){}}return s};if(q.multiple){m.prop.init_set=true;m.clearAll(m);g.each(o,function(p,t){var s={text:l(t),value:t[q.keyField]};if(!m.isAlreadySelected(m,s)){m.addNewTag(m,t,s)}});m.tagValuesSet(m);m.inputResize(m);m.prop.init_set=false}else{var r=o[0];m.elem.combo_input.val(l(r));m.elem.hidden.val(r[q.keyField]);m.prop.prev_value=l(r);m.prop.selected_text=l(r);if(q.selectOnly){m.elem.combo_input.attr("title",m.message.select_ok).removeClass(n.select_ng).addClass(n.select_ok)}m.putClearButton()}};h.prototype.eDropdownButton=function(){var l=this;if(l.option.dropButton){l.elem.button.mouseup(function(m){m.stopPropagation();if(l.elem.result_area.is(":hidden")&&!l.elem.combo_input.prop("disabled")){l.elem.combo_input.focus()}else{l.hideResults(l)}})}};h.prototype.eInput=function(){var m=this,o=m.option,n=m.elem,q=m.message;var l=function(){m.prop.page_move=false;m.suggest(m);m.setCssFocusedInput(m)};n.combo_input.keyup(function(p){m.processKey(m,p)}).keydown(function(p){m.processControl(m,p)}).focus(function(p){if(n.result_area.is(":hidden")){p.stopPropagation();m.prop.first_show=true;l()}});n.container.on("click.SelectPage","div."+m.css_class.clear_btn,function(p){p.stopPropagation();if(!m.disabled(m)){m.clearAll(m,true);if(o.eClear&&g.isFunction(o.eClear)){o.eClear(m)}}});n.result_area.on("mousedown.SelectPage",function(p){p.stopPropagation()});if(o.multiple){if(o.multipleControlbar){n.control.find(".sp_select_all").on("click.SelectPage",function(){m.selectAllLine(m)}).hover(function(){n.control_text.html(q.select_all)},function(){n.control_text.html("")});n.control.find(".sp_unselect_all").on("click.SelectPage",function(){m.unSelectAllLine(m)}).hover(function(){n.control_text.html(q.unselect_all)},function(){n.control_text.html("")});n.control.find(".sp_clear_all").on("click.SelectPage",function(){m.clearAll(m,true)}).hover(function(){n.control_text.html(q.clear_all)},function(){n.control_text.html("")})}n.element_box.on("click.SelectPage",function(r){var p=r.target||r.srcElement;if(g(p).is("ul")){n.combo_input.focus()}});n.element_box.on("click.SelectPage","span.tag_close",function(){var p=g(this).closest("li"),r=p.data("dataObj");m.removeTag(m,p);l();if(o.eTagRemove&&g.isFunction(o.eTagRemove)){o.eTagRemove([r])}});m.inputResize(m)}};h.prototype.eWhole=function(){var l=this,m=l.css_class;var n=function(o){o.elem.combo_input.val("");if(!o.option.multiple){o.elem.hidden.val("")}o.prop.selected_text=""};g(document.body).off("mousedown.selectPage").on("mousedown.selectPage",function(q){var p=q.target||q.srcElement;var o=g(p).closest("div."+m.container);g("div."+m.container+"."+m.container_open).each(function(){if(this==o[0]){return}var r=g(this),s=r.find("input."+m.input).data(h.dataKey);if(!s.elem.combo_input.val()&&s.elem.hidden.val()&&!s.option.multiple){s.prop.current_page=1;n(s);s.hideResults(s);return true}if(s.elem.results.find("li").not("."+m.message_box).length){if(s.option.autoFillResult){if(s.elem.hidden.val()){s.hideResults(s)}else{if(s.elem.results.find("li.sp_over").length){s.selectCurrentLine(s)}else{if(s.option.autoSelectFirst){s.nextLine(s);s.selectCurrentLine(s)}else{s.hideResults(s)}}}}else{s.hideResults(s)}}else{if(s.option.noResultClean){n(s)}else{if(!s.option.multiple){s.elem.hidden.val("")}}s.hideResults(s)}})})};h.prototype.eResultList=function(){var l=this,m=this.css_class;l.elem.results.children("li").hover(function(){if(l.prop.key_select){l.prop.key_select=false;return}if(!g(this).hasClass(m.selected)&&!g(this).hasClass(m.message_box)){g(this).addClass(m.select);l.setCssFocusedResults(l)}},function(){g(this).removeClass(m.select)}).click(function(n){if(l.prop.key_select){l.prop.key_select=false;return}n.preventDefault();n.stopPropagation();if(!g(this).hasClass(m.selected)){l.selectCurrentLine(l)}})};h.prototype.eScroll=function(){var l=this.css_class;g(window).on("scroll.SelectPage",function(){g("div."+l.container+"."+l.container_open).each(function(){var t=g(this),s=t.find("input."+l.input).data(h.dataKey),r=s.elem.result_area.offset(),q=g(window).scrollTop(),v=g(document).height(),o=g(window).height(),n=s.elem.result_area.outerHeight(),m=r.top+n,p=v>o,u=s.elem.result_area.hasClass("shadowDown");if(p){if(u){if(m>(o+q)){s.calcResultsSize(s)}}else{if(r.top '+n+"
              • ";l.elem.results.empty().append(m).show();l.calcResultsSize(l);l.setOpenStatus(l,true);l.elem.control.hide();if(l.option.pagination){l.elem.navi.hide()}};h.prototype.scrollWindow=function(t,q){var l=t.getCurrentLine(t),s=(l&&!q)?l.offset().top:t.elem.container.offset().top,n;t.prop.size_li=t.elem.results.children("li:first").outerHeight();n=t.prop.size_li;var r,p=g(window).height(),o=g(window).scrollTop(),m=o+p-n;if(l.length){if(sp){r=s-o}else{if(s>m){r=s-m}else{return}}}else{if(s-1&&l.elem.result_area.is(":visible"))||(g.inArray(m.keyCode,[13,9])>-1&&l.getCurrentLine(l))){m.preventDefault();m.stopPropagation();m.cancelBubble=true;m.returnValue=false;switch(m.keyCode){case 37:if(m.shiftKey){l.firstPage(l)}else{l.prevPage(l)}break;case 38:l.prop.key_select=true;l.prevLine(l);break;case 39:if(m.shiftKey){l.lastPage(l)}else{l.nextPage(l)}break;case 40:if(l.elem.results.children("li").length){l.prop.key_select=true;l.nextLine(l)}else{l.suggest(l)}break;case 9:l.prop.key_paging=true;l.selectCurrentLine(l);break;case 13:l.selectCurrentLine(l);break;case 27:l.prop.key_paging=true;l.hideResults(l);break}}};h.prototype.abortAjax=function(l){if(l.prop.xhr){l.prop.xhr.abort();l.prop.xhr=false}};h.prototype.suggest=function(m){var n,o=g.trim(m.elem.combo_input.val());if(m.option.multiple){n=o}else{if(o&&o===m.prop.selected_text){n=""}else{n=o}}n=n.split(/[\s ]+/);if(m.option.eOpen&&g.isFunction(m.option.eOpen)){m.option.eOpen.call(m)}m.abortAjax(m);var l=m.prop.current_page||1;if(typeof m.option.data=="object"){m.searchForJson(m,n,l)}else{m.searchForDb(m,n,l)}};h.prototype.setLoading=function(l){if(l.elem.results.html()===""){l.setOpenStatus(l,true)}};h.prototype.searchForDb=function(t,q,s){var m=t.option;if(!m.eAjaxSuccess||!g.isFunction(m.eAjaxSuccess)){t.hideResults(t)}var n=m.params,r={},o=m.searchField;if(q.length&&q[0]&&q[0]!==t.prop.prev_value){s=1}var l={q_word:q,pageNumber:s,pageSize:m.pageSize,andOr:m.andOr,searchTable:m.dbTable};if(m.orderBy!==false){l.orderBy=m.orderBy}l[o]=q[0];if(n&&g.isFunction(n)){var u=n.call(t);if(u&&g.isPlainObject(u)){r=g.extend({},l,u)}else{r=l}}else{r=l}t.prop.xhr=g.ajax({dataType:"json",url:m.data,type:"POST",data:r,success:function(x){if(!x||!g.isPlainObject(x)){t.hideResults(t);t.ajaxErrorNotify(t);return}var y={},w={};try{y=m.eAjaxSuccess(x);w.originalResult=y.list;w.cnt_whole=y.totalRow}catch(z){t.showMessage(t,t.message.ajax_error);return}w.candidate=[];w.keyField=[];if(typeof w.originalResult!="object"){t.prop.xhr=null;t.notFoundSearch(t);return}w.cnt_page=w.originalResult.length;for(var v=0;v ');C.append('
              • ');C.append('
              • '+G()+"
              • ");C.append('
              • ');C.append('
              • ');C.show()}else{C.find("li.pageInfoBox a").html(G())}};var t=x.elem.navi.find("ul"),r=Math.ceil(v/x.option.pageSize);if(r===0){l=0}else{if(r1){x.ePaging()}};h.prototype.displayResults=function(A,z,s){var l=A.option,n=A.elem;n.results.hide().empty();if(l.multiple&&g.type(l.maxSelectLimit)==="number"&&l.maxSelectLimit>0){var q=n.element_box.find("li.selected_tag").length;if(q>0&&q>=l.maxSelectLimit){var o=A.message.max_selected;A.showMessage(A,o.replace(A.template.msg.maxSelectLimit,l.maxSelectLimit));return}}if(z.candidate.length){var y=z.candidate,w=z.keyField,m=n.hidden.val(),B=m?m.split(","):new Array(),v="";for(var r=0;r").html(v).attr({pkey:w[r]});if(!l.formatItem){t.attr("title",v)}if(g.inArray(w[r].toString(),B)!==-1){t.addClass(A.css_class.selected)}t.data("dataObj",z.originalResult[r]);n.results.append(t)}}else{var x='
              • '+A.message.not_found+"
              • ";n.results.append(x)}n.results.show();if(l.multiple&&l.multipleControlbar){n.control.show()}if(l.pagination){n.navi.show()}A.calcResultsSize(A);A.setOpenStatus(A,true);A.eResultList();A.eScroll();if(s&&z.candidate.length&&l.autoSelectFirst){A.nextLine(A)}};h.prototype.calcResultsSize=function(m){var q=m.option,n=m.elem;var l=function(){if(n.container.css("position")==="static"){var F=n.combo_input.offset();n.result_area.css({top:F.top+n.combo_input.outerHeight()+"px",left:F.left+"px"})}else{var v;if(!q.pagination){var x=n.results.find("li:first").outerHeight(true);v=x*q.listSize;n.results.css({"max-height":v,"overflow-y":"auto"})}var B=g(document).width(),G=g(document).height(),w=g(window).height(),A=n.container.offset(),z=g(window).scrollTop(),E=n.result_area.outerWidth(),r=A.left,p=n.container.outerHeight(),u=(A.left+E)>B?r-(E-n.container.outerWidth()):r,t=A.top,D=0,C=5,s=t+p+v+C,y=G>w;v=n.result_area.outerHeight();if((t-z-C>v)&&(y&&s>(w+z))||(!y&&s>w)){D=A.top-v-C;n.result_area.removeClass("shadowUp shadowDown").addClass("shadowUp")}else{D=A.top+(q.multiple?n.container.outerHeight():p);n.result_area.removeClass("shadowUp shadowDown").addClass("shadowDown");D+=C}return{top:D+"px",left:u+"px"}}};if(n.result_area.is(":visible")){n.result_area.css(l())}else{var o=l();n.result_area.css(o).show(1,function(){var p=l();if(o.top!==p.top||o.left!==p.left){n.result_area.css(p)}})}};h.prototype.hideResults=function(l){if(l.prop.key_paging){l.scrollWindow(l,true);l.prop.key_paging=false}l.setCssFocusedInput(l);if(l.option.autoFillResult){}l.elem.results.empty();l.elem.result_area.hide();l.setOpenStatus(l,false);g(window).off("scroll.SelectPage");l.abortAjax(l);l.setButtonAttrDefault()};h.prototype.disabled=function(l,n){var m=l.elem;if(g.type(n)==="undefined"){return m.combo_input.prop("disabled")}if(g.type(n)==="boolean"){m.combo_input.prop("disabled",n);if(n){m.container.addClass(l.css_class.disabled)}else{m.container.removeClass(l.css_class.disabled)}}};h.prototype.firstPage=function(l){if(l.prop.current_page>1){l.prop.current_page=1;l.prop.page_move=true;l.suggest(l)}};h.prototype.prevPage=function(l){if(l.prop.current_page>1){l.prop.current_page--;l.prop.page_move=true;l.suggest(l)}};h.prototype.nextPage=function(l){if(l.prop.current_page0&&n.maxSelectLimit===l.elem.element_box.find("li.selected_tag").length){return false}});if(n.eSelect&&g.isFunction(n.eSelect)){n.eSelect(m,l)}l.afterAction(l,true)};h.prototype.unSelectAllLine=function(l){var n=l.option,m=[];l.elem.results.find("li").each(function(q,r){var p=g(r).attr("pkey");var o=l.elem.element_box.find('li.selected_tag[itemvalue="'+p+'"]');if(o.length){m.push(o.data("dataObj"))}l.removeTag(l,o)});l.afterAction(l,true);if(n.eTagRemove&&g.isFunction(n.eTagRemove)){n.eTagRemove(m)}};h.prototype.clearAll=function(l,m){var o=l.option,n=[];if(o.multiple){l.elem.element_box.find("li.selected_tag").each(function(p,q){n.push(g(q).data("dataObj"));q.remove()});l.elem.element_box.find("li.selected_tag").remove()}l.reset(l);l.afterAction(l,m);if(o.multiple){if(o.eTagRemove&&g.isFunction(o.eTagRemove)){o.eTagRemove(n)}}else{l.elem.clear_btn.remove()}};h.prototype.reset=function(l){l.elem.combo_input.val("");l.elem.hidden.val("");l.prop.prev_value="";l.prop.selected_text="";l.prop.current_page=1};h.prototype.getCurrentLine=function(l){if(l.elem.result_area.is(":hidden")){return false}var m=l.elem.results.find("li."+l.css_class.select);if(m.length){return m}else{return false}};h.prototype.isAlreadySelected=function(l,n){var o=false;if(n.value){var m=l.elem.hidden.val();if(m){var p=m.split(",");if(p&&p.length&&g.inArray(n.value,p)!=-1){o=true}}}return o};h.prototype.addNewTag=function(m,p,o){if(!m.option.multiple||!p||!o){return}var n=m.template.tag.content,l;n=n.replace(m.template.tag.textKey,o.text);n=n.replace(m.template.tag.valueKey,o.value);l=g(n);l.data("dataObj",p);if(m.elem.combo_input.prop("disabled")){l.find("span.tag_close").hide()}m.elem.combo_input.closest("li").before(l)};h.prototype.removeTag=function(l,q){var n=g(q).attr("itemvalue");var p=l.elem.hidden.val();if(g.type(n)!="undefined"&&p){var o=p.split(","),m=g.inArray(n.toString(),o);if(m!=-1){o.splice(m,1);l.elem.hidden.val(o.toString())}}g(q).remove();l.inputResize(l)};h.prototype.tagValuesSet=function(m){if(!m.option.multiple){return}var n=m.elem.element_box.find("li.selected_tag");if(n&&n.length){var l=new Array();g.each(n,function(q,o){var p=g(o).attr("itemvalue");if(g.type(p)!=="undefined"){l.push(p)}});if(l.length){m.elem.hidden.val(l.join(","))}}};h.prototype.inputResize=function(l){if(!l.option.multiple){return}var m=l.elem.combo_input.closest("li");var n=function(o,p){p.removeClass("full_width");var r=o.elem.combo_input.val().length+1,q=(r*0.75)+"em";o.elem.combo_input.css("width",q).removeAttr("placeholder")};if(l.elem.element_box.find("li.selected_tag").length===0){if(l.elem.combo_input.attr("placeholder_bak")){if(!m.hasClass("full_width")){m.addClass("full_width")}l.elem.combo_input.attr("placeholder",l.elem.combo_input.attr("placeholder_bak")).removeAttr("style")}else{n(l,m)}}else{n(l,m)}};h.prototype.nextLine=function(m){var o=m.getCurrentLine(m),l;if(!o){l=-1}else{l=m.elem.results.children("li").index(o);o.removeClass(m.css_class.select)}l++;if(l-1){var n=m.elem.results.children("li").eq(l);n.addClass(m.css_class.select);m.setCssFocusedResults(m)}else{m.setCssFocusedInput(m)}m.scrollWindow(m,false)};function j(l){return this.each(function(){var n=g(this),m=n.data(h.dataKey),o=g.extend({},e,n.data(),m&&m.option,typeof l==="object"&&l);if(!m){n.data(h.dataKey,(m=new h(this,o)))}})}function a(l){return g(l).closest("div.sp_container").find("input.sp_input")}function b(){return this.each(function(){var m=a(this),l=m.data(h.dataKey);if(l){l.prop.init_set=true;l.clearAll(l);l.prop.init_set=false}})}function f(){return this.each(function(){var m=a(this),l=m.data(h.dataKey);if(l&&l.elem.hidden.val()){l.setInitRecord(true)}})}function c(l){return this.each(function(){if(l&&g.isArray(l)){var n=a(this),m=n.data(h.dataKey);if(m){m.clearAll(m);m.option.data=l}}})}function k(m){var l=false;this.each(function(){var o=a(this),n=o.data(h.dataKey);if(n){if(g.type(m)!=="undefined"){n.disabled(n,m)}else{l=n.disabled(n)}}});return l}function i(){var l="";this.each(function(){var o=a(this),n=o.data(h.dataKey);if(n){if(n.option.multiple){var m=[];n.elem.element_box.find("li.selected_tag").each(function(q,p){m.push(g(p).text())});l+=m.toString()}else{l+=n.elem.combo_input.val()}}});return l}var d=g.fn.selectPage;g.fn.selectPage=j;g.fn.selectPage.Constructor=h;g.fn.selectPageClear=b;g.fn.selectPageRefresh=f;g.fn.selectPageData=c;g.fn.selectPageDisabled=k;g.fn.selectPageText=i;g.fn.selectPage.noConflict=function(){g.fn.selectPage=d;return this}})(window.jQuery); \ No newline at end of file +(function($){var defaults={data:undefined,lang:"cn",multiple:false,pagination:true,dropButton:true,listSize:10,multipleControlbar:true,maxSelectLimit:0,selectToCloseList:false,initRecord:undefined,dbTable:"tbl",keyField:"id",showField:"name",searchField:undefined,andOr:"AND",orderBy:false,pageSize:10,params:undefined,formatItem:undefined,autoFillResult:false,autoSelectFirst:false,noResultClean:true,selectOnly:false,inputDelay:0.5,eSelect:undefined,eOpen:undefined,eAjaxSuccess:undefined,eTagRemove:undefined,eClear:undefined};var SelectPage=function(input,option){this.setOption(option);this.setLanguage();this.setCssClass();this.setProp();this.setElem(input);this.setButtonAttrDefault();this.setInitRecord();this.eDropdownButton();this.eInput();this.eWhole()};SelectPage.version="2.19";SelectPage.dataKey="selectPageObject";SelectPage.prototype.setOption=function(option){option.searchField=option.searchField||option.showField;option.andOr=option.andOr.toUpperCase();if(option.andOr!=="AND"&&option.andOr!=="OR"){option.andOr="AND"}var arr=["searchField"];for(var i=0;i#item_text#',textKey:"#item_text#",valueKey:"#item_value#"},page:{current:"page_num",total:"page_count"},msg:{maxSelectLimit:"max_selected_limit"}}};SelectPage.prototype.elementRealSize=function(element,method){var defaults={absolute:false,clone:false,includeMargin:false,display:"block"};var configs=defaults,$target=element.eq(0),fix,restore,tmp=[],style="",$hidden;fix=function(){$hidden=$target.parents().addBack().filter(":hidden");style+="visibility: hidden !important; display: "+configs.display+" !important; ";if(configs.absolute===true){style+="position: absolute !important;"}$hidden.each(function(){var $this=$(this),thisStyle=$this.attr("style");tmp.push(thisStyle);$this.attr("style",thisStyle?thisStyle+";"+style:style)})};restore=function(){$hidden.each(function(i){var $this=$(this),_tmp=tmp[i];if(_tmp===undefined){$this.removeAttr("style")}else{$this.attr("style",_tmp)}})};fix();var actual=/(outer)/.test(method)?$target[method](configs.includeMargin):$target[method]();restore();return actual};SelectPage.prototype.setElem=function(combo_input){var elem={},p=this.option,css=this.css_class,msg=this.message,input=$(combo_input);var orgWidth=input.outerWidth();if(orgWidth<=0){orgWidth=this.elementRealSize(input,"outerWidth")}if(orgWidth<150){orgWidth=150}elem.combo_input=input.attr({"autocomplete":"off"}).addClass(css.input).wrap("
                ");if(p.selectOnly){elem.combo_input.prop("readonly",true)}elem.container=elem.combo_input.parent().addClass(css.container);if(elem.combo_input.prop("disabled")){if(p.multiple){elem.container.addClass(css.disabled)}else{elem.combo_input.addClass(css.input_off)}}elem.container.width(orgWidth);elem.button=$("
                ").addClass(css.button);elem.dropdown=$('');elem.clear_btn=$("
                ").html($("").addClass("sp-iconfont if-close")).addClass(css.clear_btn).attr("title",msg.clear);if(!p.dropButton){elem.clear_btn.addClass(css.align_right)}elem.element_box=$("
                  ").addClass(css.element_box);if(p.multiple&&p.multipleControlbar){elem.control=$("
                  ").addClass(css.control_box)}if(orgWidth>300){elem.result_area=$('
                  ').addClass(css.re_area)}else{elem.result_area=$("
                  ").addClass(css.re_area)}if(p.pagination){elem.navi=$("
                  ").addClass("sp_pagination").append("
                    ")}elem.results=$("
                      ").addClass(css.results);var namePrefix="_text",input_id=elem.combo_input.attr("id")||elem.combo_input.attr("name"),input_name=elem.combo_input.attr("name")||"selectPage",hidden_name=input_name,hidden_id=input_id;elem.hidden=$('').attr({name:hidden_name,id:hidden_id}).val(""); + elem.combo_input.attr({name:input_name+namePrefix,id:input_id+namePrefix});elem.container.append(elem.hidden);if(p.dropButton){elem.container.append(elem.button);elem.button.append(elem.dropdown)}$(document.body).append(elem.result_area);elem.result_area.append(elem.results);if(p.pagination){elem.result_area.append(elem.navi)}if(p.multiple){if(p.multipleControlbar){elem.control.append('');elem.control.append('');elem.control.append('');elem.control_text=$("

                      ");elem.control.append(elem.control_text);elem.result_area.prepend(elem.control)}elem.container.addClass("sp_container_combo");elem.combo_input.addClass("sp_combo_input").before(elem.element_box);var li=$("

                    • ").addClass("input_box");li.append(elem.combo_input);elem.element_box.append(li);if(elem.combo_input.attr("placeholder")){elem.combo_input.attr("placeholder_bak",elem.combo_input.attr("placeholder"))}}this.elem=elem};SelectPage.prototype.setButtonAttrDefault=function(){if(this.option.dropButton){this.elem.button.attr("title",this.message.close_btn)}};SelectPage.prototype.setInitRecord=function(refresh){var self=this,p=self.option,el=self.elem,key="";if($.type(el.combo_input.data("init"))!="undefined"){p.initRecord=String(el.combo_input.data("init"))}if(!refresh&&!p.initRecord&&el.combo_input.val()){p.initRecord=el.combo_input.val()}el.combo_input.val("");if(!refresh){el.hidden.val(p.initRecord)}key=refresh&&el.hidden.val()?el.hidden.val():p.initRecord;if(key){if(typeof p.data==="object"){var data=new Array();var keyarr=key.split(",");$.each(keyarr,function(index,row){for(var i=0;i1){data=[data[0]]}self.afterInit(self,data)}else{$.ajax({dataType:"json",type:"POST",url:p.data,data:{searchTable:p.dbTable,searchKey:p.keyField,searchValue:key},success:function(json){var d=null;if(p.eAjaxSuccess&&$.isFunction(p.eAjaxSuccess)){d=p.eAjaxSuccess(json)}self.afterInit(self,d.list)},error:function(jqXHR,textStatus,errorThrown){self.ajaxErrorNotify(self,errorThrown)}})}}};SelectPage.prototype.afterInit=function(self,data){if(!data||($.isArray(data)&&data.length===0)){return}if(!$.isArray(data)){data=[data]}var p=self.option,css=self.css_class;var getText=function(row){var text=row[p.showField];if(p.formatItem&&$.isFunction(p.formatItem)){try{text=p.formatItem(row)}catch(e){}}return text};if(p.multiple){self.prop.init_set=true;self.clearAll(self);$.each(data,function(i,row){var item={text:getText(row),value:row[p.keyField]};if(!self.isAlreadySelected(self,item)){self.addNewTag(self,row,item)}});self.tagValuesSet(self);self.inputResize(self);self.prop.init_set=false}else{var row=data[0];self.elem.combo_input.val(getText(row));self.elem.hidden.val(row[p.keyField]);self.prop.prev_value=getText(row);self.prop.selected_text=getText(row);if(p.selectOnly){self.elem.combo_input.attr("title",self.message.select_ok).removeClass(css.select_ng).addClass(css.select_ok)}self.putClearButton()}};SelectPage.prototype.eDropdownButton=function(){var self=this;if(self.option.dropButton){self.elem.button.mouseup(function(ev){ev.stopPropagation();if(self.elem.result_area.is(":hidden")&&!self.elem.combo_input.prop("disabled")){self.elem.combo_input.focus()}else{self.hideResults(self)}})}};SelectPage.prototype.eInput=function(){var self=this,p=self.option,el=self.elem,msg=self.message;var showList=function(){self.prop.page_move=false;self.suggest(self);self.setCssFocusedInput(self)};el.combo_input.keyup(function(e){self.processKey(self,e)}).keydown(function(e){self.processControl(self,e)}).focus(function(e){if(el.result_area.is(":hidden")){e.stopPropagation();self.prop.first_show=true;showList()}});el.container.on("click.SelectPage","div."+self.css_class.clear_btn,function(e){e.stopPropagation();if(!self.disabled(self)){self.clearAll(self,true);if(p.eClear&&$.isFunction(p.eClear)){p.eClear(self)}}});el.result_area.on("mousedown.SelectPage",function(e){e.stopPropagation()});if(p.multiple){if(p.multipleControlbar){el.control.find(".sp_select_all").on("click.SelectPage",function(e){self.selectAllLine(self)}).hover(function(){el.control_text.html(msg.select_all)},function(){el.control_text.html("")});el.control.find(".sp_unselect_all").on("click.SelectPage",function(e){self.unSelectAllLine(self)}).hover(function(){el.control_text.html(msg.unselect_all)},function(){el.control_text.html("")});el.control.find(".sp_clear_all").on("click.SelectPage",function(e){self.clearAll(self,true)}).hover(function(){el.control_text.html(msg.clear_all)},function(){el.control_text.html("")})}el.element_box.on("click.SelectPage",function(e){var srcEl=e.target||e.srcElement;if($(srcEl).is("ul")){el.combo_input.focus() +}});el.element_box.on("click.SelectPage","span.tag_close",function(){var li=$(this).closest("li"),data=li.data("dataObj");self.removeTag(self,li);showList();if(p.eTagRemove&&$.isFunction(p.eTagRemove)){p.eTagRemove([data])}});self.inputResize(self)}};SelectPage.prototype.eWhole=function(){var self=this,css=self.css_class;var cleanContent=function(obj){obj.elem.combo_input.val("");if(!obj.option.multiple){obj.elem.hidden.val("")}obj.prop.selected_text=""};$(document.body).off("mousedown.selectPage").on("mousedown.selectPage",function(e){var ele=e.target||e.srcElement;var sp=$(ele).closest("div."+css.container);$("div."+css.container+"."+css.container_open).each(function(){if(this==sp[0]){return}var $this=$(this),d=$this.find("input."+css.input).data(SelectPage.dataKey);if(!d.elem.combo_input.val()&&d.elem.hidden.val()&&!d.option.multiple){d.prop.current_page=1;cleanContent(d);d.hideResults(d);return true}if(d.elem.results.find("li").not("."+css.message_box).length){if(d.option.autoFillResult){if(d.elem.hidden.val()){d.hideResults(d)}else{if(d.elem.results.find("li.sp_over").length){d.selectCurrentLine(d,true)}else{if(d.option.autoSelectFirst){d.nextLine(d);d.selectCurrentLine(d,true)}else{d.hideResults(d)}}}}else{d.hideResults(d)}}else{if(d.option.noResultClean){cleanContent(d)}else{if(!d.option.multiple){d.elem.hidden.val("")}}d.hideResults(d)}})})};SelectPage.prototype.eResultList=function(){var self=this,css=this.css_class;self.elem.results.children("li").hover(function(){if(self.prop.key_select){self.prop.key_select=false;return}if(!$(this).hasClass(css.selected)&&!$(this).hasClass(css.message_box)){$(this).addClass(css.select);self.setCssFocusedResults(self)}},function(){$(this).removeClass(css.select)}).click(function(e){if(self.prop.key_select){self.prop.key_select=false;return}e.preventDefault();e.stopPropagation();if(!$(this).hasClass(css.selected)){self.selectCurrentLine(self,false)}})};SelectPage.prototype.eScroll=function(){var self=this,css=this.css_class;$(window).on("scroll.SelectPage",function(e){$("div."+css.container+"."+css.container_open).each(function(){var $this=$(this),d=$this.find("input."+css.input).data(SelectPage.dataKey),offset=d.elem.result_area.offset(),screenScrollTop=$(window).scrollTop(),docHeight=$(document).height(),viewHeight=$(window).height(),listHeight=d.elem.result_area.outerHeight(),listBottom=offset.top+listHeight,hasOverflow=docHeight>viewHeight,down=d.elem.result_area.hasClass("shadowDown");if(hasOverflow){if(down){if(listBottom>(viewHeight+screenScrollTop)){d.calcResultsSize(d)}}else{if(offset.top '+msg+"
                    • ";self.elem.results.empty().append(msgLi).show();self.calcResultsSize(self);self.setOpenStatus(self,true);self.elem.control.hide();if(self.option.pagination){self.elem.navi.hide()}};SelectPage.prototype.scrollWindow=function(self,enforce){var current_result=self.getCurrentLine(self),target_top=(current_result&&!enforce)?current_result.offset().top:self.elem.container.offset().top,target_size;self.prop.size_li=self.elem.results.children("li:first").outerHeight();target_size=self.prop.size_li;var gap,client_height=$(window).height(),scroll_top=$(window).scrollTop(),scroll_bottom=scroll_top+client_height-target_size;if(current_result.length){if(target_topclient_height){gap=target_top-scroll_top}else{if(target_top>scroll_bottom){gap=target_top-scroll_bottom}else{return}}}else{if(target_top-1&&self.elem.result_area.is(":visible"))||($.inArray(e.keyCode,[13,9])>-1&&self.getCurrentLine(self))){e.preventDefault();e.stopPropagation();e.cancelBubble=true;e.returnValue=false;switch(e.keyCode){case 37:if(e.shiftKey){self.firstPage(self)}else{self.prevPage(self)}break;case 38:self.prop.key_select=true;self.prevLine(self);break;case 39:if(e.shiftKey){self.lastPage(self)}else{self.nextPage(self)}break;case 40:if(self.elem.results.children("li").length){self.prop.key_select=true;self.nextLine(self)}else{self.suggest(self)}break;case 9:self.prop.key_paging=true;self.selectCurrentLine(self,true);break;case 13:self.selectCurrentLine(self,true);break;case 27:self.prop.key_paging=true;self.hideResults(self);break}}};SelectPage.prototype.abortAjax=function(self){if(self.prop.xhr){self.prop.xhr.abort();self.prop.xhr=false}};SelectPage.prototype.suggest=function(self){var q_word,val=$.trim(self.elem.combo_input.val());if(self.option.multiple){q_word=val}else{if(val&&val===self.prop.selected_text){q_word=""}else{q_word=val}}q_word=q_word.split(/[\s ]+/);if(self.option.eOpen&&$.isFunction(self.option.eOpen)){self.option.eOpen.call(self)}self.abortAjax(self);var which_page_num=self.prop.current_page||1;if(typeof self.option.data=="object"){self.searchForJson(self,q_word,which_page_num)}else{self.searchForDb(self,q_word,which_page_num)}};SelectPage.prototype.setLoading=function(self){if(self.elem.results.html()===""){self.setOpenStatus(self,true)}};SelectPage.prototype.searchForDb=function(self,q_word,which_page_num){var p=self.option;if(!p.eAjaxSuccess||!$.isFunction(p.eAjaxSuccess)){self.hideResults(self)}var _paramsFunc=p.params,_params={},searchKey=p.searchField;if(q_word.length&&q_word[0]&&q_word[0]!==self.prop.prev_value){which_page_num=1}var _orgParams={q_word:q_word,pageNumber:which_page_num,pageSize:p.pageSize,andOr:p.andOr,searchTable:p.dbTable};if(p.orderBy!==false){_orgParams.orderBy=p.orderBy}_orgParams[searchKey]=q_word[0];if(_paramsFunc&&$.isFunction(_paramsFunc)){var result=_paramsFunc.call(self);if(result&&$.isPlainObject(result)){_params=$.extend({},_orgParams,result)}else{_params=_orgParams}}else{_params=_orgParams}self.prop.xhr=$.ajax({dataType:"json",url:p.data,type:"POST",data:_params,success:function(returnData){if(!returnData||!$.isPlainObject(returnData)){self.hideResults(self);self.ajaxErrorNotify(self,errorThrown);return}var data={},json={};try{data=p.eAjaxSuccess(returnData);json.originalResult=data.list;json.cnt_whole=data.totalRow}catch(e){self.showMessage(self,self.message.ajax_error);return}json.candidate=[];json.keyField=[];if(typeof json.originalResult!="object"){self.prop.xhr=null;self.notFoundSearch(self);return}json.cnt_page=json.originalResult.length;for(var i=0;i ');pagebar.append('
                    • ');pagebar.append('
                    • '+updatePageInfo()+"
                    • ");pagebar.append('
                    • ');pagebar.append('
                    • ');pagebar.show()}else{pagebar.find("li.pageInfoBox a").html(updatePageInfo())}};var pagebar=self.elem.navi.find("ul"),last_page=Math.ceil(cnt_whole/self.option.pageSize);if(last_page===0){page_num=0}else{if(last_page1){self.ePaging()}};SelectPage.prototype.displayResults=function(self,json,is_query){var p=self.option,el=self.elem;el.results.hide().empty();if(p.multiple&&$.type(p.maxSelectLimit)==="number"&&p.maxSelectLimit>0){var selectedSize=el.element_box.find("li.selected_tag").length; + if(selectedSize>0&&selectedSize>=p.maxSelectLimit){var msg=self.message.max_selected;self.showMessage(self,msg.replace(self.template.msg.maxSelectLimit,p.maxSelectLimit));return}}if(json.candidate.length){var arr_candidate=json.candidate,arr_primary_key=json.keyField,keystr=el.hidden.val(),keyArr=keystr?keystr.split(","):new Array(),itemText="";for(var i=0;i").html(itemText).attr({pkey:arr_primary_key[i]});if(!p.formatItem){list.attr("title",itemText)}if($.inArray(arr_primary_key[i].toString(),keyArr)!==-1){list.addClass(self.css_class.selected)}list.data("dataObj",json.originalResult[i]);el.results.append(list)}}else{var li='
                    • '+self.message.not_found+"
                    • ";el.results.append(li)}el.results.show();if(p.multiple&&p.multipleControlbar){el.control.show()}if(p.pagination){el.navi.show()}self.calcResultsSize(self);self.setOpenStatus(self,true);self.eResultList();self.eScroll();if(is_query&&json.candidate.length&&p.autoSelectFirst){self.nextLine(self)}};SelectPage.prototype.calcResultsSize=function(self){var p=self.option,el=self.elem;var rePosition=function(){if(el.container.css("position")==="static"){var offset=el.combo_input.offset();el.result_area.css({top:offset.top+el.combo_input.outerHeight()+"px",left:offset.left+"px"})}else{if(!p.pagination){var itemHeight=el.results.find("li:first").outerHeight(true),listHeight=itemHeight*p.listSize;el.results.css({"max-height":listHeight,"overflow-y":"auto"})}var docWidth=$(document).width(),docHeight=$(document).height(),viewHeight=$(window).height(),offset=el.container.offset(),screenScrollTop=$(window).scrollTop(),listWidth=el.result_area.outerWidth(),listHeight=el.result_area.outerHeight(),defaultLeft=offset.left,inputHeight=el.container.outerHeight(),left=(offset.left+listWidth)>docWidth?defaultLeft-(listWidth-el.container.outerWidth()):defaultLeft,screenTop=offset.top,top=0,dist=5,listBottom=screenTop+inputHeight+listHeight+dist,hasOverflow=docHeight>viewHeight;if((screenTop-screenScrollTop-dist>listHeight)&&(hasOverflow&&listBottom>(viewHeight+screenScrollTop))||(!hasOverflow&&listBottom>viewHeight)){top=offset.top-listHeight-dist;el.result_area.removeClass("shadowUp shadowDown").addClass("shadowUp")}else{top=offset.top+(p.multiple?el.container.outerHeight():inputHeight);el.result_area.removeClass("shadowUp shadowDown").addClass("shadowDown");top+=dist}return{top:top+"px",left:left+"px"}}};if(el.result_area.is(":visible")){el.result_area.css(rePosition())}else{var pss=rePosition();el.result_area.css(pss).show(1,function(){var repss=rePosition();if(pss.top!==repss.top||pss.left!==repss.left){el.result_area.css(repss)}})}};SelectPage.prototype.hideResults=function(self){if(self.prop.key_paging){self.scrollWindow(self,true);self.prop.key_paging=false}self.setCssFocusedInput(self);if(self.option.autoFillResult){}self.elem.results.empty();self.elem.result_area.hide();self.setOpenStatus(self,false);$(window).off("scroll.SelectPage");self.abortAjax(self);self.setButtonAttrDefault()};SelectPage.prototype.disabled=function(self,disabled){var p=self.option,el=self.elem;if($.type(disabled)==="undefined"){return el.combo_input.prop("disabled")}if($.type(disabled)==="boolean"){el.combo_input.prop("disabled",disabled);if(disabled){el.container.addClass(self.css_class.disabled)}else{el.container.removeClass(self.css_class.disabled)}}};SelectPage.prototype.firstPage=function(self){if(self.prop.current_page>1){self.prop.current_page=1;self.prop.page_move=true;self.suggest(self)}};SelectPage.prototype.prevPage=function(self){if(self.prop.current_page>1){self.prop.current_page--;self.prop.page_move=true;self.suggest(self)}};SelectPage.prototype.nextPage=function(self){if(self.prop.current_page0&&p.maxSelectLimit===self.elem.element_box.find("li.selected_tag").length){return false}});if(p.eSelect&&$.isFunction(p.eSelect)){p.eSelect(jsonarr,self)}self.afterAction(self,true)};SelectPage.prototype.unSelectAllLine=function(self){var p=self.option,size=self.elem.results.find("li").length,ds=[];self.elem.results.find("li").each(function(i,row){var key=$(row).attr("pkey");var tag=self.elem.element_box.find('li.selected_tag[itemvalue="'+key+'"]');if(tag.length){ds.push(tag.data("dataObj"))}self.removeTag(self,tag)});self.afterAction(self,true);if(p.eTagRemove&&$.isFunction(p.eTagRemove)){p.eTagRemove(ds)}};SelectPage.prototype.clearAll=function(self,open){var p=self.option,ds=[];if(p.multiple){self.elem.element_box.find("li.selected_tag").each(function(i,row){ds.push($(row).data("dataObj"));row.remove()});self.elem.element_box.find("li.selected_tag").remove()}self.reset(self);self.afterAction(self,open);if(p.multiple){if(p.eTagRemove&&$.isFunction(p.eTagRemove)){p.eTagRemove(ds)}}else{self.elem.clear_btn.remove()}};SelectPage.prototype.reset=function(self){self.elem.combo_input.val("");self.elem.hidden.val("");self.prop.prev_value="";self.prop.selected_text="";self.prop.current_page=1};SelectPage.prototype.getCurrentLine=function(self){if(self.elem.result_area.is(":hidden")){return false}var obj=self.elem.results.find("li."+self.css_class.select);if(obj.length){return obj}else{return false}};SelectPage.prototype.isAlreadySelected=function(self,item){var isExist=false;if(item.value){var keys=self.elem.hidden.val();if(keys){var karr=keys.split(",");if(karr&&karr.length&&$.inArray(item.value,karr)!=-1){isExist=true}}}return isExist};SelectPage.prototype.addNewTag=function(self,data,item){if(!self.option.multiple||!data||!item){return}var tmp=self.template.tag.content,tag;tmp=tmp.replace(self.template.tag.textKey,item.text);tmp=tmp.replace(self.template.tag.valueKey,item.value);tag=$(tmp);tag.data("dataObj",data);if(self.elem.combo_input.prop("disabled")){tag.find("span.tag_close").hide()}self.elem.combo_input.closest("li").before(tag)};SelectPage.prototype.removeTag=function(self,item){var key=$(item).attr("itemvalue");var keys=self.elem.hidden.val();if($.type(key)!="undefined"&&keys){var keyarr=keys.split(","),index=$.inArray(key.toString(),keyarr);if(index!=-1){keyarr.splice(index,1);self.elem.hidden.val(keyarr.toString())}}$(item).remove();self.inputResize(self)};SelectPage.prototype.tagValuesSet=function(self){if(!self.option.multiple){return}var tags=self.elem.element_box.find("li.selected_tag");if(tags&&tags.length){var result=new Array();$.each(tags,function(i,li){var v=$(li).attr("itemvalue");if($.type(v)!=="undefined"){result.push(v)}});if(result.length){self.elem.hidden.val(result.join(","))}}};SelectPage.prototype.inputResize=function(self){if(!self.option.multiple){return}var width="",inputLi=self.elem.combo_input.closest("li");var setDefaultSize=function(self,inputLi){inputLi.removeClass("full_width");var minimumWidth=self.elem.combo_input.val().length+1,width=(minimumWidth*0.75)+"em";self.elem.combo_input.css("width",width).removeAttr("placeholder")};if(self.elem.element_box.find("li.selected_tag").length===0){if(self.elem.combo_input.attr("placeholder_bak")){if(!inputLi.hasClass("full_width")){inputLi.addClass("full_width")}self.elem.combo_input.attr("placeholder",self.elem.combo_input.attr("placeholder_bak")).removeAttr("style")}else{setDefaultSize(self,inputLi)}}else{setDefaultSize(self,inputLi)}};SelectPage.prototype.nextLine=function(self){var obj=self.getCurrentLine(self),idx;if(!obj){idx=-1}else{idx=self.elem.results.children("li").index(obj);obj.removeClass(self.css_class.select)}idx++;if(idx-1){var prev=self.elem.results.children("li").eq(idx);prev.addClass(self.css_class.select);self.setCssFocusedResults(self)}else{self.setCssFocusedInput(self)}self.scrollWindow(self,false)};function Plugin(option){return this.each(function(){var $this=$(this),data=$this.data(SelectPage.dataKey),params=$.extend({},defaults,$this.data(),data&&data.option,typeof option==="object"&&option);if(!data){$this.data(SelectPage.dataKey,(data=new SelectPage(this,params)))}})}function getPlugin(obj){return $(obj).closest("div.sp_container").find("input.sp_input")}function ClearSelected(){return this.each(function(){var $this=getPlugin(this),data=$this.data(SelectPage.dataKey);if(data){data.prop.init_set=true;data.clearAll(data);data.prop.init_set=false}})}function SelectedRefresh(){return this.each(function(){var $this=getPlugin(this),data=$this.data(SelectPage.dataKey);if(data&&data.elem.hidden.val()){data.setInitRecord(true)}})}function ModifyDataSource(data){return this.each(function(){if(data&&$.isArray(data)){var $this=getPlugin(this),plugin=$this.data(SelectPage.dataKey);if(plugin){plugin.clearAll(plugin);plugin.option.data=data}}})}function PluginDisabled(disabled){var status=false;this.each(function(){var $this=getPlugin(this),plugin=$this.data(SelectPage.dataKey);if(plugin){if($.type(disabled)!=="undefined"){plugin.disabled(plugin,disabled)}else{status=plugin.disabled(plugin)}}});return status}function GetInputText(){var str="";this.each(function(){var $this=getPlugin(this),data=$this.data(SelectPage.dataKey);if(data){if(data.option.multiple){var tags=[];data.elem.element_box.find("li.selected_tag").each(function(i,tag){tags.push($(tag).text())});str+=tags.toString()}else{str+=data.elem.combo_input.val()}}});return str}var old=$.fn.selectPage;$.fn.selectPage=Plugin;$.fn.selectPage.Constructor=SelectPage;$.fn.selectPageClear=ClearSelected;$.fn.selectPageRefresh=SelectedRefresh;$.fn.selectPageData=ModifyDataSource;$.fn.selectPageDisabled=PluginDisabled;$.fn.selectPageText=GetInputText;$.fn.selectPage.noConflict=function(){$.fn.selectPage=old;return this}})(window.jQuery); \ No newline at end of file