From 9d128e42fab8ad160ed51514c6f02e6ae9c27ee0 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 9 Dec 2021 23:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E8=B6=85=E8=BF=87=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E9=80=89=E6=8B=A9=E9=95=BF=E5=BA=A6=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/select2/4.0/select2.full.js | 38 ++++++++++++------- .../resources/static/select2/4.0/select2.js | 24 +++++++----- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/common/src/main/resources/static/select2/4.0/select2.full.js b/common/src/main/resources/static/select2/4.0/select2.full.js index 3ff82131..810f5799 100644 --- a/common/src/main/resources/static/select2/4.0/select2.full.js +++ b/common/src/main/resources/static/select2/4.0/select2.full.js @@ -862,17 +862,24 @@ S2.define('select2/results',[ var $selected = $options.filter('[aria-selected=true]'); - // Check if there are any selected options - if ($selected.length > 0) { - // If there are selected options, highlight the first - $selected.first().trigger('mouseenter'); - } else { - // If there are no selected options, highlight the first option - // in the dropdown - $options.first().trigger('mouseenter'); - } +// // Check if there are any selected options +// if ($selected.length > 0) { +// // If there are selected options, highlight the first +// $selected.first().trigger('mouseenter'); +// } else { +// // If there are no selected options, highlight the first option +// // in the dropdown +// $options.first().trigger('mouseenter'); +// } +// +// this.ensureHighlightVisible(); +// ThinkGem 禁用 First Item 高亮 - this.ensureHighlightVisible(); + // ThinkGem 当超过设置最大选择长度时,自动关闭下拉框 + var msl = this.options.get('maximumSelectionLength'); + if (msl > 0 && $selected.length >= msl) { + this.trigger('close', {}); + } }; Results.prototype.setClasses = function () { @@ -4492,9 +4499,9 @@ S2.define('select2/i18n/en',[],function () { maximumSelected: function (args) { var message = '最多只能选择 ' + args.maximum + ' 个项目'; - if (args.maximum != 1) { - message += 's'; - } + //if (args.maximum != 1) { // ThinkGem 删除多余的复数 + // message += 's'; + //} return message; }, @@ -5376,7 +5383,10 @@ S2.define('select2/core',[ } else { if (/*key === KEYS.ENTER || */key === KEYS.SPACE || // ThinkGem 去掉回车后打开下拉框,解决jqgrid回车获取下一个输入框按键冲突 (key === KEYS.DOWN && evt.altKey)) { - self.open(); + + if (!this.options.get('disabled')){ // 修正禁用的时候,按空格可弹窗下拉框问题 + self.open(); + } evt.preventDefault(); } diff --git a/common/src/main/resources/static/select2/4.0/select2.js b/common/src/main/resources/static/select2/4.0/select2.js index a515ea96..17cfe4b3 100644 --- a/common/src/main/resources/static/select2/4.0/select2.js +++ b/common/src/main/resources/static/select2/4.0/select2.js @@ -857,11 +857,11 @@ S2.define('select2/results',[ }; Results.prototype.highlightFirstItem = function () { -// var $options = this.$results -// .find('.select2-results__option[aria-selected]'); -// -// var $selected = $options.filter('[aria-selected=true]'); -// + var $options = this.$results + .find('.select2-results__option[aria-selected]'); + + var $selected = $options.filter('[aria-selected=true]'); + // // Check if there are any selected options // if ($selected.length > 0) { // // If there are selected options, highlight the first @@ -874,6 +874,12 @@ S2.define('select2/results',[ // // this.ensureHighlightVisible(); // ThinkGem 禁用 First Item 高亮 + + // ThinkGem 当超过设置最大选择长度时,自动关闭下拉框 + var msl = this.options.get('maximumSelectionLength'); + if (msl > 0 && $selected.length >= msl) { + this.trigger('close', {}); + } }; Results.prototype.setClasses = function () { @@ -4462,7 +4468,7 @@ S2.define('select2/dropdown/closeOnSelect',[ return CloseOnSelect; }); -//ThinkGem 默认为中文 +// ThinkGem 默认为中文 S2.define('select2/i18n/en',[],function () { // English return { @@ -4493,9 +4499,9 @@ S2.define('select2/i18n/en',[],function () { maximumSelected: function (args) { var message = '最多只能选择 ' + args.maximum + ' 个项目'; - if (args.maximum != 1) { - message += 's'; - } + //if (args.maximum != 1) { // ThinkGem 删除多余的复数 + // message += 's'; + //} return message; },