Browse Source

tab和navigation加入single属性

es6
guy 8 years ago
parent
commit
7e1b8c1514
  1. 42
      bi/base.js
  2. 2
      bi/core.js
  3. 42
      dist/base.js
  4. 2
      dist/core.js
  5. 27
      src/base/combination/navigation.js
  6. 15
      src/base/combination/tab.js
  7. 2
      src/core/wrapper/layout/layout.card.js

42
bi/base.js

@ -3920,6 +3920,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
single: false,
defaultShowIndex: 0, defaultShowIndex: 0,
tab: { tab: {
type: "bi.button_group", type: "bi.button_group",
@ -3973,6 +3974,18 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
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) {
@ -3980,12 +3993,13 @@ BI.Navigation = BI.inherit(BI.Widget, {
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._deleteOtherCards(v);
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
@ -3996,16 +4010,23 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
setSelect: function (v) { _assertCard: function () {
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);
this.afterCardCreated(v); this.afterCardCreated(v);
} }
},
setSelect: function (v) {
this._assertCard();
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.showIndex !== v) {
this.showIndex = v;
BI.nextTick(BI.bind(this.afterCardShow, this, v)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}
}, },
getSelect: function () { getSelect: function () {
@ -4636,6 +4657,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tab", baseCls: "bi-tab",
direction: "top",//top, bottom, left, right, custom direction: "top",//top, bottom, left, right, custom
single: false, //是不是单页面
logic: { logic: {
dynamic: false dynamic: false
}, },
@ -4675,6 +4697,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return card; return card;
}, },
afterCardShow: function (v) { afterCardShow: function (v) {
self._deleteOtherCards(v);
self.curr = v; self.curr = v;
} }
}); });
@ -4683,6 +4706,18 @@ BI.Tab = BI.inherit(BI.Widget, {
}); });
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
_assertCard: function (v) { _assertCard: function (v) {
if (!this.layout.isCardExisted(v)) { if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
@ -4702,6 +4737,7 @@ BI.Tab = BI.inherit(BI.Widget, {
this.tab && this.tab.setValue(v); this.tab && this.tab.setValue(v);
this._assertCard(v); this._assertCard(v);
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.curr !== v) { if (this.curr !== v) {
this.curr = v; this.curr = v;
} }

2
bi/core.js

@ -13289,7 +13289,7 @@ BI.CardLayout = BI.inherit(BI.Layout, {
isCardExisted: function (cardName) { isCardExisted: function (cardName) {
return BI.some(this.options.items, function (i, item) { return BI.some(this.options.items, function (i, item) {
return item.cardName === cardName && item.el; return item.cardName == cardName && item.el;
}); });
}, },

42
dist/base.js vendored

@ -3920,6 +3920,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
single: false,
defaultShowIndex: 0, defaultShowIndex: 0,
tab: { tab: {
type: "bi.button_group", type: "bi.button_group",
@ -3973,6 +3974,18 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
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) {
@ -3980,12 +3993,13 @@ BI.Navigation = BI.inherit(BI.Widget, {
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._deleteOtherCards(v);
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
@ -3996,16 +4010,23 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
setSelect: function (v) { _assertCard: function () {
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);
this.afterCardCreated(v); this.afterCardCreated(v);
} }
},
setSelect: function (v) {
this._assertCard();
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.showIndex !== v) {
this.showIndex = v;
BI.nextTick(BI.bind(this.afterCardShow, this, v)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}
}, },
getSelect: function () { getSelect: function () {
@ -4636,6 +4657,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tab", baseCls: "bi-tab",
direction: "top",//top, bottom, left, right, custom direction: "top",//top, bottom, left, right, custom
single: false, //是不是单页面
logic: { logic: {
dynamic: false dynamic: false
}, },
@ -4675,6 +4697,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return card; return card;
}, },
afterCardShow: function (v) { afterCardShow: function (v) {
self._deleteOtherCards(v);
self.curr = v; self.curr = v;
} }
}); });
@ -4683,6 +4706,18 @@ BI.Tab = BI.inherit(BI.Widget, {
}); });
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
_assertCard: function (v) { _assertCard: function (v) {
if (!this.layout.isCardExisted(v)) { if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
@ -4702,6 +4737,7 @@ BI.Tab = BI.inherit(BI.Widget, {
this.tab && this.tab.setValue(v); this.tab && this.tab.setValue(v);
this._assertCard(v); this._assertCard(v);
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.curr !== v) { if (this.curr !== v) {
this.curr = v; this.curr = v;
} }

2
dist/core.js vendored

@ -26842,7 +26842,7 @@ BI.CardLayout = BI.inherit(BI.Layout, {
isCardExisted: function (cardName) { isCardExisted: function (cardName) {
return BI.some(this.options.items, function (i, item) { return BI.some(this.options.items, function (i, item) {
return item.cardName === cardName && item.el; return item.cardName == cardName && item.el;
}); });
}, },

27
src/base/combination/navigation.js

@ -9,6 +9,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
logic: { logic: {
dynamic: false dynamic: false
}, },
single: false,
defaultShowIndex: 0, defaultShowIndex: 0,
tab: { tab: {
type: "bi.button_group", type: "bi.button_group",
@ -62,6 +63,18 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
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) {
@ -69,12 +82,13 @@ BI.Navigation = BI.inherit(BI.Widget, {
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._deleteOtherCards(v);
this.options.afterCardShow.apply(this, arguments); this.options.afterCardShow.apply(this, arguments);
}, },
@ -85,16 +99,23 @@ BI.Navigation = BI.inherit(BI.Widget, {
} }
}, },
setSelect: function (v) { _assertCard: function () {
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);
this.afterCardCreated(v); this.afterCardCreated(v);
} }
},
setSelect: function (v) {
this._assertCard();
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.showIndex !== v) {
this.showIndex = v;
BI.nextTick(BI.bind(this.afterCardShow, this, v)); BI.nextTick(BI.bind(this.afterCardShow, this, v));
}
}, },
getSelect: function () { getSelect: function () {

15
src/base/combination/tab.js

@ -7,6 +7,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tab", baseCls: "bi-tab",
direction: "top",//top, bottom, left, right, custom direction: "top",//top, bottom, left, right, custom
single: false, //是不是单页面
logic: { logic: {
dynamic: false dynamic: false
}, },
@ -46,6 +47,7 @@ BI.Tab = BI.inherit(BI.Widget, {
return card; return card;
}, },
afterCardShow: function (v) { afterCardShow: function (v) {
self._deleteOtherCards(v);
self.curr = v; self.curr = v;
} }
}); });
@ -54,6 +56,18 @@ BI.Tab = BI.inherit(BI.Widget, {
}); });
}, },
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
_assertCard: function (v) { _assertCard: function (v) {
if (!this.layout.isCardExisted(v)) { if (!this.layout.isCardExisted(v)) {
var card = this.options.cardCreator(v); var card = this.options.cardCreator(v);
@ -73,6 +87,7 @@ BI.Tab = BI.inherit(BI.Widget, {
this.tab && this.tab.setValue(v); this.tab && this.tab.setValue(v);
this._assertCard(v); this._assertCard(v);
this.layout.showCardByName(v); this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.curr !== v) { if (this.curr !== v) {
this.curr = v; this.curr = v;
} }

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

@ -63,7 +63,7 @@ BI.CardLayout = BI.inherit(BI.Layout, {
isCardExisted: function (cardName) { isCardExisted: function (cardName) {
return BI.some(this.options.items, function (i, item) { return BI.some(this.options.items, function (i, item) {
return item.cardName === cardName && item.el; return item.cardName == cardName && item.el;
}); });
}, },

Loading…
Cancel
Save