guy 8 years ago
parent
commit
c302441d95
  1. 65
      bi/base.js
  2. 2
      bi/case.js
  3. 257
      bi/core.js
  4. 8
      bi/widget.js
  5. 44
      demo/js/core/abstract/demo.button_group.js
  6. 65
      dist/base.js
  7. 2
      dist/case.js
  8. 257
      dist/core.js
  9. 8
      dist/widget.js
  10. 56
      src/base/combination/group.button.js
  11. 7
      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. 9
      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

65
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);
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)));
},
@ -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 = {};
@ -3944,6 +3943,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this)
})
},
mounted: function () {
var o = this.options;
if (o.defaultShowIndex !== false) {
this.setSelect(o.defaultShowIndex);
}
@ -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();

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

257
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;
});
if (index > -1) {
this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName));
delete this._children[this._getCardName(cardName)];
child.destroy();
}
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,93 +15296,6 @@ 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
@ -15348,8 +15303,7 @@ BI.EffectShowAction = BI.inherit(BI.Action, {
*/
BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {
});
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
},
_init: function () {
@ -15358,43 +15312,14 @@ BI.ShowAction = BI.inherit(BI.Action, {
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){
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) {
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

8
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;
});
}
},

44
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.vertical",
items: [{
type: "bi.button_group",
ref: function (_ref) {
ref = _ref;
},
chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE,
layouts: [{
type: "bi.vertical"
}, {
type: "bi.center_adapt",
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: "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"
}
}])
}
}]
}
}
});

65
dist/base.js vendored

@ -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);
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)));
},
@ -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 = {};
@ -3944,6 +3943,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this)
})
},
mounted: function () {
var o = this.options;
if (o.defaultShowIndex !== false) {
this.setSelect(o.defaultShowIndex);
}
@ -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();

2
dist/case.js vendored

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

257
dist/core.js vendored

@ -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,93 +19715,6 @@ 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
@ -19784,8 +19722,7 @@ BI.EffectShowAction = BI.inherit(BI.Action, {
*/
BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {
});
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
},
_init: function () {
@ -19794,43 +19731,14 @@ BI.ShowAction = BI.inherit(BI.Action, {
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){
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) {
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;
});
if (index > -1) {
this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName));
delete this._children[this._getCardName(cardName)];
child.destroy();
}
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;
}

8
dist/widget.js vendored

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

56
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);
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)));
},

7
src/base/combination/navigation.js

@ -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 = {};
@ -54,6 +53,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this)
})
},
mounted: function () {
var o = this.options;
if (o.defaultShowIndex !== false) {
this.setSelect(o.defaultShowIndex);
}

2
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();

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

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

9
src/core/action/action.show.js

@ -6,8 +6,7 @@
*/
BI.ShowAction = BI.inherit(BI.Action, {
_defaultConfig: function () {
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {
});
return BI.extend(BI.ShowAction.superclass._defaultConfig.apply(this, arguments), {});
},
_init: function () {
@ -16,11 +15,13 @@ BI.ShowAction = BI.inherit(BI.Action, {
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) {
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));
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();
},

28
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();

19
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 = [];

81
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;
});
if (index > -1) {
this.options.items.splice(index, 1);
var child = this.getWidgetByName(this._getCardName(cardName));
delete this._children[this._getCardName(cardName)];
child.destroy();
}
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;
}

8
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;
});
}
},

Loading…
Cancel
Save