From 35b1f89e18a9cd0d9118707bf1cb6c89706af57b Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Tue, 10 Nov 2020 15:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89createWidgets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../colorpicker/editor.colorpicker.hex.js | 59 +++++++++++-------- .../editor.colorpicker.hex.simple.js | 59 +++++++++++-------- 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/src/case/colorchooser/colorpicker/editor.colorpicker.hex.js b/src/case/colorchooser/colorpicker/editor.colorpicker.hex.js index 9adccf272..6a2354da3 100644 --- a/src/case/colorchooser/colorpicker/editor.colorpicker.hex.js +++ b/src/case/colorchooser/colorpicker/editor.colorpicker.hex.js @@ -31,29 +31,28 @@ BI.HexColorPickerEditor = BI.inherit(BI.Widget, { var checker = function (v) { return BI.isNumeric(v) && (v | 0) >= 0 && (v | 0) <= 255; }; - var Ws = BI.createWidgets([{}, {}, {}], { - type: "bi.small_text_editor", - cls: "color-picker-editor-input", - validationChecker: checker, - errorText: BI.i18nText("BI-Color_Picker_Error_Text"), - allowBlank: true, - value: 255, - width: c.RGB_WIDTH, - height: 20, - listeners: [{ - eventName: BI.TextEditor.EVENT_CHANGE, - action: function () { - self._checkEditors(); - if (checker(self.storeValue.r) && checker(self.storeValue.g) && checker(self.storeValue.b)) { - self.colorShow.element.css("background-color", self.getValue()); - self.fireEvent(BI.ColorPickerEditor.EVENT_CHANGE); + var Ws = BI.map(BI.range(0, 3), function () { + return { + type: "bi.small_text_editor", + cls: "color-picker-editor-input", + validationChecker: checker, + errorText: BI.i18nText("BI-Color_Picker_Error_Text"), + allowBlank: true, + value: 255, + width: c.RGB_WIDTH, + height: 20, + listeners: [{ + eventName: BI.TextEditor.EVENT_CHANGE, + action: function () { + self._checkEditors(); + if (checker(self.storeValue.r) && checker(self.storeValue.g) && checker(self.storeValue.b)) { + self.colorShow.element.css("background-color", self.getValue()); + self.fireEvent(BI.ColorPickerEditor.EVENT_CHANGE); + } } - } - }] + }] + }; }); - this.R = Ws[0]; - this.G = Ws[1]; - this.B = Ws[2]; return { type: "bi.absolute", @@ -98,13 +97,25 @@ BI.HexColorPickerEditor = BI.inherit(BI.Widget, { } }] }, { - el: this.R, + el: BI.extend(Ws[0], { + ref: function (_ref) { + self.R = _ref + } + }), width: c.RGB_WIDTH }, { - el: this.G, + el: BI.extend(Ws[1], { + ref: function (_ref) { + self.G = _ref + } + }), width: c.RGB_WIDTH }, { - el: this.B, + el: BI.extend(Ws[2], { + ref: function (_ref) { + self.B = _ref + } + }), width: c.RGB_WIDTH }, { el: { diff --git a/src/case/colorchooser/colorpicker/editor.colorpicker.hex.simple.js b/src/case/colorchooser/colorpicker/editor.colorpicker.hex.simple.js index 2b2019e88..cd9e5a3d3 100644 --- a/src/case/colorchooser/colorpicker/editor.colorpicker.hex.simple.js +++ b/src/case/colorchooser/colorpicker/editor.colorpicker.hex.simple.js @@ -29,29 +29,28 @@ BI.SimpleHexColorPickerEditor = BI.inherit(BI.Widget, { var checker = function (v) { return BI.isNumeric(v) && (v | 0) >= 0 && (v | 0) <= 255; }; - var Ws = BI.createWidgets([{}, {}, {}], { - type: "bi.small_text_editor", - cls: "color-picker-editor-input", - validationChecker: checker, - errorText: BI.i18nText("BI-Color_Picker_Error_Text"), - allowBlank: true, - value: 255, - width: c.RGB_WIDTH, - height: 20, - listeners: [{ - eventName: BI.TextEditor.EVENT_CHANGE, - action: function () { - self._checkEditors(); - if (self.R.isValid() && self.G.isValid() && self.B.isValid()) { - self.colorShow.element.css("background-color", self.getValue()); - self.fireEvent(BI.SimpleColorPickerEditor.EVENT_CHANGE); + var Ws = BI.map(BI.range(0, 3), function () { + return { + type: "bi.small_text_editor", + cls: "color-picker-editor-input", + validationChecker: checker, + errorText: BI.i18nText("BI-Color_Picker_Error_Text"), + allowBlank: true, + value: 255, + width: c.RGB_WIDTH, + height: 20, + listeners: [{ + eventName: BI.TextEditor.EVENT_CHANGE, + action: function () { + self._checkEditors(); + if (self.R.isValid() && self.G.isValid() && self.B.isValid()) { + self.colorShow.element.css("background-color", self.getValue()); + self.fireEvent(BI.SimpleColorPickerEditor.EVENT_CHANGE); + } } - } - }] + }] + } }); - this.R = Ws[0]; - this.G = Ws[1]; - this.B = Ws[2]; return { type: "bi.vertical", @@ -95,13 +94,25 @@ BI.SimpleHexColorPickerEditor = BI.inherit(BI.Widget, { } }] }, { - el: this.R, + el: BI.extend(Ws[0], { + ref: function (_ref) { + self.R = _ref + } + }), width: c.RGB_WIDTH }, { - el: this.G, + el: BI.extend(Ws[1], { + ref: function (_ref) { + self.G = _ref + } + }), width: c.RGB_WIDTH }, { - el: this.B, + el: BI.extend(Ws[2], { + ref: function (_ref) { + self.B = _ref + } + }), width: c.RGB_WIDTH }] }, {