guy 8 years ago
parent
commit
c302441d95
  1. 111
      bi/base.js
  2. 2
      bi/case.js
  3. 265
      bi/core.js
  4. 8
      bi/widget.js
  5. 44
      demo/js/core/abstract/demo.button_group.js
  6. 111
      dist/base.js
  7. 2
      dist/case.js
  8. 265
      dist/core.js
  9. 8
      dist/widget.js
  10. 56
      src/base/combination/group.button.js
  11. 53
      src/base/combination/navigation.js
  12. 2
      src/base/combination/tab.js
  13. 2
      src/case/loader/sort.list.js
  14. 88
      src/core/action/action.show.effect.js
  15. 17
      src/core/action/action.show.js
  16. 32
      src/core/action/action.show.scale.js
  17. 2
      src/core/view.js
  18. 28
      src/core/widget.js
  19. 19
      src/core/wrapper/layout.js
  20. 81
      src/core/wrapper/layout/layout.card.js
  21. 8
      src/widget/arrangement/arrangement.js

111
bi/base.js

@ -1034,7 +1034,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
_packageBtns: function (btns) { _packageBtns: function (btns) {
var o = this.options; var o = this.options;
for (var i = o.layouts.length - 1; i > 0; i--) { for (var i = o.layouts.length - 1; i > 0; i--) {
btns = BI.map(btns, function (k, it) { btns = BI.map(btns, function (k, it) {
return BI.extend({}, o.layouts[i], { return BI.extend({}, o.layouts[i], {
@ -1049,6 +1048,18 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return btns; 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) { _packageItems: function (items, packBtns) {
return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns));
}, },
@ -1064,6 +1075,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return layout; return layout;
}, },
//如果是一个简单的layout
_isSimpleLayout: function () {
var o = this.options;
return o.layouts.length === 1
},
doBehavior: function () { doBehavior: function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
@ -1078,9 +1095,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
var btns = this._btnsCreator.apply(this, arguments); var btns = this._btnsCreator.apply(this, arguments);
this.buttons = BI.concat(btns, this.buttons); this.buttons = BI.concat(btns, this.buttons);
//如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) {
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items)
&& this.layouts && this.layouts.prependItems) {
this.layouts.prependItems(btns); this.layouts.prependItems(btns);
return; return;
} }
@ -1095,8 +1110,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.buttons = BI.concat(this.buttons, btns); this.buttons = BI.concat(this.buttons, btns);
//如果是一个简单的layout //如果是一个简单的layout
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) {
&& this.layouts && this.layouts.addItems) {
this.layouts.addItems(btns); this.layouts.addItems(btns);
return; return;
} }
@ -1105,36 +1119,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.layouts.addItems(this._packageLayout(items).items); this.layouts.addItems(this._packageLayout(items).items);
}, },
removeItemAt: function (indexes) { removeItemAt: function (index) {
var self = this; this.buttons[index].destroy();
indexes = BI.isArray(indexes) ? indexes : [indexes]; this.layouts.removeItemAt(index);
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);
}, },
populate: function (items) { populate: function (items) {
items = items || []; items = items || [];
this.options.items = items;
this.empty(); this.empty();
this.options.items = items;
this.buttons = this._btnsCreator.apply(this, arguments); this.buttons = this._btnsCreator.apply(this, arguments);
if (this._isSimpleLayout()) {
items = this._packageSimpleItems(this.buttons);
} else {
items = this._packageItems(items, this._packageBtns(this.buttons)); items = this._packageItems(items, this._packageBtns(this.buttons));
}
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); 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, { BI.Navigation = BI.inherit(BI.Widget, {
_defaultConfig: function(){ _defaultConfig: function () {
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
direction: "bottom",//top, bottom, left, right, custom direction: "bottom",//top, bottom, left, right, custom
logic: { logic: {
dynamic: false dynamic: false
@ -3905,7 +3905,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
items: [], items: [],
layouts: [] layouts: []
}, },
cardCreator: function(v){ cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();
}, },
@ -3914,8 +3914,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
}) })
}, },
_init: function(){ render: function () {
BI.Navigation.superclass._init.apply(this,arguments);
var self = this, o = this.options; 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.cardMap = {};
@ -3933,10 +3932,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
new BI.ShowListener({ new BI.ShowListener({
eventObj: this.tab, eventObj: this.tab,
cardLayout: this.layout, cardLayout: this.layout,
cardNameCreator: function(v){ cardNameCreator: function (v) {
return self.showIndex + v; return self.showIndex + v;
}, },
cardCreator: function(v){ cardCreator: function (v) {
var card = o.cardCreator(v); var card = o.cardCreator(v);
self.cardMap[v] = card; self.cardMap[v] = card;
return card; return card;
@ -3944,37 +3943,41 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, 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); this.setSelect(o.defaultShowIndex);
} }
}, },
afterCardCreated: function(v){ afterCardCreated: function (v) {
var self = this; 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); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if(type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
} }
}) })
this.options.afterCardCreated.apply(this, arguments); this.options.afterCardCreated.apply(this, arguments);
}, },
afterCardShow: function(v){ afterCardShow: function (v) {
this.showIndex = v; this.showIndex = v;
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
populate: function(){ populate: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.populate.apply(card, arguments); return card.populate.apply(card, arguments);
} }
}, },
setSelect: function(v){ setSelect: function (v) {
this.showIndex = v; this.showIndex = v;
if(!this.layout.isCardExisted(v)){ if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
this.cardMap[v] = card; this.cardMap[v] = card;
this.layout.addCardByName(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)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}, },
getSelect: function(){ getSelect: function () {
return this.showIndex; return this.showIndex;
}, },
getSelectedCard: function(){ getSelectedCard: function () {
if(BI.isKey(this.showIndex)){ if (BI.isKey(this.showIndex)) {
return this.cardMap[this.showIndex]; return this.cardMap[this.showIndex];
} }
}, },
@ -3997,9 +4000,9 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
setValue: function(v){ setValue: function (v) {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
card.setValue(v); card.setValue(v);
} }
}, },
@ -4007,19 +4010,19 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
getValue: function(){ getValue: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.getValue(); return card.getValue();
} }
}, },
empty: function(){ empty: function () {
this.layout.deleteAllCard(); this.layout.deleteAllCard();
this.cardMap = {}; this.cardMap = {};
}, },
destroy: function(){ destroy: function () {
BI.Navigation.superclass.destroy.apply(this, arguments); BI.Navigation.superclass.destroy.apply(this, arguments);
} }
}); });
@ -4615,7 +4618,7 @@ BI.Tab = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
defaultShowIndex: 0, defaultShowIndex: false,
tab: false, tab: false,
cardCreator: function (v) { cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();

2
bi/case.js

@ -8384,7 +8384,7 @@ BI.SortList = BI.inherit(BI.Widget, {
placeholder: { placeholder: {
element: function ($currentItem) { element: function ($currentItem) {
var holder = BI.createWidget({ var holder = BI.createWidget({
type: "bi.label", type: "bi.layout",
cls: "bi-sortable-holder", cls: "bi-sortable-holder",
height: $currentItem.outerHeight() height: $currentItem.outerHeight()
}); });

265
bi/core.js

@ -4587,14 +4587,6 @@ BI.Widget = BI.inherit(BI.OB, {
this._initElementHeight(); this._initElementHeight();
}, },
setElement: function (widget) {
if (widget == this) {
return;
}
this.element = BI.isWidget(widget) ? widget.element : $(widget);
return this;
},
setEnable: function (enable) { setEnable: function (enable) {
if (enable === true) { if (enable === true) {
this.options.disabled = false; this.options.disabled = false;
@ -4676,8 +4668,17 @@ BI.Widget = BI.inherit(BI.OB, {
return widget; return widget;
}, },
removeWidget: function (name) { removeWidget: function (nameOrWidget) {
delete this._children[name]; 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) { hasWidget: function (name) {
@ -4751,6 +4752,13 @@ BI.Widget = BI.inherit(BI.OB, {
this.setVisible(true); this.setVisible(true);
}, },
isolate: function () {
if (this._parent) {
this._parent.removeWidget(this);
BI.DOM.hang([this]);
}
},
empty: function () { empty: function () {
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
widget._unMount(); 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)); options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel));
if (this._cardLayouts[key]) { if (this._cardLayouts[key]) {
options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName);
this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize();
return this; return this;
} }
this._cardLayouts[key] = BI.createWidget({ this._cardLayouts[key] = BI.createWidget({
@ -5741,6 +5748,7 @@ BI.View = BI.inherit(BI.V, {
delete this._cardLayouts; delete this._cardLayouts;
delete this._cards; delete this._cards;
this.remove(); this.remove();
this.trigger(BI.Events.DESTROY);
this.destroyed(); this.destroyed();
}, },
@ -11211,7 +11219,6 @@ BI.Layout = BI.inherit(BI.Widget, {
var self = this, w; var self = this, w;
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
w = BI.createWidget(item); w = BI.createWidget(item);
this.addWidget(this._getChildName(i), w);
w.on(BI.Events.DESTROY, function () { w.on(BI.Events.DESTROY, function () {
BI.each(self._children, function (name, child) { BI.each(self._children, function (name, child) {
if (child === w) { if (child === w) {
@ -11219,6 +11226,7 @@ BI.Layout = BI.inherit(BI.Widget, {
} }
}); });
}); });
this.addWidget(this._getChildName(i), w);
} else { } else {
w = this.getWidgetByName(this._getChildName(i)); 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 () { empty: function () {
BI.Layout.superclass.empty.apply(this, arguments); BI.Layout.superclass.empty.apply(this, arguments);
this.options.items = []; this.options.items = [];
@ -13273,27 +13298,28 @@ BI.CardLayout = BI.inherit(BI.Layout, {
this.populate(this.options.items); this.populate(this.options.items);
}, },
_getCardName: function (cardName) {
return this.getName() + cardName;
},
resize: function () { resize: function () {
// console.log("default布局不需要resize"); // console.log("default布局不需要resize");
}, },
stroke: function (items) { stroke: function (items) {
var self = this; var self = this, o = this.options;
this.showIndex = void 0; this.showIndex = void 0;
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (!!item) { if (!!item) {
if (!self.hasWidget(self._getCardName(item.cardName))) { if (!self.hasWidget(item.cardName)) {
var w = BI.createWidget(item); var w = BI.createWidget(item);
self.addWidget(self._getCardName(item.cardName), w);
w.on(BI.Events.DESTROY, function () { 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 { } 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.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"});
w.setVisible(false); w.setVisible(false);
@ -13304,6 +13330,11 @@ BI.CardLayout = BI.inherit(BI.Layout, {
update: function () { update: function () {
}, },
empty: function () {
BI.CardLayout.superclass.empty.apply(this, arguments);
this.options.items = [];
},
populate: function (items) { populate: function (items) {
BI.CardLayout.superclass.populate.apply(this, arguments); BI.CardLayout.superclass.populate.apply(this, arguments);
this._mount(); this._mount();
@ -13311,53 +13342,62 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
isCardExisted: function (cardName) { 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) { getCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
throw new Error("cardName is not exist"); throw new Error("cardName is not exist");
} }
return this._children[this._getCardName(cardName)]; return this._children[cardName];
}, },
deleteCardByName: function (cardName) { deleteCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
return; throw new Error("cardName is not exist");
} }
var index = BI.findKey(this.options.items, function (i, item) { var index = BI.findKey(this.options.items, function (i, item) {
return item.cardName == cardName; return item.cardName == cardName;
}); });
if (index > -1) {
this.options.items.splice(index, 1); this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName)); }
delete this._children[this._getCardName(cardName)]; var child = this._children[cardName];
child.destroy(); child && child.destroy();
}, },
addCardByName: function (cardName, cardItem) { addCardByName: function (cardName, cardItem) {
if (this.hasWidget(this._getCardName(cardName))) { if (this.isCardExisted(cardName)) {
throw new Error("cardName is already exist"); throw new Error("cardName is already exist");
} }
this.options.items.push({el: cardItem, cardName: cardName});
var widget = BI.createWidget(cardItem); var widget = BI.createWidget(cardItem);
widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) widget.element.css({
.appendTo(this.element); "position": "relative",
"top": "0",
"left": "0",
"width": "100%",
"height": "100%"
}).appendTo(this.element);
widget.invisible(); widget.invisible();
this.addWidget(this._getCardName(cardName), widget); this.addWidget(cardName, widget);
this.options.items.push({el: cardItem, cardName: cardName});
return widget; return widget;
}, },
showCardByName: function (name, action, callback) { showCardByName: function (name, action, callback) {
var self = this; var self = this;
//name不存在的时候全部隐藏 //name不存在的时候全部隐藏
var exist = this.hasWidget(this._getCardName(name)); var exist = this.isCardExisted(name);
if (this.showIndex != null) { if (this.showIndex != null) {
this.lastShowIndex = this.showIndex; this.lastShowIndex = this.showIndex;
} }
this.showIndex = this._getCardName(name); this.showIndex = name;
var flag = false; var flag = false;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
if (self._getCardName(name) != i) { 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(); !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible();
} else { } else {
@ -13369,8 +13409,8 @@ BI.CardLayout = BI.inherit(BI.Layout, {
showLastCard: function () { showLastCard: function () {
var self = this; var self = this;
this.showIndex = this.lastShowIndex; this.showIndex = this.lastShowIndex;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
el.setVisible(self.showIndex == i); self._children[item.cardName].setVisible(self.showIndex == i);
}) })
}, },
@ -13404,15 +13444,17 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
hideAllCard: function () { hideAllCard: function () {
BI.each(this._children, function (i, el) { var self = this;
el.invisible(); BI.each(this.options.items, function (i, item) {
self._children[item.cardName].invisible();
}); });
}, },
isAllCardHide: function () { isAllCardHide: function () {
var self = this;
var flag = true; var flag = true;
BI.some(this._children, function (i, el) { BI.some(this.options.items, function (i, item) {
if (el.isVisible()) { if (self._children[item.cardName].isVisible()) {
flag = false; flag = false;
return false; return false;
} }
@ -15254,147 +15296,30 @@ BI.ActionFactory = {
return new action(options); 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 * guy
* 由一个元素切换到另一个元素的行为 * 由一个元素切换到另一个元素的行为
* @class BI.ShowAction * @class BI.ShowAction
* @extends BI.Action * @extends BI.Action
*/ */
BI.ShowAction = BI.inherit(BI.Action, { BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function() { _defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
});
}, },
_init : function() { _init: function () {
BI.ShowAction.superclass._init.apply(this, arguments); 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);
},
actionBack: function(tar, src, callback){
tar = tar || this.options.tar; tar = tar || this.options.tar;
tar.element.hide(0, callback); tar.setVisible(true);
} callback && 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){ actionBack: function (tar, src, callback) {
tar = tar || this.options.tar; 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 * @class BI.FloatSection

8
bi/widget.js

@ -3020,7 +3020,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
_moveElement: function (layout, l, x, y, isUserAction) { _moveElement: function (layout, l, x, y, isUserAction) {
var self = this; var self = this;
if (l.static) { if (l._static) {
return layout; return layout;
} }
@ -3053,7 +3053,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
continue; continue;
} }
if (collision.static) { if (collision._static) {
layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction);
} else { } else {
layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); 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++) { for (var i = 0, len = sorted.length; i < len; i++) {
var l = sorted[i]; var l = sorted[i];
if (!l.static) { if (!l._static) {
l = this._compactItem(compareWith, l, verticalCompact); l = this._compactItem(compareWith, l, verticalCompact);
compareWith.push(l); compareWith.push(l);
@ -3160,7 +3160,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
return out; return out;
function getStatics(layout) { function getStatics(layout) {
return BI.filter(layout, function (i, l) { return BI.filter(layout, function (i, l) {
return l.static; return l._static;
}); });
} }
}, },

44
demo/js/core/abstract/demo.button_group.js

@ -3,21 +3,59 @@ Demo.Func = BI.inherit(BI.Widget, {
baseCls: "demo-func" baseCls: "demo-func"
}, },
render: function () { render: function () {
var ref;
return { return {
type: "bi.vertical",
items: [{
type: "bi.button_group", type: "bi.button_group",
ref: function (_ref) {
ref = _ref;
},
chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE, chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}, { items: [{
type: "bi.center_adapt", type: "bi.vtape",
height: 200,
}]
}], }],
items: [{ items: [{
el: {
type: "bi.label", type: "bi.label",
text: "button_group是一类具有相同属性或相似属性的抽象, 本案例实现的是布局的嵌套(vertical布局下内嵌center_adapt布局)" text: "button_group是一类具有相同属性或相似属性的抽象, 本案例实现的是布局的嵌套(vertical布局下内嵌center_adapt布局)"
},
height: 150,
}, {
el: {
type: "bi.button",
text: "1"
}
}]
}, { }, {
type: "bi.button", type: "bi.button",
text: "populate",
handler: function () {
ref.populate([{
el: {
type: "bi.label",
text: "1" text: "1"
},
height: 50
}, {
el: {
type: "bi.button",
text: "2"
},
height: 50
}, {
el: {
type: "bi.label",
text: "3"
}
}])
}
}] }]
} }
} }
}); });

111
dist/base.js vendored

@ -1034,7 +1034,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
_packageBtns: function (btns) { _packageBtns: function (btns) {
var o = this.options; var o = this.options;
for (var i = o.layouts.length - 1; i > 0; i--) { for (var i = o.layouts.length - 1; i > 0; i--) {
btns = BI.map(btns, function (k, it) { btns = BI.map(btns, function (k, it) {
return BI.extend({}, o.layouts[i], { return BI.extend({}, o.layouts[i], {
@ -1049,6 +1048,18 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return btns; 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) { _packageItems: function (items, packBtns) {
return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns));
}, },
@ -1064,6 +1075,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return layout; return layout;
}, },
//如果是一个简单的layout
_isSimpleLayout: function () {
var o = this.options;
return o.layouts.length === 1
},
doBehavior: function () { doBehavior: function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
@ -1078,9 +1095,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
var btns = this._btnsCreator.apply(this, arguments); var btns = this._btnsCreator.apply(this, arguments);
this.buttons = BI.concat(btns, this.buttons); this.buttons = BI.concat(btns, this.buttons);
//如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) {
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items)
&& this.layouts && this.layouts.prependItems) {
this.layouts.prependItems(btns); this.layouts.prependItems(btns);
return; return;
} }
@ -1095,8 +1110,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.buttons = BI.concat(this.buttons, btns); this.buttons = BI.concat(this.buttons, btns);
//如果是一个简单的layout //如果是一个简单的layout
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) {
&& this.layouts && this.layouts.addItems) {
this.layouts.addItems(btns); this.layouts.addItems(btns);
return; return;
} }
@ -1105,36 +1119,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.layouts.addItems(this._packageLayout(items).items); this.layouts.addItems(this._packageLayout(items).items);
}, },
removeItemAt: function (indexes) { removeItemAt: function (index) {
var self = this; this.buttons[index].destroy();
indexes = BI.isArray(indexes) ? indexes : [indexes]; this.layouts.removeItemAt(index);
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);
}, },
populate: function (items) { populate: function (items) {
items = items || []; items = items || [];
this.options.items = items;
this.empty(); this.empty();
this.options.items = items;
this.buttons = this._btnsCreator.apply(this, arguments); this.buttons = this._btnsCreator.apply(this, arguments);
if (this._isSimpleLayout()) {
items = this._packageSimpleItems(this.buttons);
} else {
items = this._packageItems(items, this._packageBtns(this.buttons)); items = this._packageItems(items, this._packageBtns(this.buttons));
}
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); 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, { BI.Navigation = BI.inherit(BI.Widget, {
_defaultConfig: function(){ _defaultConfig: function () {
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
direction: "bottom",//top, bottom, left, right, custom direction: "bottom",//top, bottom, left, right, custom
logic: { logic: {
dynamic: false dynamic: false
@ -3905,7 +3905,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
items: [], items: [],
layouts: [] layouts: []
}, },
cardCreator: function(v){ cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();
}, },
@ -3914,8 +3914,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
}) })
}, },
_init: function(){ render: function () {
BI.Navigation.superclass._init.apply(this,arguments);
var self = this, o = this.options; 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.cardMap = {};
@ -3933,10 +3932,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
new BI.ShowListener({ new BI.ShowListener({
eventObj: this.tab, eventObj: this.tab,
cardLayout: this.layout, cardLayout: this.layout,
cardNameCreator: function(v){ cardNameCreator: function (v) {
return self.showIndex + v; return self.showIndex + v;
}, },
cardCreator: function(v){ cardCreator: function (v) {
var card = o.cardCreator(v); var card = o.cardCreator(v);
self.cardMap[v] = card; self.cardMap[v] = card;
return card; return card;
@ -3944,37 +3943,41 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, 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); this.setSelect(o.defaultShowIndex);
} }
}, },
afterCardCreated: function(v){ afterCardCreated: function (v) {
var self = this; 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); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if(type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
} }
}) })
this.options.afterCardCreated.apply(this, arguments); this.options.afterCardCreated.apply(this, arguments);
}, },
afterCardShow: function(v){ afterCardShow: function (v) {
this.showIndex = v; this.showIndex = v;
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
populate: function(){ populate: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.populate.apply(card, arguments); return card.populate.apply(card, arguments);
} }
}, },
setSelect: function(v){ setSelect: function (v) {
this.showIndex = v; this.showIndex = v;
if(!this.layout.isCardExisted(v)){ if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
this.cardMap[v] = card; this.cardMap[v] = card;
this.layout.addCardByName(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)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}, },
getSelect: function(){ getSelect: function () {
return this.showIndex; return this.showIndex;
}, },
getSelectedCard: function(){ getSelectedCard: function () {
if(BI.isKey(this.showIndex)){ if (BI.isKey(this.showIndex)) {
return this.cardMap[this.showIndex]; return this.cardMap[this.showIndex];
} }
}, },
@ -3997,9 +4000,9 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
setValue: function(v){ setValue: function (v) {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
card.setValue(v); card.setValue(v);
} }
}, },
@ -4007,19 +4010,19 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
getValue: function(){ getValue: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.getValue(); return card.getValue();
} }
}, },
empty: function(){ empty: function () {
this.layout.deleteAllCard(); this.layout.deleteAllCard();
this.cardMap = {}; this.cardMap = {};
}, },
destroy: function(){ destroy: function () {
BI.Navigation.superclass.destroy.apply(this, arguments); BI.Navigation.superclass.destroy.apply(this, arguments);
} }
}); });
@ -4615,7 +4618,7 @@ BI.Tab = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
defaultShowIndex: 0, defaultShowIndex: false,
tab: false, tab: false,
cardCreator: function (v) { cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();

2
dist/case.js vendored

@ -8384,7 +8384,7 @@ BI.SortList = BI.inherit(BI.Widget, {
placeholder: { placeholder: {
element: function ($currentItem) { element: function ($currentItem) {
var holder = BI.createWidget({ var holder = BI.createWidget({
type: "bi.label", type: "bi.layout",
cls: "bi-sortable-holder", cls: "bi-sortable-holder",
height: $currentItem.outerHeight() height: $currentItem.outerHeight()
}); });

265
dist/core.js vendored

@ -14508,14 +14508,6 @@ BI.Widget = BI.inherit(BI.OB, {
this._initElementHeight(); this._initElementHeight();
}, },
setElement: function (widget) {
if (widget == this) {
return;
}
this.element = BI.isWidget(widget) ? widget.element : $(widget);
return this;
},
setEnable: function (enable) { setEnable: function (enable) {
if (enable === true) { if (enable === true) {
this.options.disabled = false; this.options.disabled = false;
@ -14597,8 +14589,17 @@ BI.Widget = BI.inherit(BI.OB, {
return widget; return widget;
}, },
removeWidget: function (name) { removeWidget: function (nameOrWidget) {
delete this._children[name]; 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) { hasWidget: function (name) {
@ -14672,6 +14673,13 @@ BI.Widget = BI.inherit(BI.OB, {
this.setVisible(true); this.setVisible(true);
}, },
isolate: function () {
if (this._parent) {
this._parent.removeWidget(this);
BI.DOM.hang([this]);
}
},
empty: function () { empty: function () {
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
widget._unMount(); 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)); options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel));
if (this._cardLayouts[key]) { if (this._cardLayouts[key]) {
options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName);
this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize();
return this; return this;
} }
this._cardLayouts[key] = BI.createWidget({ this._cardLayouts[key] = BI.createWidget({
@ -15662,6 +15669,7 @@ BI.View = BI.inherit(BI.V, {
delete this._cardLayouts; delete this._cardLayouts;
delete this._cards; delete this._cards;
this.remove(); this.remove();
this.trigger(BI.Events.DESTROY);
this.destroyed(); this.destroyed();
}, },
@ -19353,7 +19361,6 @@ BI.Layout = BI.inherit(BI.Widget, {
var self = this, w; var self = this, w;
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
w = BI.createWidget(item); w = BI.createWidget(item);
this.addWidget(this._getChildName(i), w);
w.on(BI.Events.DESTROY, function () { w.on(BI.Events.DESTROY, function () {
BI.each(self._children, function (name, child) { BI.each(self._children, function (name, child) {
if (child === w) { if (child === w) {
@ -19361,6 +19368,7 @@ BI.Layout = BI.inherit(BI.Widget, {
} }
}); });
}); });
this.addWidget(this._getChildName(i), w);
} else { } else {
w = this.getWidgetByName(this._getChildName(i)); 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 () { empty: function () {
BI.Layout.superclass.empty.apply(this, arguments); BI.Layout.superclass.empty.apply(this, arguments);
this.options.items = []; this.options.items = [];
@ -19690,147 +19715,30 @@ BI.ActionFactory = {
return new action(options); 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 * guy
* 由一个元素切换到另一个元素的行为 * 由一个元素切换到另一个元素的行为
* @class BI.ShowAction * @class BI.ShowAction
* @extends BI.Action * @extends BI.Action
*/ */
BI.ShowAction = BI.inherit(BI.Action, { BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function() { _defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
});
}, },
_init : function() { _init: function () {
BI.ShowAction.superclass._init.apply(this, arguments); 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);
},
actionBack: function(tar, src, callback){
tar = tar || this.options.tar; tar = tar || this.options.tar;
tar.element.hide(0, callback); tar.setVisible(true);
} callback && 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){ actionBack: function (tar, src, callback) {
tar = tar || this.options.tar; 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 * @class BI.FloatSection
@ -26804,27 +26712,28 @@ BI.CardLayout = BI.inherit(BI.Layout, {
this.populate(this.options.items); this.populate(this.options.items);
}, },
_getCardName: function (cardName) {
return this.getName() + cardName;
},
resize: function () { resize: function () {
// console.log("default布局不需要resize"); // console.log("default布局不需要resize");
}, },
stroke: function (items) { stroke: function (items) {
var self = this; var self = this, o = this.options;
this.showIndex = void 0; this.showIndex = void 0;
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (!!item) { if (!!item) {
if (!self.hasWidget(self._getCardName(item.cardName))) { if (!self.hasWidget(item.cardName)) {
var w = BI.createWidget(item); var w = BI.createWidget(item);
self.addWidget(self._getCardName(item.cardName), w);
w.on(BI.Events.DESTROY, function () { 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 { } 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.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"});
w.setVisible(false); w.setVisible(false);
@ -26835,6 +26744,11 @@ BI.CardLayout = BI.inherit(BI.Layout, {
update: function () { update: function () {
}, },
empty: function () {
BI.CardLayout.superclass.empty.apply(this, arguments);
this.options.items = [];
},
populate: function (items) { populate: function (items) {
BI.CardLayout.superclass.populate.apply(this, arguments); BI.CardLayout.superclass.populate.apply(this, arguments);
this._mount(); this._mount();
@ -26842,53 +26756,62 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
isCardExisted: function (cardName) { 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) { getCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
throw new Error("cardName is not exist"); throw new Error("cardName is not exist");
} }
return this._children[this._getCardName(cardName)]; return this._children[cardName];
}, },
deleteCardByName: function (cardName) { deleteCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
return; throw new Error("cardName is not exist");
} }
var index = BI.findKey(this.options.items, function (i, item) { var index = BI.findKey(this.options.items, function (i, item) {
return item.cardName == cardName; return item.cardName == cardName;
}); });
if (index > -1) {
this.options.items.splice(index, 1); this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName)); }
delete this._children[this._getCardName(cardName)]; var child = this._children[cardName];
child.destroy(); child && child.destroy();
}, },
addCardByName: function (cardName, cardItem) { addCardByName: function (cardName, cardItem) {
if (this.hasWidget(this._getCardName(cardName))) { if (this.isCardExisted(cardName)) {
throw new Error("cardName is already exist"); throw new Error("cardName is already exist");
} }
this.options.items.push({el: cardItem, cardName: cardName});
var widget = BI.createWidget(cardItem); var widget = BI.createWidget(cardItem);
widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) widget.element.css({
.appendTo(this.element); "position": "relative",
"top": "0",
"left": "0",
"width": "100%",
"height": "100%"
}).appendTo(this.element);
widget.invisible(); widget.invisible();
this.addWidget(this._getCardName(cardName), widget); this.addWidget(cardName, widget);
this.options.items.push({el: cardItem, cardName: cardName});
return widget; return widget;
}, },
showCardByName: function (name, action, callback) { showCardByName: function (name, action, callback) {
var self = this; var self = this;
//name不存在的时候全部隐藏 //name不存在的时候全部隐藏
var exist = this.hasWidget(this._getCardName(name)); var exist = this.isCardExisted(name);
if (this.showIndex != null) { if (this.showIndex != null) {
this.lastShowIndex = this.showIndex; this.lastShowIndex = this.showIndex;
} }
this.showIndex = this._getCardName(name); this.showIndex = name;
var flag = false; var flag = false;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
if (self._getCardName(name) != i) { 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(); !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible();
} else { } else {
@ -26900,8 +26823,8 @@ BI.CardLayout = BI.inherit(BI.Layout, {
showLastCard: function () { showLastCard: function () {
var self = this; var self = this;
this.showIndex = this.lastShowIndex; this.showIndex = this.lastShowIndex;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
el.setVisible(self.showIndex == i); self._children[item.cardName].setVisible(self.showIndex == i);
}) })
}, },
@ -26935,15 +26858,17 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
hideAllCard: function () { hideAllCard: function () {
BI.each(this._children, function (i, el) { var self = this;
el.invisible(); BI.each(this.options.items, function (i, item) {
self._children[item.cardName].invisible();
}); });
}, },
isAllCardHide: function () { isAllCardHide: function () {
var self = this;
var flag = true; var flag = true;
BI.some(this._children, function (i, el) { BI.some(this.options.items, function (i, item) {
if (el.isVisible()) { if (self._children[item.cardName].isVisible()) {
flag = false; flag = false;
return false; return false;
} }

8
dist/widget.js vendored

@ -3020,7 +3020,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
_moveElement: function (layout, l, x, y, isUserAction) { _moveElement: function (layout, l, x, y, isUserAction) {
var self = this; var self = this;
if (l.static) { if (l._static) {
return layout; return layout;
} }
@ -3053,7 +3053,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
continue; continue;
} }
if (collision.static) { if (collision._static) {
layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction);
} else { } else {
layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); 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++) { for (var i = 0, len = sorted.length; i < len; i++) {
var l = sorted[i]; var l = sorted[i];
if (!l.static) { if (!l._static) {
l = this._compactItem(compareWith, l, verticalCompact); l = this._compactItem(compareWith, l, verticalCompact);
compareWith.push(l); compareWith.push(l);
@ -3160,7 +3160,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
return out; return out;
function getStatics(layout) { function getStatics(layout) {
return BI.filter(layout, function (i, l) { return BI.filter(layout, function (i, l) {
return l.static; return l._static;
}); });
} }
}, },

56
src/base/combination/group.button.js

@ -71,7 +71,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
_packageBtns: function (btns) { _packageBtns: function (btns) {
var o = this.options; var o = this.options;
for (var i = o.layouts.length - 1; i > 0; i--) { for (var i = o.layouts.length - 1; i > 0; i--) {
btns = BI.map(btns, function (k, it) { btns = BI.map(btns, function (k, it) {
return BI.extend({}, o.layouts[i], { return BI.extend({}, o.layouts[i], {
@ -86,6 +85,18 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return btns; 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) { _packageItems: function (items, packBtns) {
return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns));
}, },
@ -101,6 +112,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return layout; return layout;
}, },
//如果是一个简单的layout
_isSimpleLayout: function () {
var o = this.options;
return o.layouts.length === 1
},
doBehavior: function () { doBehavior: function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
@ -115,9 +132,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
var btns = this._btnsCreator.apply(this, arguments); var btns = this._btnsCreator.apply(this, arguments);
this.buttons = BI.concat(btns, this.buttons); this.buttons = BI.concat(btns, this.buttons);
//如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) {
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items)
&& this.layouts && this.layouts.prependItems) {
this.layouts.prependItems(btns); this.layouts.prependItems(btns);
return; return;
} }
@ -132,8 +147,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.buttons = BI.concat(this.buttons, btns); this.buttons = BI.concat(this.buttons, btns);
//如果是一个简单的layout //如果是一个简单的layout
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) {
&& this.layouts && this.layouts.addItems) {
this.layouts.addItems(btns); this.layouts.addItems(btns);
return; return;
} }
@ -142,36 +156,22 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
this.layouts.addItems(this._packageLayout(items).items); this.layouts.addItems(this._packageLayout(items).items);
}, },
removeItemAt: function (indexes) { removeItemAt: function (index) {
var self = this; this.buttons[index].destroy();
indexes = BI.isArray(indexes) ? indexes : [indexes]; this.layouts.removeItemAt(index);
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);
}, },
populate: function (items) { populate: function (items) {
items = items || []; items = items || [];
this.options.items = items;
this.empty(); this.empty();
this.options.items = items;
this.buttons = this._btnsCreator.apply(this, arguments); this.buttons = this._btnsCreator.apply(this, arguments);
if (this._isSimpleLayout()) {
items = this._packageSimpleItems(this.buttons);
} else {
items = this._packageItems(items, this._packageBtns(this.buttons)); items = this._packageItems(items, this._packageBtns(this.buttons));
}
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items)));
}, },

53
src/base/combination/navigation.js

@ -3,8 +3,8 @@
*/ */
BI.Navigation = BI.inherit(BI.Widget, { BI.Navigation = BI.inherit(BI.Widget, {
_defaultConfig: function(){ _defaultConfig: function () {
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
direction: "bottom",//top, bottom, left, right, custom direction: "bottom",//top, bottom, left, right, custom
logic: { logic: {
dynamic: false dynamic: false
@ -15,7 +15,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
items: [], items: [],
layouts: [] layouts: []
}, },
cardCreator: function(v){ cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();
}, },
@ -24,8 +24,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
}) })
}, },
_init: function(){ render: function () {
BI.Navigation.superclass._init.apply(this,arguments);
var self = this, o = this.options; 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.cardMap = {};
@ -43,10 +42,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
new BI.ShowListener({ new BI.ShowListener({
eventObj: this.tab, eventObj: this.tab,
cardLayout: this.layout, cardLayout: this.layout,
cardNameCreator: function(v){ cardNameCreator: function (v) {
return self.showIndex + v; return self.showIndex + v;
}, },
cardCreator: function(v){ cardCreator: function (v) {
var card = o.cardCreator(v); var card = o.cardCreator(v);
self.cardMap[v] = card; self.cardMap[v] = card;
return card; return card;
@ -54,37 +53,41 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, 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); this.setSelect(o.defaultShowIndex);
} }
}, },
afterCardCreated: function(v){ afterCardCreated: function (v) {
var self = this; 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); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if(type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
} }
}) })
this.options.afterCardCreated.apply(this, arguments); this.options.afterCardCreated.apply(this, arguments);
}, },
afterCardShow: function(v){ afterCardShow: function (v) {
this.showIndex = v; this.showIndex = v;
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
populate: function(){ populate: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.populate.apply(card, arguments); return card.populate.apply(card, arguments);
} }
}, },
setSelect: function(v){ setSelect: function (v) {
this.showIndex = v; this.showIndex = v;
if(!this.layout.isCardExisted(v)){ if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
this.cardMap[v] = card; this.cardMap[v] = card;
this.layout.addCardByName(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)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}, },
getSelect: function(){ getSelect: function () {
return this.showIndex; return this.showIndex;
}, },
getSelectedCard: function(){ getSelectedCard: function () {
if(BI.isKey(this.showIndex)){ if (BI.isKey(this.showIndex)) {
return this.cardMap[this.showIndex]; return this.cardMap[this.showIndex];
} }
}, },
@ -107,9 +110,9 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
setValue: function(v){ setValue: function (v) {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
card.setValue(v); card.setValue(v);
} }
}, },
@ -117,19 +120,19 @@ BI.Navigation = BI.inherit(BI.Widget, {
/** /**
* @override * @override
*/ */
getValue: function(){ getValue: function () {
var card = this.layout.getShowingCard(); var card = this.layout.getShowingCard();
if(card){ if (card) {
return card.getValue(); return card.getValue();
} }
}, },
empty: function(){ empty: function () {
this.layout.deleteAllCard(); this.layout.deleteAllCard();
this.cardMap = {}; this.cardMap = {};
}, },
destroy: function(){ destroy: function () {
BI.Navigation.superclass.destroy.apply(this, arguments); BI.Navigation.superclass.destroy.apply(this, arguments);
} }
}); });

2
src/base/combination/tab.js

@ -10,7 +10,7 @@ BI.Tab = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
defaultShowIndex: 0, defaultShowIndex: false,
tab: false, tab: false,
cardCreator: function (v) { cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();

2
src/case/loader/sort.list.js

@ -65,7 +65,7 @@ BI.SortList = BI.inherit(BI.Widget, {
placeholder: { placeholder: {
element: function ($currentItem) { element: function ($currentItem) {
var holder = BI.createWidget({ var holder = BI.createWidget({
type: "bi.label", type: "bi.layout",
cls: "bi-sortable-holder", cls: "bi-sortable-holder",
height: $currentItem.outerHeight() height: $currentItem.outerHeight()
}); });

88
src/core/action/action.show.effect.js

@ -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();
}
}
});

17
src/core/action/action.show.js

@ -5,22 +5,23 @@
* @extends BI.Action * @extends BI.Action
*/ */
BI.ShowAction = BI.inherit(BI.Action, { BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function() { _defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
});
}, },
_init : function() { _init: function () {
BI.ShowAction.superclass._init.apply(this, arguments); BI.ShowAction.superclass._init.apply(this, arguments);
}, },
actionPerformed: function(src, tar, callback){ actionPerformed: function (src, tar, callback) {
tar = tar || this.options.tar; 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 = tar || this.options.tar;
tar.element.hide(0, callback); tar.setVisible(false);
callback && callback();
} }
}); });

32
src/core/action/action.show.scale.js

@ -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);
}
});

2
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)); options.isLayer && (vessel = BI.Layers.has(id) ? BI.Layers.get(id) : BI.Layers.create(id, vessel));
if (this._cardLayouts[key]) { if (this._cardLayouts[key]) {
options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName); options.defaultShowName && this._cardLayouts[key].setDefaultShowName(options.defaultShowName);
this._cardLayouts[key].setElement(vessel) && this._cardLayouts[key].resize();
return this; return this;
} }
this._cardLayouts[key] = BI.createWidget({ this._cardLayouts[key] = BI.createWidget({
@ -509,6 +508,7 @@ BI.View = BI.inherit(BI.V, {
delete this._cardLayouts; delete this._cardLayouts;
delete this._cards; delete this._cards;
this.remove(); this.remove();
this.trigger(BI.Events.DESTROY);
this.destroyed(); this.destroyed();
}, },

28
src/core/widget.js

@ -209,14 +209,6 @@ BI.Widget = BI.inherit(BI.OB, {
this._initElementHeight(); this._initElementHeight();
}, },
setElement: function (widget) {
if (widget == this) {
return;
}
this.element = BI.isWidget(widget) ? widget.element : $(widget);
return this;
},
setEnable: function (enable) { setEnable: function (enable) {
if (enable === true) { if (enable === true) {
this.options.disabled = false; this.options.disabled = false;
@ -298,8 +290,17 @@ BI.Widget = BI.inherit(BI.OB, {
return widget; return widget;
}, },
removeWidget: function (name) { removeWidget: function (nameOrWidget) {
delete this._children[name]; 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) { hasWidget: function (name) {
@ -373,6 +374,13 @@ BI.Widget = BI.inherit(BI.OB, {
this.setVisible(true); this.setVisible(true);
}, },
isolate: function () {
if (this._parent) {
this._parent.removeWidget(this);
BI.DOM.hang([this]);
}
},
empty: function () { empty: function () {
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
widget._unMount(); widget._unMount();

19
src/core/wrapper/layout.js

@ -71,7 +71,6 @@ BI.Layout = BI.inherit(BI.Widget, {
var self = this, w; var self = this, w;
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
w = BI.createWidget(item); w = BI.createWidget(item);
this.addWidget(this._getChildName(i), w);
w.on(BI.Events.DESTROY, function () { w.on(BI.Events.DESTROY, function () {
BI.each(self._children, function (name, child) { BI.each(self._children, function (name, child) {
if (child === w) { if (child === w) {
@ -79,6 +78,7 @@ BI.Layout = BI.inherit(BI.Widget, {
} }
}); });
}); });
this.addWidget(this._getChildName(i), w);
} else { } else {
w = this.getWidgetByName(this._getChildName(i)); 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 () { empty: function () {
BI.Layout.superclass.empty.apply(this, arguments); BI.Layout.superclass.empty.apply(this, arguments);
this.options.items = []; this.options.items = [];

81
src/core/wrapper/layout/layout.card.js

@ -18,27 +18,28 @@ BI.CardLayout = BI.inherit(BI.Layout, {
this.populate(this.options.items); this.populate(this.options.items);
}, },
_getCardName: function (cardName) {
return this.getName() + cardName;
},
resize: function () { resize: function () {
// console.log("default布局不需要resize"); // console.log("default布局不需要resize");
}, },
stroke: function (items) { stroke: function (items) {
var self = this; var self = this, o = this.options;
this.showIndex = void 0; this.showIndex = void 0;
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (!!item) { if (!!item) {
if (!self.hasWidget(self._getCardName(item.cardName))) { if (!self.hasWidget(item.cardName)) {
var w = BI.createWidget(item); var w = BI.createWidget(item);
self.addWidget(self._getCardName(item.cardName), w);
w.on(BI.Events.DESTROY, function () { 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 { } 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.element.css({"position": "absolute", "top": "0", "right": "0", "bottom": "0", "left": "0"});
w.setVisible(false); w.setVisible(false);
@ -49,6 +50,11 @@ BI.CardLayout = BI.inherit(BI.Layout, {
update: function () { update: function () {
}, },
empty: function () {
BI.CardLayout.superclass.empty.apply(this, arguments);
this.options.items = [];
},
populate: function (items) { populate: function (items) {
BI.CardLayout.superclass.populate.apply(this, arguments); BI.CardLayout.superclass.populate.apply(this, arguments);
this._mount(); this._mount();
@ -56,53 +62,62 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
isCardExisted: function (cardName) { 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) { getCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
throw new Error("cardName is not exist"); throw new Error("cardName is not exist");
} }
return this._children[this._getCardName(cardName)]; return this._children[cardName];
}, },
deleteCardByName: function (cardName) { deleteCardByName: function (cardName) {
if (!this.hasWidget(this._getCardName(cardName))) { if (!this.isCardExisted(cardName)) {
return; throw new Error("cardName is not exist");
} }
var index = BI.findKey(this.options.items, function (i, item) { var index = BI.findKey(this.options.items, function (i, item) {
return item.cardName == cardName; return item.cardName == cardName;
}); });
if (index > -1) {
this.options.items.splice(index, 1); this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName)); }
delete this._children[this._getCardName(cardName)]; var child = this._children[cardName];
child.destroy(); child && child.destroy();
}, },
addCardByName: function (cardName, cardItem) { addCardByName: function (cardName, cardItem) {
if (this.hasWidget(this._getCardName(cardName))) { if (this.isCardExisted(cardName)) {
throw new Error("cardName is already exist"); throw new Error("cardName is already exist");
} }
this.options.items.push({el: cardItem, cardName: cardName});
var widget = BI.createWidget(cardItem); var widget = BI.createWidget(cardItem);
widget.element.css({"position": "relative", "top": "0", "left": "0", "width": "100%", "height": "100%"}) widget.element.css({
.appendTo(this.element); "position": "relative",
"top": "0",
"left": "0",
"width": "100%",
"height": "100%"
}).appendTo(this.element);
widget.invisible(); widget.invisible();
this.addWidget(this._getCardName(cardName), widget); this.addWidget(cardName, widget);
this.options.items.push({el: cardItem, cardName: cardName});
return widget; return widget;
}, },
showCardByName: function (name, action, callback) { showCardByName: function (name, action, callback) {
var self = this; var self = this;
//name不存在的时候全部隐藏 //name不存在的时候全部隐藏
var exist = this.hasWidget(this._getCardName(name)); var exist = this.isCardExisted(name);
if (this.showIndex != null) { if (this.showIndex != null) {
this.lastShowIndex = this.showIndex; this.lastShowIndex = this.showIndex;
} }
this.showIndex = this._getCardName(name); this.showIndex = name;
var flag = false; var flag = false;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
if (self._getCardName(name) != i) { 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(); !flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible();
} else { } else {
@ -114,8 +129,8 @@ BI.CardLayout = BI.inherit(BI.Layout, {
showLastCard: function () { showLastCard: function () {
var self = this; var self = this;
this.showIndex = this.lastShowIndex; this.showIndex = this.lastShowIndex;
BI.each(this._children, function (i, el) { BI.each(this.options.items, function (i, item) {
el.setVisible(self.showIndex == i); self._children[item.cardName].setVisible(self.showIndex == i);
}) })
}, },
@ -149,15 +164,17 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}, },
hideAllCard: function () { hideAllCard: function () {
BI.each(this._children, function (i, el) { var self = this;
el.invisible(); BI.each(this.options.items, function (i, item) {
self._children[item.cardName].invisible();
}); });
}, },
isAllCardHide: function () { isAllCardHide: function () {
var self = this;
var flag = true; var flag = true;
BI.some(this._children, function (i, el) { BI.some(this.options.items, function (i, item) {
if (el.isVisible()) { if (self._children[item.cardName].isVisible()) {
flag = false; flag = false;
return false; return false;
} }

8
src/widget/arrangement/arrangement.js

@ -2083,7 +2083,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
_moveElement: function (layout, l, x, y, isUserAction) { _moveElement: function (layout, l, x, y, isUserAction) {
var self = this; var self = this;
if (l.static) { if (l._static) {
return layout; return layout;
} }
@ -2116,7 +2116,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
continue; continue;
} }
if (collision.static) { if (collision._static) {
layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction); layout = this._moveElementAwayFromCollision(layout, collision, l, isUserAction);
} else { } else {
layout = this._moveElementAwayFromCollision(layout, l, collision, isUserAction); 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++) { for (var i = 0, len = sorted.length; i < len; i++) {
var l = sorted[i]; var l = sorted[i];
if (!l.static) { if (!l._static) {
l = this._compactItem(compareWith, l, verticalCompact); l = this._compactItem(compareWith, l, verticalCompact);
compareWith.push(l); compareWith.push(l);
@ -2223,7 +2223,7 @@ BI.Arrangement = BI.inherit(BI.Widget, {
return out; return out;
function getStatics(layout) { function getStatics(layout) {
return BI.filter(layout, function (i, l) { return BI.filter(layout, function (i, l) {
return l.static; return l._static;
}); });
} }
}, },

Loading…
Cancel
Save