From c302441d95265d4e92c31dde958908f7d90607a7 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 27 Mar 2017 21:01:10 +0800 Subject: [PATCH] add --- bi/base.js | 113 ++++----- bi/case.js | 2 +- bi/core.js | 267 ++++++++------------- bi/widget.js | 8 +- demo/js/core/abstract/demo.button_group.js | 58 ++++- dist/base.js | 113 ++++----- dist/case.js | 2 +- dist/core.js | 267 ++++++++------------- dist/widget.js | 8 +- src/base/combination/group.button.js | 58 ++--- src/base/combination/navigation.js | 53 ++-- src/base/combination/tab.js | 2 +- src/case/loader/sort.list.js | 2 +- src/core/action/action.show.effect.js | 88 ------- src/core/action/action.show.js | 17 +- src/core/action/action.show.scale.js | 32 --- src/core/view.js | 2 +- src/core/widget.js | 28 ++- src/core/wrapper/layout.js | 19 +- src/core/wrapper/layout/layout.card.js | 83 ++++--- src/widget/arrangement/arrangement.js | 8 +- 21 files changed, 525 insertions(+), 705 deletions(-) delete mode 100644 src/core/action/action.show.effect.js delete mode 100644 src/core/action/action.show.scale.js diff --git a/bi/base.js b/bi/base.js index 6a1ab582f3..b85a2d5a99 100644 --- a/bi/base.js +++ b/bi/base.js @@ -1034,7 +1034,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { _packageBtns: function (btns) { var o = this.options; - for (var i = o.layouts.length - 1; i > 0; i--) { btns = BI.map(btns, function (k, it) { return BI.extend({}, o.layouts[i], { @@ -1049,6 +1048,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] + }) + }) + }, + _packageItems: function (items, packBtns) { return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); }, @@ -1064,6 +1075,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { return layout; }, + //如果是一个简单的layout + _isSimpleLayout: function () { + var o = this.options; + return o.layouts.length === 1 + }, + doBehavior: function () { var args = Array.prototype.slice.call(arguments); @@ -1078,9 +1095,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); - //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.prependItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); return; } @@ -1095,8 +1110,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.buttons = BI.concat(this.buttons, btns); //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.addItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); return; } @@ -1105,36 +1119,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.layouts.addItems(this._packageLayout(items).items); }, - removeItemAt: function (indexes) { - var self = this; - indexes = BI.isArray(indexes) ? indexes : [indexes]; - var buttons = []; - BI.each(indexes, function (i, index) { - buttons.push(self.buttons[index]); - }); - BI.each(buttons, function (i, btn) { - btn && btn.destroy(); - }) - }, - - removeItems: function (v) { - v = BI.isArray(v) ? v : [v]; - var indexes = []; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { - indexes.push(i); - } - }); - this.removeItemAt(indexes); + removeItemAt: function (index) { + this.buttons[index].destroy(); + this.layouts.removeItemAt(index); }, populate: function (items) { items = items || []; - this.options.items = items; this.empty(); + this.options.items = items; this.buttons = this._btnsCreator.apply(this, arguments); - items = this._packageItems(items, this._packageBtns(this.buttons)); + if (this._isSimpleLayout()) { + items = this._packageSimpleItems(this.buttons); + } else { + items = this._packageItems(items, this._packageBtns(this.buttons)); + } this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); }, @@ -3893,8 +3893,8 @@ BI.shortcut("bi.loader", BI.Loader);/** */ BI.Navigation = BI.inherit(BI.Widget, { - _defaultConfig: function(){ - return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { + _defaultConfig: function () { + return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { direction: "bottom",//top, bottom, left, right, custom logic: { dynamic: false @@ -3905,7 +3905,7 @@ BI.Navigation = BI.inherit(BI.Widget, { items: [], layouts: [] }, - cardCreator: function(v){ + cardCreator: function (v) { return BI.createWidget(); }, @@ -3914,8 +3914,7 @@ BI.Navigation = BI.inherit(BI.Widget, { }) }, - _init: function(){ - BI.Navigation.superclass._init.apply(this,arguments); + render: function () { var self = this, o = this.options; this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.cardMap = {}; @@ -3933,10 +3932,10 @@ BI.Navigation = BI.inherit(BI.Widget, { new BI.ShowListener({ eventObj: this.tab, cardLayout: this.layout, - cardNameCreator: function(v){ + cardNameCreator: function (v) { return self.showIndex + v; }, - cardCreator: function(v){ + cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; return card; @@ -3944,37 +3943,41 @@ BI.Navigation = BI.inherit(BI.Widget, { afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardShow: BI.bind(this.afterCardShow, this) }) - if(o.defaultShowIndex !== false){ + }, + + mounted: function () { + var o = this.options; + if (o.defaultShowIndex !== false) { this.setSelect(o.defaultShowIndex); } }, - afterCardCreated: function(v){ + afterCardCreated: function (v) { var self = this; - this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function(type, value, obj){ + this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if(type === BI.Events.CLICK) { + if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } }) this.options.afterCardCreated.apply(this, arguments); }, - afterCardShow: function(v){ + afterCardShow: function (v) { this.showIndex = v; this.options.afterCardShow.apply(this, arguments); }, - populate: function(){ + populate: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.populate.apply(card, arguments); } }, - setSelect: function(v){ + setSelect: function (v) { this.showIndex = v; - if(!this.layout.isCardExisted(v)){ + if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); @@ -3984,12 +3987,12 @@ BI.Navigation = BI.inherit(BI.Widget, { BI.nextTick(BI.bind(this.afterCardShow, this, v)); }, - getSelect: function(){ + getSelect: function () { return this.showIndex; }, - getSelectedCard: function(){ - if(BI.isKey(this.showIndex)){ + getSelectedCard: function () { + if (BI.isKey(this.showIndex)) { return this.cardMap[this.showIndex]; } }, @@ -3997,9 +4000,9 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - setValue: function(v){ + setValue: function (v) { var card = this.layout.getShowingCard(); - if(card){ + if (card) { card.setValue(v); } }, @@ -4007,19 +4010,19 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - getValue: function(){ + getValue: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.getValue(); } }, - empty: function(){ + empty: function () { this.layout.deleteAllCard(); this.cardMap = {}; }, - destroy: function(){ + destroy: function () { BI.Navigation.superclass.destroy.apply(this, arguments); } }); @@ -4615,7 +4618,7 @@ BI.Tab = BI.inherit(BI.Widget, { logic: { dynamic: false }, - defaultShowIndex: 0, + defaultShowIndex: false, tab: false, cardCreator: function (v) { return BI.createWidget(); diff --git a/bi/case.js b/bi/case.js index 96c0ff9952..e4215d7248 100644 --- a/bi/case.js +++ b/bi/case.js @@ -8384,7 +8384,7 @@ BI.SortList = BI.inherit(BI.Widget, { placeholder: { element: function ($currentItem) { var holder = BI.createWidget({ - type: "bi.label", + type: "bi.layout", cls: "bi-sortable-holder", height: $currentItem.outerHeight() }); diff --git a/bi/core.js b/bi/core.js index 614b5119ed..ae283440f6 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4587,14 +4587,6 @@ BI.Widget = BI.inherit(BI.OB, { this._initElementHeight(); }, - setElement: function (widget) { - if (widget == this) { - return; - } - this.element = BI.isWidget(widget) ? widget.element : $(widget); - return this; - }, - setEnable: function (enable) { if (enable === true) { this.options.disabled = false; @@ -4676,8 +4668,17 @@ BI.Widget = BI.inherit(BI.OB, { return widget; }, - removeWidget: function (name) { - delete this._children[name]; + removeWidget: function (nameOrWidget) { + var self = this; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, widget) { + if (widget === nameOrWidget) { + delete self._children[name]; + } + }) + } else { + delete this._children[nameOrWidget]; + } }, hasWidget: function (name) { @@ -4751,6 +4752,13 @@ BI.Widget = BI.inherit(BI.OB, { this.setVisible(true); }, + isolate: function () { + if (this._parent) { + this._parent.removeWidget(this); + BI.DOM.hang([this]); + } + }, + empty: function () { BI.each(this._children, function (i, widget) { widget._unMount(); @@ -5383,7 +5391,6 @@ BI.View = BI.inherit(BI.V, { options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel)); if (this._cardLayouts[key]) { options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); - this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize(); return this; } this._cardLayouts[key] = BI.createWidget({ @@ -5741,6 +5748,7 @@ BI.View = BI.inherit(BI.V, { delete this._cardLayouts; delete this._cards; this.remove(); + this.trigger(BI.Events.DESTROY); this.destroyed(); }, @@ -11211,7 +11219,6 @@ BI.Layout = BI.inherit(BI.Widget, { var self = this, w; if (!this.hasWidget(this._getChildName(i))) { w = BI.createWidget(item); - this.addWidget(this._getChildName(i), w); w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { @@ -11219,6 +11226,7 @@ BI.Layout = BI.inherit(BI.Widget, { } }); }); + this.addWidget(this._getChildName(i), w); } else { w = this.getWidgetByName(this._getChildName(i)); } @@ -11489,6 +11497,23 @@ BI.Layout = BI.inherit(BI.Widget, { }); }, + removeWidget: function (nameOrWidget) { + var removeIndex; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeIndex = name; + } + }) + } else { + removeIndex = nameOrWidget; + } + if (removeIndex) { + this.options.items.splice(removeIndex, 1); + } + BI.Layout.superclass.removeWidget.apply(this, arguments); + }, + empty: function () { BI.Layout.superclass.empty.apply(this, arguments); this.options.items = []; @@ -13273,27 +13298,28 @@ BI.CardLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - _getCardName: function (cardName) { - return this.getName() + cardName; - }, - resize: function () { // console.log("default布局不需要resize"); }, stroke: function (items) { - var self = this; + var self = this, o = this.options; this.showIndex = void 0; BI.each(items, function (i, item) { if (!!item) { - if (!self.hasWidget(self._getCardName(item.cardName))) { + if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); - self.addWidget(self._getCardName(item.cardName), w); w.on(BI.Events.DESTROY, function () { - delete self._children[self._getCardName(item.cardName)]; + var index = BI.findKey(o.items, function (i, tItem) { + return tItem.cardName == item.cardName; + }); + if (index > -1) { + o.items.splice(index, 1); + } }); + self.addWidget(item.cardName, w); } else { - var w = self.getWidgetByName(self._getCardName(item.cardName)); + var w = self.getWidgetByName(item.cardName); } w.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"}); w.setVisible(false); @@ -13304,6 +13330,11 @@ BI.CardLayout = BI.inherit(BI.Layout, { update: function () { }, + empty: function () { + BI.CardLayout.superclass.empty.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { BI.CardLayout.superclass.populate.apply(this, arguments); this._mount(); @@ -13311,53 +13342,62 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, isCardExisted: function (cardName) { - return this.hasWidget(this._getCardName(cardName)); + return BI.some(this.options.items, function (i, item) { + return item.cardName === cardName && item.el; + }); }, getCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { + if (!this.isCardExisted(cardName)) { throw new Error("cardName is not exist"); } - return this._children[this._getCardName(cardName)]; + return this._children[cardName]; }, deleteCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { - return; + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); } var index = BI.findKey(this.options.items, function (i, item) { return item.cardName == cardName; }); - this.options.items.splice(index, 1); - var child = this.getWidgetByName(this._getCardName(cardName)); - delete this._children[this._getCardName(cardName)]; - child.destroy(); + if (index > -1) { + this.options.items.splice(index, 1); + } + var child = this._children[cardName]; + child && child.destroy(); }, addCardByName: function (cardName, cardItem) { - if (this.hasWidget(this._getCardName(cardName))) { + if (this.isCardExisted(cardName)) { throw new Error("cardName is already exist"); } - this.options.items.push({el: cardItem, cardName: cardName}); var widget = BI.createWidget(cardItem); - widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) - .appendTo(this.element); + widget.element.css({ + "position": "relative", + "top": "0", + "left": "0", + "width": "100%", + "height": "100%" + }).appendTo(this.element); widget.invisible(); - this.addWidget(this._getCardName(cardName), widget); + this.addWidget(cardName, widget); + this.options.items.push({el: cardItem, cardName: cardName}); return widget; }, showCardByName: function (name, action, callback) { var self = this; //name不存在的时候全部隐藏 - var exist = this.hasWidget(this._getCardName(name)); + var exist = this.isCardExisted(name); if (this.showIndex != null) { this.lastShowIndex = this.showIndex; } - this.showIndex = this._getCardName(name); + this.showIndex = name; var flag = false; - BI.each(this._children, function (i, el) { - if (self._getCardName(name) != i) { + BI.each(this.options.items, function (i, item) { + var el = self._children[item.cardName]; + if (name != item.cardName) { //动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了 !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible(); } else { @@ -13369,8 +13409,8 @@ BI.CardLayout = BI.inherit(BI.Layout, { showLastCard: function () { var self = this; this.showIndex = this.lastShowIndex; - BI.each(this._children, function (i, el) { - el.setVisible(self.showIndex == i); + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].setVisible(self.showIndex == i); }) }, @@ -13404,15 +13444,17 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, hideAllCard: function () { - BI.each(this._children, function (i, el) { - el.invisible(); + var self = this; + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].invisible(); }); }, isAllCardHide: function () { + var self = this; var flag = true; - BI.some(this._children, function (i, el) { - if (el.isVisible()) { + BI.some(this.options.items, function (i, item) { + if (self._children[item.cardName].isVisible()) { flag = false; return false; } @@ -15254,147 +15296,30 @@ BI.ActionFactory = { return new action(options); } }/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.EffectShowAction - * @extends BI.Action - */ -BI.EffectShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.EffectShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.EffectShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ - src = src || this.options.src ,tar = tar || this.options.tar || "body"; - - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - - transferEl.element.css({ - width: tar.element.width(), - height: tar.element.height(), - top: tar.element.offset().top, - left: tar.element.offset().left - }); - - src.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - tar && tar.element.show(0, callback); - }) - } else { - tar && tar.element.show(0, callback); - } - }, - - actionBack: function(tar, src, callback){ - src = src || this.options.src || $("body"),tar = tar || this.options.tar; - tar && tar.element.hide(); - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - transferEl.element.css({ - width: src.element.width(), - height: src.element.height(), - top: src.element.offset().top, - left: src.element.offset().left - }); - - tar.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - callback && callback(); - }) - } else { - callback && callback(); - } - } -});/** * guy * 由一个元素切换到另一个元素的行为 * @class BI.ShowAction * @extends BI.Action */ BI.ShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { - }); + _defaultConfig: function () { + return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {}); }, - _init : function() { + _init: function () { BI.ShowAction.superclass._init.apply(this, arguments); }, - actionPerformed: function(src, tar, callback){ - tar = tar || this.options.tar; - tar && tar.element.show(0, callback); - }, - - actionBack: function(tar, src, callback){ - tar = tar || this.options.tar; - tar.element.hide(0, callback); - } -});/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.ScaleShowAction - * @extends BI.Action - * @abstract - */ -BI.ScaleShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ScaleShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.ScaleShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ + actionPerformed: function (src, tar, callback) { tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.show("scale", {percent:110}, 200, callback) : tar.element.show(0,callback); + tar.setVisible(true); + callback && callback(); }, - actionBack : function(tar, src, callback){ + actionBack: function (tar, src, callback) { tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.hide("scale", {percent:0}, 200, callback) : tar.element.hide(0,callback); + tar.setVisible(false); + callback && callback(); } });/** * @class BI.FloatSection diff --git a/bi/widget.js b/bi/widget.js index c2be3e4d39..42a46c18d7 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -3020,7 +3020,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { _moveElement: function (layout, l, x, y, isUserAction) { var self = this; - if (l.static) { + if (l._static) { return layout; } @@ -3053,7 +3053,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { continue; } - if (collision.static) { + if (collision._static) { layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); } else { layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); @@ -3146,7 +3146,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { for (var i = 0, len = sorted.length; i < len; i++) { var l = sorted[i]; - if (!l.static) { + if (!l._static) { l = this._compactItem(compareWith, l, verticalCompact); compareWith.push(l); @@ -3160,7 +3160,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { return out; function getStatics(layout) { return BI.filter(layout, function (i, l) { - return l.static; + return l._static; }); } }, diff --git a/demo/js/core/abstract/demo.button_group.js b/demo/js/core/abstract/demo.button_group.js index dbdf470a79..6a45c11332 100644 --- a/demo/js/core/abstract/demo.button_group.js +++ b/demo/js/core/abstract/demo.button_group.js @@ -3,21 +3,59 @@ Demo.Func = BI.inherit(BI.Widget, { baseCls: "demo-func" }, render: function () { + var ref; return { - type: "bi.button_group", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE, - layouts: [{ - type: "bi.vertical" - }, { - type: "bi.center_adapt", - }], + type: "bi.vertical", items: [{ - type: "bi.label", - text: "button_group是一类具有相同属性或相似属性的抽象, 本案例实现的是布局的嵌套(vertical布局下内嵌center_adapt布局)" + type: "bi.button_group", + ref: function (_ref) { + ref = _ref; + }, + chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE, + layouts: [{ + type: "bi.vertical", + items: [{ + type: "bi.vtape", + height: 200, + }] + }], + items: [{ + el: { + type: "bi.label", + text: "button_group是一类具有相同属性或相似属性的抽象, 本案例实现的是布局的嵌套(vertical布局下内嵌center_adapt布局)" + }, + height: 150, + }, { + el: { + type: "bi.button", + text: "1" + } + }] }, { type: "bi.button", - text: "1" + text: "populate", + handler: function () { + ref.populate([{ + el: { + type: "bi.label", + text: "1" + }, + height: 50 + }, { + el: { + type: "bi.button", + text: "2" + }, + height: 50 + }, { + el: { + type: "bi.label", + text: "3" + } + }]) + } }] + } } }); diff --git a/dist/base.js b/dist/base.js index 6a1ab582f3..b85a2d5a99 100644 --- a/dist/base.js +++ b/dist/base.js @@ -1034,7 +1034,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { _packageBtns: function (btns) { var o = this.options; - for (var i = o.layouts.length - 1; i > 0; i--) { btns = BI.map(btns, function (k, it) { return BI.extend({}, o.layouts[i], { @@ -1049,6 +1048,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] + }) + }) + }, + _packageItems: function (items, packBtns) { return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); }, @@ -1064,6 +1075,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { return layout; }, + //如果是一个简单的layout + _isSimpleLayout: function () { + var o = this.options; + return o.layouts.length === 1 + }, + doBehavior: function () { var args = Array.prototype.slice.call(arguments); @@ -1078,9 +1095,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); - //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.prependItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); return; } @@ -1095,8 +1110,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.buttons = BI.concat(this.buttons, btns); //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.addItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); return; } @@ -1105,36 +1119,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.layouts.addItems(this._packageLayout(items).items); }, - removeItemAt: function (indexes) { - var self = this; - indexes = BI.isArray(indexes) ? indexes : [indexes]; - var buttons = []; - BI.each(indexes, function (i, index) { - buttons.push(self.buttons[index]); - }); - BI.each(buttons, function (i, btn) { - btn && btn.destroy(); - }) - }, - - removeItems: function (v) { - v = BI.isArray(v) ? v : [v]; - var indexes = []; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { - indexes.push(i); - } - }); - this.removeItemAt(indexes); + removeItemAt: function (index) { + this.buttons[index].destroy(); + this.layouts.removeItemAt(index); }, populate: function (items) { items = items || []; - this.options.items = items; this.empty(); + this.options.items = items; this.buttons = this._btnsCreator.apply(this, arguments); - items = this._packageItems(items, this._packageBtns(this.buttons)); + if (this._isSimpleLayout()) { + items = this._packageSimpleItems(this.buttons); + } else { + items = this._packageItems(items, this._packageBtns(this.buttons)); + } this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); }, @@ -3893,8 +3893,8 @@ BI.shortcut("bi.loader", BI.Loader);/** */ BI.Navigation = BI.inherit(BI.Widget, { - _defaultConfig: function(){ - return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { + _defaultConfig: function () { + return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { direction: "bottom",//top, bottom, left, right, custom logic: { dynamic: false @@ -3905,7 +3905,7 @@ BI.Navigation = BI.inherit(BI.Widget, { items: [], layouts: [] }, - cardCreator: function(v){ + cardCreator: function (v) { return BI.createWidget(); }, @@ -3914,8 +3914,7 @@ BI.Navigation = BI.inherit(BI.Widget, { }) }, - _init: function(){ - BI.Navigation.superclass._init.apply(this,arguments); + render: function () { var self = this, o = this.options; this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.cardMap = {}; @@ -3933,10 +3932,10 @@ BI.Navigation = BI.inherit(BI.Widget, { new BI.ShowListener({ eventObj: this.tab, cardLayout: this.layout, - cardNameCreator: function(v){ + cardNameCreator: function (v) { return self.showIndex + v; }, - cardCreator: function(v){ + cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; return card; @@ -3944,37 +3943,41 @@ BI.Navigation = BI.inherit(BI.Widget, { afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardShow: BI.bind(this.afterCardShow, this) }) - if(o.defaultShowIndex !== false){ + }, + + mounted: function () { + var o = this.options; + if (o.defaultShowIndex !== false) { this.setSelect(o.defaultShowIndex); } }, - afterCardCreated: function(v){ + afterCardCreated: function (v) { var self = this; - this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function(type, value, obj){ + this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if(type === BI.Events.CLICK) { + if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } }) this.options.afterCardCreated.apply(this, arguments); }, - afterCardShow: function(v){ + afterCardShow: function (v) { this.showIndex = v; this.options.afterCardShow.apply(this, arguments); }, - populate: function(){ + populate: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.populate.apply(card, arguments); } }, - setSelect: function(v){ + setSelect: function (v) { this.showIndex = v; - if(!this.layout.isCardExisted(v)){ + if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); @@ -3984,12 +3987,12 @@ BI.Navigation = BI.inherit(BI.Widget, { BI.nextTick(BI.bind(this.afterCardShow, this, v)); }, - getSelect: function(){ + getSelect: function () { return this.showIndex; }, - getSelectedCard: function(){ - if(BI.isKey(this.showIndex)){ + getSelectedCard: function () { + if (BI.isKey(this.showIndex)) { return this.cardMap[this.showIndex]; } }, @@ -3997,9 +4000,9 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - setValue: function(v){ + setValue: function (v) { var card = this.layout.getShowingCard(); - if(card){ + if (card) { card.setValue(v); } }, @@ -4007,19 +4010,19 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - getValue: function(){ + getValue: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.getValue(); } }, - empty: function(){ + empty: function () { this.layout.deleteAllCard(); this.cardMap = {}; }, - destroy: function(){ + destroy: function () { BI.Navigation.superclass.destroy.apply(this, arguments); } }); @@ -4615,7 +4618,7 @@ BI.Tab = BI.inherit(BI.Widget, { logic: { dynamic: false }, - defaultShowIndex: 0, + defaultShowIndex: false, tab: false, cardCreator: function (v) { return BI.createWidget(); diff --git a/dist/case.js b/dist/case.js index 96c0ff9952..e4215d7248 100644 --- a/dist/case.js +++ b/dist/case.js @@ -8384,7 +8384,7 @@ BI.SortList = BI.inherit(BI.Widget, { placeholder: { element: function ($currentItem) { var holder = BI.createWidget({ - type: "bi.label", + type: "bi.layout", cls: "bi-sortable-holder", height: $currentItem.outerHeight() }); diff --git a/dist/core.js b/dist/core.js index 30f2f8af73..ceb4a35c63 100644 --- a/dist/core.js +++ b/dist/core.js @@ -14508,14 +14508,6 @@ BI.Widget = BI.inherit(BI.OB, { this._initElementHeight(); }, - setElement: function (widget) { - if (widget == this) { - return; - } - this.element = BI.isWidget(widget) ? widget.element : $(widget); - return this; - }, - setEnable: function (enable) { if (enable === true) { this.options.disabled = false; @@ -14597,8 +14589,17 @@ BI.Widget = BI.inherit(BI.OB, { return widget; }, - removeWidget: function (name) { - delete this._children[name]; + removeWidget: function (nameOrWidget) { + var self = this; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, widget) { + if (widget === nameOrWidget) { + delete self._children[name]; + } + }) + } else { + delete this._children[nameOrWidget]; + } }, hasWidget: function (name) { @@ -14672,6 +14673,13 @@ BI.Widget = BI.inherit(BI.OB, { this.setVisible(true); }, + isolate: function () { + if (this._parent) { + this._parent.removeWidget(this); + BI.DOM.hang([this]); + } + }, + empty: function () { BI.each(this._children, function (i, widget) { widget._unMount(); @@ -15304,7 +15312,6 @@ BI.View = BI.inherit(BI.V, { options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel)); if (this._cardLayouts[key]) { options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); - this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize(); return this; } this._cardLayouts[key] = BI.createWidget({ @@ -15662,6 +15669,7 @@ BI.View = BI.inherit(BI.V, { delete this._cardLayouts; delete this._cards; this.remove(); + this.trigger(BI.Events.DESTROY); this.destroyed(); }, @@ -19353,7 +19361,6 @@ BI.Layout = BI.inherit(BI.Widget, { var self = this, w; if (!this.hasWidget(this._getChildName(i))) { w = BI.createWidget(item); - this.addWidget(this._getChildName(i), w); w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { @@ -19361,6 +19368,7 @@ BI.Layout = BI.inherit(BI.Widget, { } }); }); + this.addWidget(this._getChildName(i), w); } else { w = this.getWidgetByName(this._getChildName(i)); } @@ -19631,6 +19639,23 @@ BI.Layout = BI.inherit(BI.Widget, { }); }, + removeWidget: function (nameOrWidget) { + var removeIndex; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeIndex = name; + } + }) + } else { + removeIndex = nameOrWidget; + } + if (removeIndex) { + this.options.items.splice(removeIndex, 1); + } + BI.Layout.superclass.removeWidget.apply(this, arguments); + }, + empty: function () { BI.Layout.superclass.empty.apply(this, arguments); this.options.items = []; @@ -19690,147 +19715,30 @@ BI.ActionFactory = { return new action(options); } }/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.EffectShowAction - * @extends BI.Action - */ -BI.EffectShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.EffectShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.EffectShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ - src = src || this.options.src ,tar = tar || this.options.tar || "body"; - - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - - transferEl.element.css({ - width: tar.element.width(), - height: tar.element.height(), - top: tar.element.offset().top, - left: tar.element.offset().left - }); - - src.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - tar && tar.element.show(0, callback); - }) - } else { - tar && tar.element.show(0, callback); - } - }, - - actionBack: function(tar, src, callback){ - src = src || this.options.src || $("body"),tar = tar || this.options.tar; - tar && tar.element.hide(); - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - transferEl.element.css({ - width: src.element.width(), - height: src.element.height(), - top: src.element.offset().top, - left: src.element.offset().left - }); - - tar.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - callback && callback(); - }) - } else { - callback && callback(); - } - } -});/** * guy * 由一个元素切换到另一个元素的行为 * @class BI.ShowAction * @extends BI.Action */ BI.ShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { - }); + _defaultConfig: function () { + return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {}); }, - _init : function() { + _init: function () { BI.ShowAction.superclass._init.apply(this, arguments); }, - actionPerformed: function(src, tar, callback){ + actionPerformed: function (src, tar, callback) { tar = tar || this.options.tar; - tar && tar.element.show(0, callback); + tar.setVisible(true); + callback && callback(); }, - actionBack: function(tar, src, callback){ + actionBack: function (tar, src, callback) { tar = tar || this.options.tar; - tar.element.hide(0, callback); - } -});/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.ScaleShowAction - * @extends BI.Action - * @abstract - */ -BI.ScaleShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ScaleShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.ScaleShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ - tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.show("scale", {percent:110}, 200, callback) : tar.element.show(0,callback); - }, - - actionBack : function(tar, src, callback){ - tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.hide("scale", {percent:0}, 200, callback) : tar.element.hide(0,callback); + tar.setVisible(false); + callback && callback(); } });/** * @class BI.FloatSection @@ -26804,27 +26712,28 @@ BI.CardLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - _getCardName: function (cardName) { - return this.getName() + cardName; - }, - resize: function () { // console.log("default布局不需要resize"); }, stroke: function (items) { - var self = this; + var self = this, o = this.options; this.showIndex = void 0; BI.each(items, function (i, item) { if (!!item) { - if (!self.hasWidget(self._getCardName(item.cardName))) { + if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); - self.addWidget(self._getCardName(item.cardName), w); w.on(BI.Events.DESTROY, function () { - delete self._children[self._getCardName(item.cardName)]; + var index = BI.findKey(o.items, function (i, tItem) { + return tItem.cardName == item.cardName; + }); + if (index > -1) { + o.items.splice(index, 1); + } }); + self.addWidget(item.cardName, w); } else { - var w = self.getWidgetByName(self._getCardName(item.cardName)); + var w = self.getWidgetByName(item.cardName); } w.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"}); w.setVisible(false); @@ -26835,6 +26744,11 @@ BI.CardLayout = BI.inherit(BI.Layout, { update: function () { }, + empty: function () { + BI.CardLayout.superclass.empty.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { BI.CardLayout.superclass.populate.apply(this, arguments); this._mount(); @@ -26842,53 +26756,62 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, isCardExisted: function (cardName) { - return this.hasWidget(this._getCardName(cardName)); + return BI.some(this.options.items, function (i, item) { + return item.cardName === cardName && item.el; + }); }, getCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { + if (!this.isCardExisted(cardName)) { throw new Error("cardName is not exist"); } - return this._children[this._getCardName(cardName)]; + return this._children[cardName]; }, deleteCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { - return; + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); } var index = BI.findKey(this.options.items, function (i, item) { return item.cardName == cardName; }); - this.options.items.splice(index, 1); - var child = this.getWidgetByName(this._getCardName(cardName)); - delete this._children[this._getCardName(cardName)]; - child.destroy(); + if (index > -1) { + this.options.items.splice(index, 1); + } + var child = this._children[cardName]; + child && child.destroy(); }, addCardByName: function (cardName, cardItem) { - if (this.hasWidget(this._getCardName(cardName))) { + if (this.isCardExisted(cardName)) { throw new Error("cardName is already exist"); } - this.options.items.push({el: cardItem, cardName: cardName}); var widget = BI.createWidget(cardItem); - widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) - .appendTo(this.element); + widget.element.css({ + "position": "relative", + "top": "0", + "left": "0", + "width": "100%", + "height": "100%" + }).appendTo(this.element); widget.invisible(); - this.addWidget(this._getCardName(cardName), widget); + this.addWidget(cardName, widget); + this.options.items.push({el: cardItem, cardName: cardName}); return widget; }, showCardByName: function (name, action, callback) { var self = this; //name不存在的时候全部隐藏 - var exist = this.hasWidget(this._getCardName(name)); + var exist = this.isCardExisted(name); if (this.showIndex != null) { this.lastShowIndex = this.showIndex; } - this.showIndex = this._getCardName(name); + this.showIndex = name; var flag = false; - BI.each(this._children, function (i, el) { - if (self._getCardName(name) != i) { + BI.each(this.options.items, function (i, item) { + var el = self._children[item.cardName]; + if (name != item.cardName) { //动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了 !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible(); } else { @@ -26900,8 +26823,8 @@ BI.CardLayout = BI.inherit(BI.Layout, { showLastCard: function () { var self = this; this.showIndex = this.lastShowIndex; - BI.each(this._children, function (i, el) { - el.setVisible(self.showIndex == i); + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].setVisible(self.showIndex == i); }) }, @@ -26935,15 +26858,17 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, hideAllCard: function () { - BI.each(this._children, function (i, el) { - el.invisible(); + var self = this; + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].invisible(); }); }, isAllCardHide: function () { + var self = this; var flag = true; - BI.some(this._children, function (i, el) { - if (el.isVisible()) { + BI.some(this.options.items, function (i, item) { + if (self._children[item.cardName].isVisible()) { flag = false; return false; } diff --git a/dist/widget.js b/dist/widget.js index c2be3e4d39..42a46c18d7 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -3020,7 +3020,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { _moveElement: function (layout, l, x, y, isUserAction) { var self = this; - if (l.static) { + if (l._static) { return layout; } @@ -3053,7 +3053,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { continue; } - if (collision.static) { + if (collision._static) { layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); } else { layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); @@ -3146,7 +3146,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { for (var i = 0, len = sorted.length; i < len; i++) { var l = sorted[i]; - if (!l.static) { + if (!l._static) { l = this._compactItem(compareWith, l, verticalCompact); compareWith.push(l); @@ -3160,7 +3160,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { return out; function getStatics(layout) { return BI.filter(layout, function (i, l) { - return l.static; + return l._static; }); } }, diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index 2ccc1fe1da..655960ab40 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -71,7 +71,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { _packageBtns: function (btns) { var o = this.options; - for (var i = o.layouts.length - 1; i > 0; i--) { btns = BI.map(btns, function (k, it) { return BI.extend({}, o.layouts[i], { @@ -86,6 +85,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] + }) + }) + }, + _packageItems: function (items, packBtns) { return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); }, @@ -101,6 +112,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { return layout; }, + //如果是一个简单的layout + _isSimpleLayout: function () { + var o = this.options; + return o.layouts.length === 1 + }, + doBehavior: function () { var args = Array.prototype.slice.call(arguments); @@ -115,9 +132,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); - //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.prependItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); return; } @@ -132,8 +147,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.buttons = BI.concat(this.buttons, btns); //如果是一个简单的layout - if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) - && this.layouts && this.layouts.addItems) { + if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); return; } @@ -142,36 +156,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { this.layouts.addItems(this._packageLayout(items).items); }, - removeItemAt: function (indexes) { - var self = this; - indexes = BI.isArray(indexes) ? indexes : [indexes]; - var buttons = []; - BI.each(indexes, function (i, index) { - buttons.push(self.buttons[index]); - }); - BI.each(buttons, function (i, btn) { - btn && btn.destroy(); - }) - }, - - removeItems: function (v) { - v = BI.isArray(v) ? v : [v]; - var indexes = []; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { - indexes.push(i); - } - }); - this.removeItemAt(indexes); + removeItemAt: function (index) { + this.buttons[index].destroy(); + this.layouts.removeItemAt(index); }, populate: function (items) { items = items || []; - this.options.items = items; this.empty(); + this.options.items = items; this.buttons = this._btnsCreator.apply(this, arguments); - items = this._packageItems(items, this._packageBtns(this.buttons)); + if (this._isSimpleLayout()) { + items = this._packageSimpleItems(this.buttons); + } else { + items = this._packageItems(items, this._packageBtns(this.buttons)); + } this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); }, diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index 272c95c126..c119f92bbc 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -3,8 +3,8 @@ */ BI.Navigation = BI.inherit(BI.Widget, { - _defaultConfig: function(){ - return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { + _defaultConfig: function () { + return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { direction: "bottom",//top, bottom, left, right, custom logic: { dynamic: false @@ -15,7 +15,7 @@ BI.Navigation = BI.inherit(BI.Widget, { items: [], layouts: [] }, - cardCreator: function(v){ + cardCreator: function (v) { return BI.createWidget(); }, @@ -24,8 +24,7 @@ BI.Navigation = BI.inherit(BI.Widget, { }) }, - _init: function(){ - BI.Navigation.superclass._init.apply(this,arguments); + render: function () { var self = this, o = this.options; this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.cardMap = {}; @@ -43,10 +42,10 @@ BI.Navigation = BI.inherit(BI.Widget, { new BI.ShowListener({ eventObj: this.tab, cardLayout: this.layout, - cardNameCreator: function(v){ + cardNameCreator: function (v) { return self.showIndex + v; }, - cardCreator: function(v){ + cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; return card; @@ -54,37 +53,41 @@ BI.Navigation = BI.inherit(BI.Widget, { afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardShow: BI.bind(this.afterCardShow, this) }) - if(o.defaultShowIndex !== false){ + }, + + mounted: function () { + var o = this.options; + if (o.defaultShowIndex !== false) { this.setSelect(o.defaultShowIndex); } }, - afterCardCreated: function(v){ + afterCardCreated: function (v) { var self = this; - this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function(type, value, obj){ + this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if(type === BI.Events.CLICK) { + if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } }) this.options.afterCardCreated.apply(this, arguments); }, - afterCardShow: function(v){ + afterCardShow: function (v) { this.showIndex = v; this.options.afterCardShow.apply(this, arguments); }, - populate: function(){ + populate: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.populate.apply(card, arguments); } }, - setSelect: function(v){ + setSelect: function (v) { this.showIndex = v; - if(!this.layout.isCardExisted(v)){ + if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); @@ -94,12 +97,12 @@ BI.Navigation = BI.inherit(BI.Widget, { BI.nextTick(BI.bind(this.afterCardShow, this, v)); }, - getSelect: function(){ + getSelect: function () { return this.showIndex; }, - getSelectedCard: function(){ - if(BI.isKey(this.showIndex)){ + getSelectedCard: function () { + if (BI.isKey(this.showIndex)) { return this.cardMap[this.showIndex]; } }, @@ -107,9 +110,9 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - setValue: function(v){ + setValue: function (v) { var card = this.layout.getShowingCard(); - if(card){ + if (card) { card.setValue(v); } }, @@ -117,19 +120,19 @@ BI.Navigation = BI.inherit(BI.Widget, { /** * @override */ - getValue: function(){ + getValue: function () { var card = this.layout.getShowingCard(); - if(card){ + if (card) { return card.getValue(); } }, - empty: function(){ + empty: function () { this.layout.deleteAllCard(); this.cardMap = {}; }, - destroy: function(){ + destroy: function () { BI.Navigation.superclass.destroy.apply(this, arguments); } }); diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 87dd4d1285..0c0b5e7fe0 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -10,7 +10,7 @@ BI.Tab = BI.inherit(BI.Widget, { logic: { dynamic: false }, - defaultShowIndex: 0, + defaultShowIndex: false, tab: false, cardCreator: function (v) { return BI.createWidget(); diff --git a/src/case/loader/sort.list.js b/src/case/loader/sort.list.js index 97f81c98a2..333d546915 100644 --- a/src/case/loader/sort.list.js +++ b/src/case/loader/sort.list.js @@ -65,7 +65,7 @@ BI.SortList = BI.inherit(BI.Widget, { placeholder: { element: function ($currentItem) { var holder = BI.createWidget({ - type: "bi.label", + type: "bi.layout", cls: "bi-sortable-holder", height: $currentItem.outerHeight() }); diff --git a/src/core/action/action.show.effect.js b/src/core/action/action.show.effect.js deleted file mode 100644 index bc9351208e..0000000000 --- a/src/core/action/action.show.effect.js +++ /dev/null @@ -1,88 +0,0 @@ -/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.EffectShowAction - * @extends BI.Action - */ -BI.EffectShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.EffectShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.EffectShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ - src = src || this.options.src ,tar = tar || this.options.tar || "body"; - - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - - transferEl.element.css({ - width: tar.element.width(), - height: tar.element.height(), - top: tar.element.offset().top, - left: tar.element.offset().left - }); - - src.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - tar && tar.element.show(0, callback); - }) - } else { - tar && tar.element.show(0, callback); - } - }, - - actionBack: function(tar, src, callback){ - src = src || this.options.src || $("body"),tar = tar || this.options.tar; - tar && tar.element.hide(); - if(this._checkBrowser()) { - var transferEl = BI.createWidget({ - type: "bi.layout", - cls: "bi-transfer-temp-el" - }) - - BI.createWidget({ - type: "bi.absolute", - element: "body", - items: [transferEl] - }) - transferEl.element.css({ - width: src.element.width(), - height: src.element.height(), - top: src.element.offset().top, - left: src.element.offset().left - }); - - tar.element.effect("transfer", { - to: transferEl.element, - className: "ui-effects-transfer" - }, 400, function () { - transferEl.destroy(); - callback && callback(); - }) - } else { - callback && callback(); - } - } -}); \ No newline at end of file diff --git a/src/core/action/action.show.js b/src/core/action/action.show.js index e29cfc8b8f..1f24c9a0ef 100644 --- a/src/core/action/action.show.js +++ b/src/core/action/action.show.js @@ -5,22 +5,23 @@ * @extends BI.Action */ BI.ShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { - }); + _defaultConfig: function () { + return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {}); }, - _init : function() { + _init: function () { BI.ShowAction.superclass._init.apply(this, arguments); }, - actionPerformed: function(src, tar, callback){ + actionPerformed: function (src, tar, callback) { tar = tar || this.options.tar; - tar && tar.element.show(0, callback); + tar.setVisible(true); + callback && callback(); }, - actionBack: function(tar, src, callback){ + actionBack: function (tar, src, callback) { tar = tar || this.options.tar; - tar.element.hide(0, callback); + tar.setVisible(false); + callback && callback(); } }); \ No newline at end of file diff --git a/src/core/action/action.show.scale.js b/src/core/action/action.show.scale.js deleted file mode 100644 index f06043fa65..0000000000 --- a/src/core/action/action.show.scale.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * guy - * 由一个元素切换到另一个元素的行为 - * @class BI.ScaleShowAction - * @extends BI.Action - * @abstract - */ -BI.ScaleShowAction = BI.inherit(BI.Action, { - _defaultConfig: function() { - return BI.extend(BI.ScaleShowAction.superclass._defaultConfig.apply(this, arguments), { - }); - }, - - _init : function() { - BI.ScaleShowAction.superclass._init.apply(this, arguments); - }, - - _checkBrowser: function(){ - return false; -// return !(BI.isFireFox() && parseInt($.browser.version) < 10); - }, - - actionPerformed: function(src, tar, callback){ - tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.show("scale", {percent:110}, 200, callback) : tar.element.show(0,callback); - }, - - actionBack : function(tar, src, callback){ - tar = tar || this.options.tar; - this._checkBrowser() ? tar.element.hide("scale", {percent:0}, 200, callback) : tar.element.hide(0,callback); - } -}); \ No newline at end of file diff --git a/src/core/view.js b/src/core/view.js index 0883a9da65..b5e19022d0 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -151,7 +151,6 @@ BI.View = BI.inherit(BI.V, { options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel)); if (this._cardLayouts[key]) { options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); - this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize(); return this; } this._cardLayouts[key] = BI.createWidget({ @@ -509,6 +508,7 @@ BI.View = BI.inherit(BI.V, { delete this._cardLayouts; delete this._cards; this.remove(); + this.trigger(BI.Events.DESTROY); this.destroyed(); }, diff --git a/src/core/widget.js b/src/core/widget.js index 20cf9c948b..90c1e8eb19 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -209,14 +209,6 @@ BI.Widget = BI.inherit(BI.OB, { this._initElementHeight(); }, - setElement: function (widget) { - if (widget == this) { - return; - } - this.element = BI.isWidget(widget) ? widget.element : $(widget); - return this; - }, - setEnable: function (enable) { if (enable === true) { this.options.disabled = false; @@ -298,8 +290,17 @@ BI.Widget = BI.inherit(BI.OB, { return widget; }, - removeWidget: function (name) { - delete this._children[name]; + removeWidget: function (nameOrWidget) { + var self = this; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, widget) { + if (widget === nameOrWidget) { + delete self._children[name]; + } + }) + } else { + delete this._children[nameOrWidget]; + } }, hasWidget: function (name) { @@ -373,6 +374,13 @@ BI.Widget = BI.inherit(BI.OB, { this.setVisible(true); }, + isolate: function () { + if (this._parent) { + this._parent.removeWidget(this); + BI.DOM.hang([this]); + } + }, + empty: function () { BI.each(this._children, function (i, widget) { widget._unMount(); diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 7cadb57fa7..477c5d7ce7 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -71,7 +71,6 @@ BI.Layout = BI.inherit(BI.Widget, { var self = this, w; if (!this.hasWidget(this._getChildName(i))) { w = BI.createWidget(item); - this.addWidget(this._getChildName(i), w); w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { @@ -79,6 +78,7 @@ BI.Layout = BI.inherit(BI.Widget, { } }); }); + this.addWidget(this._getChildName(i), w); } else { w = this.getWidgetByName(this._getChildName(i)); } @@ -349,6 +349,23 @@ BI.Layout = BI.inherit(BI.Widget, { }); }, + removeWidget: function (nameOrWidget) { + var removeIndex; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeIndex = name; + } + }) + } else { + removeIndex = nameOrWidget; + } + if (removeIndex) { + this.options.items.splice(removeIndex, 1); + } + BI.Layout.superclass.removeWidget.apply(this, arguments); + }, + empty: function () { BI.Layout.superclass.empty.apply(this, arguments); this.options.items = []; diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index d4ea610d4e..9711da9e2e 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -18,27 +18,28 @@ BI.CardLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - _getCardName: function (cardName) { - return this.getName() + cardName; - }, - resize: function () { // console.log("default布局不需要resize"); }, stroke: function (items) { - var self = this; + var self = this, o = this.options; this.showIndex = void 0; BI.each(items, function (i, item) { if (!!item) { - if (!self.hasWidget(self._getCardName(item.cardName))) { + if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); - self.addWidget(self._getCardName(item.cardName), w); w.on(BI.Events.DESTROY, function () { - delete self._children[self._getCardName(item.cardName)]; + var index = BI.findKey(o.items, function (i, tItem) { + return tItem.cardName == item.cardName; + }); + if (index > -1) { + o.items.splice(index, 1); + } }); + self.addWidget(item.cardName, w); } else { - var w = self.getWidgetByName(self._getCardName(item.cardName)); + var w = self.getWidgetByName(item.cardName); } w.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"}); w.setVisible(false); @@ -49,6 +50,11 @@ BI.CardLayout = BI.inherit(BI.Layout, { update: function () { }, + empty: function () { + BI.CardLayout.superclass.empty.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { BI.CardLayout.superclass.populate.apply(this, arguments); this._mount(); @@ -56,53 +62,62 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, isCardExisted: function (cardName) { - return this.hasWidget(this._getCardName(cardName)); + return BI.some(this.options.items, function (i, item) { + return item.cardName === cardName && item.el; + }); }, getCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { + if (!this.isCardExisted(cardName)) { throw new Error("cardName is not exist"); } - return this._children[this._getCardName(cardName)]; + return this._children[cardName]; }, deleteCardByName: function (cardName) { - if (!this.hasWidget(this._getCardName(cardName))) { - return; + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); } var index = BI.findKey(this.options.items, function (i, item) { return item.cardName == cardName; }); - this.options.items.splice(index, 1); - var child = this.getWidgetByName(this._getCardName(cardName)); - delete this._children[this._getCardName(cardName)]; - child.destroy(); + if (index > -1) { + this.options.items.splice(index, 1); + } + var child = this._children[cardName]; + child && child.destroy(); }, addCardByName: function (cardName, cardItem) { - if (this.hasWidget(this._getCardName(cardName))) { + if (this.isCardExisted(cardName)) { throw new Error("cardName is already exist"); } - this.options.items.push({el: cardItem, cardName: cardName}); var widget = BI.createWidget(cardItem); - widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) - .appendTo(this.element); + widget.element.css({ + "position": "relative", + "top": "0", + "left": "0", + "width": "100%", + "height": "100%" + }).appendTo(this.element); widget.invisible(); - this.addWidget(this._getCardName(cardName), widget); + this.addWidget(cardName, widget); + this.options.items.push({el: cardItem, cardName: cardName}); return widget; }, showCardByName: function (name, action, callback) { var self = this; //name不存在的时候全部隐藏 - var exist = this.hasWidget(this._getCardName(name)); + var exist = this.isCardExisted(name); if (this.showIndex != null) { this.lastShowIndex = this.showIndex; } - this.showIndex = this._getCardName(name); + this.showIndex = name; var flag = false; - BI.each(this._children, function (i, el) { - if (self._getCardName(name) != i) { + BI.each(this.options.items, function (i, item) { + var el = self._children[item.cardName]; + if (name != item.cardName) { //动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了 !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible(); } else { @@ -114,8 +129,8 @@ BI.CardLayout = BI.inherit(BI.Layout, { showLastCard: function () { var self = this; this.showIndex = this.lastShowIndex; - BI.each(this._children, function (i, el) { - el.setVisible(self.showIndex == i); + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].setVisible(self.showIndex == i); }) }, @@ -149,15 +164,17 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, hideAllCard: function () { - BI.each(this._children, function (i, el) { - el.invisible(); + var self = this; + BI.each(this.options.items, function (i, item) { + self._children[item.cardName].invisible(); }); }, isAllCardHide: function () { + var self = this; var flag = true; - BI.some(this._children, function (i, el) { - if (el.isVisible()) { + BI.some(this.options.items, function (i, item) { + if (self._children[item.cardName].isVisible()) { flag = false; return false; } diff --git a/src/widget/arrangement/arrangement.js b/src/widget/arrangement/arrangement.js index 42ee9b7c98..da80c75254 100644 --- a/src/widget/arrangement/arrangement.js +++ b/src/widget/arrangement/arrangement.js @@ -2083,7 +2083,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { _moveElement: function (layout, l, x, y, isUserAction) { var self = this; - if (l.static) { + if (l._static) { return layout; } @@ -2116,7 +2116,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { continue; } - if (collision.static) { + if (collision._static) { layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); } else { layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); @@ -2209,7 +2209,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { for (var i = 0, len = sorted.length; i < len; i++) { var l = sorted[i]; - if (!l.static) { + if (!l._static) { l = this._compactItem(compareWith, l, verticalCompact); compareWith.push(l); @@ -2223,7 +2223,7 @@ BI.Arrangement = BI.inherit(BI.Widget, { return out; function getStatics(layout) { return BI.filter(layout, function (i, l) { - return l.static; + return l._static; }); } },