diff --git a/.eslintrc b/.eslintrc index 12defcd8a..41426aa36 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,8 @@ "env": { "browser": true, "node": true, - "es6": true + "es6": true, + "jest": true }, "globals": { "window": true, diff --git a/package.json b/package.json index 435bd5356..852797d95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fineui", - "version": "2.0.20220812095620", + "version": "2.0.20220812180611", "description": "fineui", "main": "dist/fineui_without_conflict.min.js", "types": "dist/lib/index.d.ts", diff --git a/src/base/collection/__test__/collection.test.js b/src/base/collection/__test__/collection.test.js index 381735ac3..6ce44fc22 100644 --- a/src/base/collection/__test__/collection.test.js +++ b/src/base/collection/__test__/collection.test.js @@ -5,7 +5,6 @@ */ describe("CollectionTest", function () { - /** * test_author_windy */ @@ -35,4 +34,4 @@ describe("CollectionTest", function () { // TODO 列表展示类控件不知道该测什么,先标记一下 grid.destroy(); }); -}); \ No newline at end of file +}); diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 8605e70c5..1d56702fe 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -58,7 +58,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (o.overflowY === false) { scrollable = false; } else { - scrollable = "y" + scrollable = "y"; } } else { if (o.overflowY === false) { @@ -84,7 +84,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { // mounted之后绑定事件 mounted: function () { - var o = this.options; + var o = this.options; if (o.scrollLeft !== 0 || o.scrollTop !== 0) { this.element.scrollTop(o.scrollTop); this.element.scrollLeft(o.scrollLeft); @@ -101,10 +101,10 @@ BI.CollectionView = BI.inherit(BI.Widget, { for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); - if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || - cellMetadatum.width == null || isNaN(cellMetadatum.width) || - cellMetadatum.x == null || isNaN(cellMetadatum.x) || - cellMetadatum.y == null || isNaN(cellMetadatum.y)) { + if (BI.isNull(cellMetadatum.height) || isNaN(cellMetadatum.height) || + BI.isNull(cellMetadatum.width) || isNaN(cellMetadatum.width) || + BI.isNull(cellMetadatum.x) || isNaN(cellMetadatum.x) || + BI.isNull(cellMetadatum.y) || isNaN(cellMetadatum.y)) { throw Error(); } @@ -124,16 +124,18 @@ BI.CollectionView = BI.inherit(BI.Widget, { _cellRenderers: function (height, width, x, y) { this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y); + return this._cellGroupRenderer(); }, _cellGroupRenderer: function () { - var self = this, o = this.options; + var self = this; var rendered = []; BI.each(this._lastRenderedCellIndices, function (i, index) { var cellMetadata = self._sectionManager.getCellMetadata(index); rendered.push(cellMetadata); }); + return rendered; }, @@ -167,16 +169,16 @@ BI.CollectionView = BI.inherit(BI.Widget, { var topMap = BI.invert(tops); // 存储上下左右四个边界 var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; - var assertMinBorder = function (border, offset) { - if (border[offset] == null) { + function assertMinBorder(border, offset) { + if (BI.isNull(border[offset])) { border[offset] = Number.MAX_VALUE; } - }; - var assertMaxBorder = function (border, offset) { - if (border[offset] == null) { + } + function assertMaxBorder(border, offset) { + if (BI.isNull(border[offset])) { border[offset] = 0; } - }; + } for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1]; @@ -194,7 +196,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { this.renderedCells[index].el.element.css("left", datum.x / BI.pixRatio + BI.pixUnit); // } // if (this.renderedCells[index]._top !== datum.y) { - this.renderedCells[index].el.element.css("top", datum.y / BI.pixRatio + BI.pixUnit); + this.renderedCells[index].el.element.css("top", datum.y / BI.pixRatio + BI.pixUnit); // } renderedCells.push(child = this.renderedCells[index]); } else { @@ -213,7 +215,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { left: datum.x, top: datum.y, _left: datum.x, - _top: datum.y, + _top: datum.y // _width: datum.width, // _height: datum.height }); @@ -280,7 +282,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { var minY = BI.max(topBorder); var maxY = BI.min(bottomBorder); - this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; + this.renderRange = { minX: minX, minY: minY, maxX: maxX, maxY: maxY }; } }, @@ -339,7 +341,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (this.options.overflowX !== !!b) { this.options.overflowX = !!b; BI.nextTick(function () { - self.element.css({overflowX: b ? "auto" : "hidden"}); + self.element.css({ overflowX: b ? "auto" : "hidden" }); }); } }, @@ -349,7 +351,7 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (this.options.overflowY !== !!b) { this.options.overflowY = !!b; BI.nextTick(function () { - self.element.css({overflowY: b ? "auto" : "hidden"}); + self.element.css({ overflowY: b ? "auto" : "hidden" }); }); } }, diff --git a/src/base/combination/bubble.js b/src/base/combination/bubble.js index f698b4a1a..288612a0c 100644 --- a/src/base/combination/bubble.js +++ b/src/base/combination/bubble.js @@ -6,6 +6,7 @@ BI.Bubble = BI.inherit(BI.Widget, { _defaultConfig: function () { var conf = BI.Bubble.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-popper", attributes: { @@ -36,7 +37,7 @@ el: {}, popup: {}, comboClass: "bi-combo-popup", - hoverClass: "bi-combo-hover", + hoverClass: "bi-combo-hover" }); }, @@ -104,14 +105,14 @@ _initPullDownAction: function () { var self = this, o = this.options; var evs = (this.options.trigger || "").split(","); - var st = function (e) { + function st (e) { if (o.stopEvent) { e.stopEvent(); } if (o.stopPropagation) { e.stopPropagation(); } - }; + } var enterPopup = false; @@ -217,6 +218,8 @@ } }); break; + default: + break; } }); }, @@ -229,7 +232,7 @@ _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { type: "bi.bubble_popup_view", showArrow: o.showArrow, @@ -286,6 +289,7 @@ return; } this._hideView(e); + return true; }, @@ -319,7 +323,7 @@ }, _popupView: function (e) { - var self = this, o = this.options; + var o = this.options; this._assertPopupViewRender(); this.fireEvent(BI.Bubble.EVENT_BEFORE_POPUPVIEW); // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index 27d00fc6a..c44338429 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -1,6 +1,7 @@ !(function () { var needHideWhenAnotherComboOpen = {}; var currentOpenedCombos = {}; + /** * @class BI.Combo * @extends BI.Widget @@ -11,6 +12,7 @@ }, _defaultConfig: function () { var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""), attributes: { @@ -107,7 +109,7 @@ _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { type: "bi.popup_view", showArrow: o.showArrow, @@ -280,10 +282,12 @@ delete p.adaptHeight; p.dir = "right"; break; + default: + break; } if ("adaptHeight" in p) { - this.resetListHeight(p["adaptHeight"]); + this.resetListHeight(p.adaptHeight); } var width = this.combo.element.outerWidth(); var height = this.combo.element.outerHeight(); diff --git a/src/base/combination/expander.js b/src/base/combination/expander.js index 407413c40..f3d87109b 100644 --- a/src/base/combination/expander.js +++ b/src/base/combination/expander.js @@ -126,6 +126,8 @@ BI.Expander = BI.inherit(BI.Widget, { })); } break; + default: + break; } }); }, @@ -136,7 +138,7 @@ BI.Expander = BI.inherit(BI.Widget, { _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(this.options.popup, { type: "bi.button_group", cls: "expander-popup", @@ -255,6 +257,7 @@ BI.Expander = BI.inherit(BI.Widget, { if (this.expander.options.id === id) { return this.expander; } + return this.popupView && this.popupView.getNodeById(id); }, @@ -262,6 +265,7 @@ BI.Expander = BI.inherit(BI.Widget, { if (this.expander.getValue() === value) { return this.expander; } + return this.popupView && this.popupView.getNodeByValue(value); }, diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index b9e8f7127..fa91d7239 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -42,7 +42,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, _createBtns: function (items) { - var o = this.options; return BI.createWidgets(BI.createItems(items, { type: "bi.text_button" }), this); @@ -66,6 +65,8 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { case BI.ButtonGroup.CHOOSE_TYPE_NONE: self.setValue([]); break; + default: + break; } self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); @@ -95,15 +96,18 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }); }); } + return btns; }, _packageSimpleItems: function (btns) { var o = this.options; + return BI.map(o.items, function (i, item) { if (BI.stripEL(item) === item) { return btns[i]; } + return BI.extend({}, item, { el: btns[i] }); @@ -122,12 +126,14 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; + return layout; }, // 如果是一个简单的layout _isSimpleLayout: function () { var o = this.options; + return BI.isArray(o.layouts) ? (o.layouts.length === 1 && !BI.isArray(o.items[0])) : true; }, @@ -140,12 +146,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, prependItems: function (items) { - var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); + return; } @@ -154,13 +160,13 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, addItems: function (items) { - var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(this.buttons, btns); // 如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); + return; } @@ -257,6 +263,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { v.push(item.getValue()); } }); + return v; }, @@ -267,6 +274,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { v.push(item.getValue()); } }); + return v; }, @@ -285,6 +293,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { btns.push(item); } }); + return btns; }, @@ -295,6 +304,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { btns.push(item); } }); + return btns; }, @@ -303,9 +313,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { index = i; + return true; } }); + return index; }, @@ -314,9 +326,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.options.id === id) { node = item; + return true; } }); + return node; }, @@ -325,9 +339,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { node = item; + return true; } }); + return node; }, diff --git a/src/base/combination/group.combo.js b/src/base/combination/group.combo.js index 7c07445ee..9e4d56749 100644 --- a/src/base/combination/group.combo.js +++ b/src/base/combination/group.combo.js @@ -15,7 +15,7 @@ BI.ComboGroup = BI.inherit(BI.Widget, { isNeedAdjustHeight: false, isNeedAdjustWidth: false, - el: {type: "bi.text_button", text: "", value: ""}, + el: { type: "bi.text_button", text: "", value: "" }, items: [], popup: { diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index d42c7a5b7..7efe85716 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -29,9 +29,10 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { var o = this.options; var map = this.buttonMap = {}; var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; - for (var i = layouts.length - 1; i > 0; i--) { + for (let i = layouts.length - 1; i > 0; i--) { items = BI.map(items, function (k, it) { var el = BI.stripEL(it); + return BI.extend({}, layouts[i], { items: [ BI.extend({}, layouts[i].el, { @@ -47,6 +48,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { }); }); } + return items; }, @@ -60,6 +62,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; + return layout; }, @@ -93,6 +96,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } } }); + return v; }, @@ -119,6 +123,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } } }); + return v; }, diff --git a/src/base/combination/loader.js b/src/base/combination/loader.js index a56e72708..b873d09c0 100644 --- a/src/base/combination/loader.js +++ b/src/base/combination/loader.js @@ -38,7 +38,7 @@ BI.Loader = BI.inherit(BI.Widget, { _prevLoad: function () { var self = this, o = this.options; this.prev.setLoading(); - o.itemsCreator.apply(this, [{times: --this.times}, function () { + o.itemsCreator.apply(this, [{ times: --this.times }, function () { self.prev.setLoaded(); self.prependItems.apply(self, arguments); }]); @@ -47,7 +47,7 @@ BI.Loader = BI.inherit(BI.Widget, { _nextLoad: function () { var self = this, o = this.options; this.next.setLoading(); - o.itemsCreator.apply(this, [{times: ++this.times}, function () { + o.itemsCreator.apply(this, [{ times: ++this.times }, function () { self.next.setLoaded(); self.addItems.apply(self, arguments); }]); @@ -122,6 +122,7 @@ BI.Loader = BI.inherit(BI.Widget, { if (BI.isNumber(o.count)) { return this.count < o.count; } + return !!o.hasPrev.apply(this, [{ times: this.times, count: this.count @@ -133,6 +134,7 @@ BI.Loader = BI.inherit(BI.Widget, { if (BI.isNumber(o.count)) { return this.count < o.count; } + return !!o.hasNext.apply(this, [{ times: this.times, count: this.count @@ -168,13 +170,14 @@ BI.Loader = BI.inherit(BI.Widget, { _populate: function (items) { var self = this, o = this.options; if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { - o.itemsCreator.apply(this, [{times: 1}, function () { + o.itemsCreator.apply(this, [{ times: 1 }, function () { if (arguments.length === 0) { throw new Error("参数不能为空"); } self.populate.apply(self, arguments); o.onLoaded(); }]); + return false; } this.options.items = items; @@ -195,6 +198,7 @@ BI.Loader = BI.inherit(BI.Widget, { this.prev.invisible(); } } + return true; }, diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index b2d5ae867..7223a1c5f 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -23,7 +23,7 @@ BI.Navigation = BI.inherit(BI.Widget, { render: function () { var self = this, o = this.options; - this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); + this.tab = BI.createWidget(this.options.tab, { type: "bi.button_group" }); this.cardMap = {}; this.showIndex = 0; this.layout = BI.createWidget({ @@ -45,6 +45,7 @@ BI.Navigation = BI.inherit(BI.Widget, { cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; + return card; }, afterCardCreated: BI.bind(this.afterCardCreated, this), @@ -54,7 +55,7 @@ BI.Navigation = BI.inherit(BI.Widget, { if (BI.isFunction(o.showIndex)) { this.__watch(o.showIndex, function (context, newValue) { self.setSelect(newValue); - }) + }); } }, diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index 0989b4c8a..14efe2e77 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -82,6 +82,8 @@ BI.Searcher = BI.inherit(BI.Widget, { self._pauseSearch(); } break; + default: + break; } }); }, @@ -109,6 +111,8 @@ BI.Searcher = BI.inherit(BI.Widget, { values.push(obj.getValue()); o.adapter && o.adapter.setValue(values); break; + default: + break; } } self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); @@ -140,7 +144,6 @@ BI.Searcher = BI.inherit(BI.Widget, { }, _pauseSearch: function () { - var o = this.options, name = this.getName(); this._stop = true; BI.nextTick(function (name) { BI.Maskers.hide(name); @@ -153,7 +156,7 @@ BI.Searcher = BI.inherit(BI.Widget, { }, _stopSearch: function () { - var o = this.options, name = this.getName(); + var name = this.getName(); this._stop = true; BI.Maskers.hide(name); if (this._isSearching === true) { @@ -175,6 +178,7 @@ BI.Searcher = BI.inherit(BI.Widget, { this.popupView.populate(find, match, keyword); o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); + return; } this.popupView.loading && this.popupView.loading(); @@ -203,6 +207,7 @@ BI.Searcher = BI.inherit(BI.Widget, { if (BI.isEmptyString(res[res.length - 1])) { res = res.slice(0, res.length - 1); } + return BI.isNull(res) ? "" : res[res.length - 1]; } }, @@ -246,6 +251,7 @@ BI.Searcher = BI.inherit(BI.Widget, { hasMatched: function () { this._assertPopupView(); + return this.popupView.hasMatched(); }, @@ -288,8 +294,8 @@ BI.Searcher = BI.inherit(BI.Widget, { if (BI.isNull(this.popupView)) { return o.popup.value; } - return this.popupView.getValue(); + return this.popupView.getValue(); }, populate: function (result, searchResult, keyword) { diff --git a/src/base/combination/switcher.js b/src/base/combination/switcher.js index 1a929f704..ce0a623e2 100644 --- a/src/base/combination/switcher.js +++ b/src/base/combination/switcher.js @@ -265,6 +265,7 @@ BI.Switcher = BI.inherit(BI.Widget, { if (this.switcher.attr("id") === id) { return this.switcher; } + return this.popupView && this.popupView.getNodeById(id); }, @@ -272,6 +273,7 @@ BI.Switcher = BI.inherit(BI.Widget, { if (this.switcher.getValue() === value) { return this.switcher; } + return this.popupView && this.popupView.getNodeByValue(value); }, diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 90a788a17..3020859f5 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -112,7 +112,7 @@ BI.Tab = BI.inherit(BI.Widget, { }, removeTab: function (cardname) { - var self = this, o = this.options; + var self = this; BI.any(this.cardMap, function (name, card) { if (BI.isEqual(name, (cardname + ""))) { self.layout.deleteCardByName(name); diff --git a/src/base/combination/tree.button.js b/src/base/combination/tree.button.js index 45b436b8a..457c5afd5 100644 --- a/src/base/combination/tree.button.js +++ b/src/base/combination/tree.button.js @@ -16,6 +16,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setNotSelectedValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -31,6 +32,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (BI.isFunction(item.setEnabledValue)) { item.setEnabledValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -46,6 +48,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -61,12 +64,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getNotSelectedValue()); + return; } if (item.isEnabled() && item.isSelected && !item.isSelected()) { v.push(item.getValue()); } }); + return v; }, @@ -75,12 +80,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getValue()); + return; } if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } }); + return v; }, @@ -89,12 +96,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getSelectedButtons()); + return; } if (item.isSelected && item.isSelected()) { btns.push(item); } }); + return btns; }, @@ -103,12 +112,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getNotSelectedButtons()); + return; } if (item.isSelected && !item.isSelected()) { btns.push(item); } }); + return btns; }, @@ -118,12 +129,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { leaves = leaves.concat(item.getAllLeaves()); + return; } if (item.isEnabled()) { leaves.push(item); } }); + return leaves; }, @@ -133,9 +146,11 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { var vs = item.getValue(); if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { index = i; + return true; } }); + return index; }, @@ -145,14 +160,17 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { if (item.isEnabled()) { if (item.attr("id") === id) { node = item; + return true; } else if (BI.isFunction(item.getNodeById)) { - if (node = item.getNodeById(id)) { + node = item.getNodeById(id); + if (node) { return true; } } } }); + return node; }, @@ -161,15 +179,18 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.any(this.buttons, function (i, item) { if (item.isEnabled()) { if (BI.isFunction(item.getNodeByValue)) { - if (node = item.getNodeByValue(value)) { + node = item.getNodeByValue(value); + if (node) { return true; } } else if (item.attr("value") === value) { node = item; + return true; } } }); + return node; } }); diff --git a/src/base/foundation/__test__/message.test.js b/src/base/foundation/__test__/message.test.js index 7097c50ff..5e4890147 100644 --- a/src/base/foundation/__test__/message.test.js +++ b/src/base/foundation/__test__/message.test.js @@ -4,7 +4,6 @@ * Created by windy on 2020/3/9 */ describe("MessageTest", function () { - /** * test_author_windy */ @@ -44,4 +43,3 @@ describe("MessageTest", function () { expect(body.find(".bi-toast").length).to.equal(1); }); }); - diff --git a/src/base/foundation/message.js b/src/base/foundation/message.js index 82ab48ee5..875a244e5 100644 --- a/src/base/foundation/message.js +++ b/src/base/foundation/message.js @@ -3,8 +3,7 @@ * 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) * @class BI.Msg */ -BI.Msg = function () { - +BI.Msg = ((function () { var $mask, $pop; var messageShows = []; @@ -69,6 +68,7 @@ BI.Msg = function () { toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); toast.destroy?.(); }, 5000); + return function () { toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); toast.destroy?.(); @@ -92,14 +92,14 @@ BI.Msg = function () { right: 0, bottom: 0 }).appendTo("body"); - var close = function () { + function close () { messageShows[messageShows.length - 1].destroy(); messageShows.pop(); if (messageShows.length === 0) { $mask.remove(); $mask = null; } - }; + } var controlItems = []; if (hasCancel === true) { controlItems.push({ @@ -231,4 +231,4 @@ BI.Msg = function () { messageShows[messageShows.length] = BI.createWidget(conf); } }; -}(); +})()); diff --git a/src/base/grid/__test__/grid.test.js b/src/base/grid/__test__/grid.test.js index d65c3d24c..da11bba80 100644 --- a/src/base/grid/__test__/grid.test.js +++ b/src/base/grid/__test__/grid.test.js @@ -4,7 +4,6 @@ * Created by windy on 2020/3/20 */ describe("GridTest", function () { - /** * test_author_windy */ @@ -38,4 +37,4 @@ describe("GridTest", function () { // TODO 性能展示类控件,不知道要测啥,标记一下 grid.destroy(); }); -}); \ No newline at end of file +}); diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 334851235..c08f30645 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -61,7 +61,7 @@ BI.GridView = BI.inherit(BI.Widget, { if (o.overflowY === false) { scrollable = false; } else { - scrollable = "y" + scrollable = "y"; } } else { if (o.overflowY === false) { @@ -258,7 +258,7 @@ BI.GridView = BI.inherit(BI.Widget, { this.container.attr("items", renderedCells); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; - this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; + this.renderRange = { minX: minX, minY: minY, maxX: maxX, maxY: maxY }; } }, @@ -279,7 +279,7 @@ BI.GridView = BI.inherit(BI.Widget, { }, _populate: function (items) { - var self = this, o = this.options; + var o = this.options; this._reRange(); if (items && items !== this.options.items) { this.options.items = items; @@ -333,7 +333,7 @@ BI.GridView = BI.inherit(BI.Widget, { if (this.options.overflowX !== !!b) { this.options.overflowX = !!b; BI.nextTick(function () { - self.element.css({overflowX: b ? "auto" : "hidden"}); + self.element.css({ overflowX: b ? "auto" : "hidden" }); }); } }, @@ -343,7 +343,7 @@ BI.GridView = BI.inherit(BI.Widget, { if (this.options.overflowY !== !!b) { this.options.overflowY = !!b; BI.nextTick(function () { - self.element.css({overflowY: b ? "auto" : "hidden"}); + self.element.css({ overflowY: b ? "auto" : "hidden" }); }); } }, diff --git a/src/base/layer/__test__/layer.popover.test.js b/src/base/layer/__test__/layer.popover.test.js index 1830744a8..09c05858b 100644 --- a/src/base/layer/__test__/layer.popover.test.js +++ b/src/base/layer/__test__/layer.popover.test.js @@ -5,7 +5,6 @@ */ describe("PopoverTest", function () { - /** * test_author_windy */ @@ -30,4 +29,4 @@ describe("PopoverTest", function () { done(); }, 100); }); -}); \ No newline at end of file +}); diff --git a/src/base/layer/layer.drawer.js b/src/base/layer/layer.drawer.js index 2bf2b2942..3472f6942 100644 --- a/src/base/layer/layer.drawer.js +++ b/src/base/layer/layer.drawer.js @@ -144,6 +144,8 @@ BI.Drawer = BI.inherit(BI.Widget, { top: "100%" }); break; + default: + break; } }, @@ -172,6 +174,8 @@ BI.Drawer = BI.inherit(BI.Widget, { top: "calc(100% - " + size.height + "px)" }); break; + default: + break; } callback && callback(); }); @@ -180,7 +184,6 @@ BI.Drawer = BI.inherit(BI.Widget, { hide: function (callback) { var self = this, o = this.options; requestAnimationFrame(function () { - var size = self._getSuitableSize(); switch (o.placement) { case "right": self.element.css({ @@ -202,6 +205,8 @@ BI.Drawer = BI.inherit(BI.Widget, { top: "100%" }); break; + default: + break; } setTimeout(callback, 300); }); diff --git a/src/base/layer/layer.popover.js b/src/base/layer/layer.popover.js index bce738ef3..c4d2efa5d 100644 --- a/src/base/layer/layer.popover.js +++ b/src/base/layer/layer.popover.js @@ -157,18 +157,16 @@ BI.Popover = BI.inherit(BI.Widget, { // mounted之后绑定事件 mounted: function () { var self = this; - var o = this.options; this.dragger.element.mousedown(function (e) { - var pos = self.element.offset(); - self.startX = pos.left; - self.startY = pos.top; + self.startX = self.element[0].offsetLeft; + self.startY = self.element[0].offsetTop; self.tracker.captureMouseMoves(e); }); }, _getSuitableBodyHeight: function (height) { var o = this.options; - var c = this._constant; + return BI.clamp(height, 0, BI.Widget._renderEngine.createElement("body")[0].clientHeight - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap); }, @@ -224,7 +222,7 @@ BI.Popover = BI.inherit(BI.Widget, { }, setZindex: function (zindex) { - this.element.css({"z-index": zindex}); + this.element.css({ "z-index": zindex }); }, destroyed: function () { diff --git a/src/base/layer/layer.popup.js b/src/base/layer/layer.popup.js index 8e747d24f..6255975ab 100644 --- a/src/base/layer/layer.popup.js +++ b/src/base/layer/layer.popup.js @@ -50,22 +50,24 @@ BI.PopupView = BI.inherit(BI.Widget, { render: function () { var self = this, o = this.options; - var fn = function (e) { + function fn (e) { e.stopPropagation(); - }, stop = function (e) { + } + function stop (e) { e.stopEvent(); + return false; - }; + } this.element.css({ "z-index": BI.zIndex_popup, "min-width": BI.isNumeric(o.minWidth) ? (o.minWidth / BI.pixRatio + BI.pixUnit) : o.minWidth, "max-width": BI.isNumeric(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth - }).bind({click: fn}); + }).bind({ click: fn }); this.element.bind("mousewheel", fn); - o.stopPropagation && this.element.bind({mousedown: fn, mouseup: fn, mouseover: fn}); - o.stopEvent && this.element.bind({mousedown: stop, mouseup: stop, mouseover: stop}); + o.stopPropagation && this.element.bind({ mousedown: fn, mouseup: fn, mouseover: fn }); + o.stopEvent && this.element.bind({ mousedown: stop, mouseup: stop, mouseover: stop }); this.tool = this._createTool(); this.tab = this._createTab(); this.view = this._createView(); @@ -108,7 +110,7 @@ BI.PopupView = BI.inherit(BI.Widget, { type: "bi.absolute", cls: "bi-bubble-arrow-wrapper", items: [{ - el: this.arrow, + el: this.arrow }] }); // 因为三角符号的原因位置变大了,需要占位 @@ -121,7 +123,7 @@ BI.PopupView = BI.inherit(BI.Widget, { items: [{ el: this.arrowWrapper, left: 0, - top: 0, + top: 0 }, { el: this.placeholder }] @@ -131,7 +133,7 @@ BI.PopupView = BI.inherit(BI.Widget, { _createView: function () { var o = this.options; - this.button_group = BI.createWidget(o.el, {type: "bi.button_group", value: o.value}); + this.button_group = BI.createWidget(o.el, { type: "bi.button_group", value: o.value }); this.button_group.element.css({ "min-height": BI.isNumeric(o.minHeight) ? (o.minHeight / BI.pixRatio + BI.pixUnit) : o.minHeight, "padding-top": o.innerVgap / BI.pixRatio + BI.pixUnit, @@ -139,6 +141,7 @@ BI.PopupView = BI.inherit(BI.Widget, { "padding-left": o.innerHgap / BI.pixRatio + BI.pixUnit, "padding-right": o.innerHgap / BI.pixRatio + BI.pixUnit }); + return this.button_group; }, @@ -147,6 +150,7 @@ BI.PopupView = BI.inherit(BI.Widget, { if (false === o.tool) { return; } + return BI.createWidget(o.tool); }, @@ -155,6 +159,7 @@ BI.PopupView = BI.inherit(BI.Widget, { if (o.tabs.length === 0) { return; } + return BI.createWidget({ type: "bi.center", cls: "list-view-tab", @@ -218,7 +223,7 @@ BI.PopupView = BI.inherit(BI.Widget, { top: o.tgap + o.vgap, left: 0, right: "", - bottom: "", + bottom: "" }; placeholderStyle = { left: 0, @@ -237,7 +242,7 @@ BI.PopupView = BI.inherit(BI.Widget, { top: o.bgap + o.vgap, left: "", right: 0, - bottom: "", + bottom: "" }; placeholderStyle = { left: 0, @@ -257,14 +262,14 @@ BI.PopupView = BI.inherit(BI.Widget, { bottom: o.bgap + o.vgap, left: 0, right: "", - top: "", + top: "" }; placeholderStyle = { left: 0, right: 0, height: this._const.TRIANGLE_LENGTH, top: "", - bottom: -this._const.TRIANGLE_LENGTH, + bottom: -this._const.TRIANGLE_LENGTH }; break; case "top,left": @@ -276,14 +281,14 @@ BI.PopupView = BI.inherit(BI.Widget, { bottom: o.bgap + o.vgap, right: 0, left: "", - top: "", + top: "" }; placeholderStyle = { left: 0, right: 0, height: this._const.TRIANGLE_LENGTH, top: "", - bottom: -this._const.TRIANGLE_LENGTH, + bottom: -this._const.TRIANGLE_LENGTH }; break; case "left": @@ -296,7 +301,7 @@ BI.PopupView = BI.inherit(BI.Widget, { right: o.rgap + o.hgap, top: 0, bottom: "", - left: "", + left: "" }; placeholderStyle = { top: 0, @@ -315,7 +320,7 @@ BI.PopupView = BI.inherit(BI.Widget, { right: o.rgap + o.hgap, bottom: 0, top: "", - left: "", + left: "" }; placeholderStyle = { top: 0, @@ -335,7 +340,7 @@ BI.PopupView = BI.inherit(BI.Widget, { left: o.lgap + o.hgap, top: 0, bottom: "", - right: "", + right: "" }; placeholderStyle = { top: 0, @@ -354,7 +359,7 @@ BI.PopupView = BI.inherit(BI.Widget, { left: o.lgap + o.hgap, bottom: 0, top: "", - right: "", + right: "" }; placeholderStyle = { top: 0, @@ -372,8 +377,15 @@ BI.PopupView = BI.inherit(BI.Widget, { break; case "innerLeft": break; + default: + break; } - this.element.removeClass("left").removeClass("right").removeClass("top").removeClass("bottom").addClass(direction); + this.element + .removeClass("left") + .removeClass("right") + .removeClass("top") + .removeClass("bottom") + .addClass(direction); this.arrow.element.css(style); this.arrowWrapper.element.css(wrapperStyle); this.placeholder.element.css(placeholderStyle); @@ -399,7 +411,7 @@ BI.PopupView = BI.inherit(BI.Widget, { toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0); var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVgap; this.view.resetHeight ? this.view.resetHeight(resetHeight) : - this.view.element.css({"max-height": resetHeight / BI.pixRatio + BI.pixUnit}); + this.view.element.css({ "max-height": resetHeight / BI.pixRatio + BI.pixUnit }); }, setValue: function (selectedValues) { diff --git a/src/base/layer/layer.searcher.js b/src/base/layer/layer.searcher.js index 12867ed93..0d0f475fa 100644 --- a/src/base/layer/layer.searcher.js +++ b/src/base/layer/layer.searcher.js @@ -9,12 +9,13 @@ BI.SearcherView = BI.inherit(BI.Pane, { _defaultConfig: function () { var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card", tipText: BI.i18nText("BI-No_Select"), chooseType: BI.Selection.Single, - matcher: {// 完全匹配的构造器 + matcher: { // 完全匹配的构造器 type: "bi.button_group", behaviors: { redmark: function () { diff --git a/src/base/list/listview.js b/src/base/list/listview.js index 65f777a99..bca51e3cc 100644 --- a/src/base/list/listview.js +++ b/src/base/list/listview.js @@ -21,13 +21,13 @@ BI.ListView = BI.inherit(BI.Widget, { }, init: function () { - var self = this; this.renderedIndex = -1; this.cache = {}; }, render: function () { var self = this, o = this.options; + return { type: "bi.vertical", items: [BI.extend({ @@ -72,10 +72,11 @@ BI.ListView = BI.inherit(BI.Widget, { var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0; var cnt = this.renderedIndex + 1; var lastHeight; - var getElementHeight = function () { + function getElementHeight () { return self.container.element.height(); - }; - while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { + } + lastHeight = getElementHeight(); + while ((lastHeight) < minContentHeight && index < o.items.length) { var items = o.items.slice(index, index + o.blockSize); this.container.addItems(items.map(function (item, i) { return o.itemFormatter(item, index + i); @@ -93,7 +94,6 @@ BI.ListView = BI.inherit(BI.Widget, { }, _calculateBlocksToRender: function () { - var o = this.options; this._renderMoreIf(); }, diff --git a/src/base/list/virtualgrouplist.js b/src/base/list/virtualgrouplist.js index cb8d1b533..2dc5f97a5 100644 --- a/src/base/list/virtualgrouplist.js +++ b/src/base/list/virtualgrouplist.js @@ -27,6 +27,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, { render: function () { var self = this, o = this.options; + return { type: "bi.vertical", items: [{ diff --git a/src/base/list/virtuallist.js b/src/base/list/virtuallist.js index d5881b30b..7ae32143a 100644 --- a/src/base/list/virtuallist.js +++ b/src/base/list/virtuallist.js @@ -20,13 +20,13 @@ BI.VirtualList = BI.inherit(BI.Widget, { }, init: function () { - var self = this; this.renderedIndex = -1; this.cache = {}; }, render: function () { - var self = this, o = this.options; + var self = this; + return { type: "bi.vertical", items: [{ @@ -45,7 +45,7 @@ BI.VirtualList = BI.inherit(BI.Widget, { ref: function () { self.bottomBlank = this; } - }], + }] }; }, diff --git a/src/base/tree/customtree.js b/src/base/tree/customtree.js index a72edba2a..fc7ce4736 100644 --- a/src/base/tree/customtree.js +++ b/src/base/tree/customtree.js @@ -47,7 +47,7 @@ BI.CustomTree = BI.inherit(BI.Widget, { el: { value: node.value }, - popup: {type: "bi.custom_tree"} + popup: { type: "bi.custom_tree" } }, BI.deepClone(o.expander), { id: node.id, pId: node.pId @@ -68,6 +68,7 @@ BI.CustomTree = BI.inherit(BI.Widget, { } var args = Array.prototype.slice.call(arguments, 0); args[0].node = node; + return o.itemsCreator.apply(self, args); }; BI.isNull(item.popup.el) && (item.popup.el = BI.deepClone(o.el)); @@ -76,6 +77,7 @@ BI.CustomTree = BI.inherit(BI.Widget, { items.push(node); } }); + return items; }, @@ -145,4 +147,4 @@ BI.CustomTree = BI.inherit(BI.Widget, { }); BI.CustomTree.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.custom_tree", BI.CustomTree); \ No newline at end of file +BI.shortcut("bi.custom_tree", BI.CustomTree);