Browse Source

Pull request #1531: 无JIRA任务 重构context

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '6ebdc3591e14f0ed3866cd814c1786cb5ce1f6d7':
  context重构
  context重构
  context重构
  context重构
  context
  Composition API
  重构context
es6
guy 4 years ago
parent
commit
67f2894a0d
  1. 51
      dist/fix/fix.compact.ie.js
  2. 59
      dist/fix/fix.compact.js
  3. 22
      src/core/shortcut.js
  4. 42
      src/core/widget.js
  5. 2
      src/core/wrapper/layout.js
  6. 4
      src/core/wrapper/layout/adapt/adapt.table.js
  7. 8
      src/core/wrapper/layout/adapt/float.horizontal.js
  8. 12
      src/core/wrapper/layout/layout.border.js
  9. 6
      src/core/wrapper/layout/layout.card.js
  10. 4
      src/core/wrapper/layout/layout.division.js
  11. 8
      src/core/wrapper/layout/layout.grid.js
  12. 4
      src/core/wrapper/layout/layout.horizontal.js
  13. 4
      src/core/wrapper/layout/layout.table.js
  14. 6
      src/core/wrapper/layout/layout.tape.js
  15. 8
      src/core/wrapper/layout/layout.td.js
  16. 4
      src/core/wrapper/layout/layout.window.js
  17. 6
      src/core/wrapper/layout/middle/middle.center.js
  18. 6
      src/core/wrapper/layout/middle/middle.float.center.js
  19. 6
      src/core/wrapper/layout/middle/middle.horizontal.js
  20. 6
      src/core/wrapper/layout/middle/middle.vertical.js

51
dist/fix/fix.compact.ie.js vendored

@ -32,20 +32,9 @@
Fix.Model.target = target = _target; Fix.Model.target = target = _target;
} }
function popTarget() { function popTarget () {
Fix.Model.target = target = targetStack.pop(); targetStack.pop();
} Fix.Model.target = target = null;
var context = null;
var contextStack = [];
function pushContext(_context) {
if (context) contextStack.push(context);
Fix.Model.context = context = _context;
}
function popContext() {
Fix.Model.context = context = contextStack.pop();
} }
var oldWatch = Fix.watch; var oldWatch = Fix.watch;
@ -69,7 +58,7 @@
if (target != null) { if (target != null) {
return target; return target;
} }
widget = widget || context; widget = widget || BI.Widget.context;
var p = widget; var p = widget;
while (p) { while (p) {
if (p instanceof Fix.Model || p.store || p.__cacheStore) { if (p instanceof Fix.Model || p.store || p.__cacheStore) {
@ -86,20 +75,20 @@
} }
} }
var _create = BI.createWidget; // var _create = BI.createWidget;
BI.createWidget = function (item, options, context) { // BI.createWidget = function (item, options, context) {
var pushed = false; // var pushed = false;
if (BI.isWidget(options)) { // if (BI.isWidget(options)) {
pushContext(options); // pushContext(options);
pushed = true; // pushed = true;
} else if (context != null) { // } else if (context != null) {
pushContext(context); // pushContext(context);
pushed = true; // pushed = true;
} // }
var result = _create.apply(this, arguments); // var result = _create.apply(this, arguments);
pushed && popContext(); // pushed && popContext();
return result; // return result;
}; // };
BI.watch = function (watch, handler) { BI.watch = function (watch, handler) {
if (BI.Widget.current) { if (BI.Widget.current) {
@ -124,9 +113,9 @@
_.each(["populate", "addItems", "prependItems"], function (name) { _.each(["populate", "addItems", "prependItems"], function (name) {
var old = BI.Loader.prototype[name]; var old = BI.Loader.prototype[name];
BI.Loader.prototype[name] = function () { BI.Loader.prototype[name] = function () {
pushContext(this); BI.Widget.pushContext(this);
var result = old.apply(this, arguments); var result = old.apply(this, arguments);
popContext(); BI.Widget.popContext();
return result; return result;
}; };
}); });

59
dist/fix/fix.compact.js vendored

@ -33,19 +33,8 @@
} }
function popTarget () { function popTarget () {
Fix.Model.target = target = targetStack.pop(); targetStack.pop();
} Fix.Model.target = target = null;
var context = null;
var contextStack = [];
function pushContext (_context) {
if (context) contextStack.push(context);
Fix.Model.context = context = _context;
}
function popContext () {
Fix.Model.context = context = contextStack.pop();
} }
var oldWatch = Fix.watch; var oldWatch = Fix.watch;
@ -73,7 +62,7 @@
if (target != null) { if (target != null) {
return target; return target;
} }
widget = widget || context; widget = widget || BI.Widget.context;
var p = widget; var p = widget;
while (p) { while (p) {
if (p instanceof Fix.Model || p.store || p.__cacheStore) { if (p instanceof Fix.Model || p.store || p.__cacheStore) {
@ -90,25 +79,25 @@
} }
} }
var _create = BI.createWidget; // var _create = BI.createWidget;
BI.createWidget = function (item, options, context) { // BI.createWidget = function (item, options, context) {
var pushed = false; // var pushed = false;
if (BI.isWidget(options)) { // if (BI.isWidget(options)) {
pushContext(options); // pushContext(options);
pushed = true; // pushed = true;
} else if (context != null) { // } else if (context != null) {
pushContext(context); // pushContext(context);
pushed = true; // pushed = true;
} // }
var result = _create.apply(this, arguments); // var result = _create.apply(this, arguments);
// try { // // try {
// var result = _create.apply(this, arguments); // // var result = _create.apply(this, arguments);
// } catch (e) { // // } catch (e) {
// console.error(e); // // console.error(e);
// } // // }
pushed && popContext(); // pushed && popContext();
return result; // return result;
}; // };
BI.watch = function (watch, handler) { BI.watch = function (watch, handler) {
if (BI.Widget.current) { if (BI.Widget.current) {
@ -133,13 +122,13 @@
_.each(["populate", "addItems", "prependItems"], function (name) { _.each(["populate", "addItems", "prependItems"], function (name) {
var old = BI.Loader.prototype[name]; var old = BI.Loader.prototype[name];
BI.Loader.prototype[name] = function () { BI.Loader.prototype[name] = function () {
pushContext(this); BI.Widget.pushContext(this);
try { try {
var result = old.apply(this, arguments); var result = old.apply(this, arguments);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
popContext(); BI.Widget.popContext();
return result; return result;
}; };
}); });

22
src/core/shortcut.js

@ -11,7 +11,7 @@
}; };
// 根据配置属性生成widget // 根据配置属性生成widget
var createWidget = function (config) { var createWidget = function (config, lazy) {
var cls = kv[config.type]; var cls = kv[config.type];
if (!cls) { if (!cls) {
@ -19,17 +19,17 @@
} }
var widget = new cls(); var widget = new cls();
BI.Widget.pushContext(widget);
widget._initProps(config); widget._initProps(config);
widget._initRoot(); widget._initRoot();
widget._initRef(); if (!lazy || config.element || config.root) {
// if (config.element || config.root) { widget._lazyConstructor();
widget._lazyConstructor(); }
// } BI.Widget.popContext();
return widget; return widget;
}; };
BI.createWidget = BI.createWidget || function (item, options, context) { BI.createWidget = BI.createWidget || function (item, options, context, lazy) {
// 先把准备环境准备好 // 先把准备环境准备好
BI.init(); BI.init();
var el, w; var el, w;
@ -57,7 +57,7 @@
BI.Plugin.getObject(el.type, this); BI.Plugin.getObject(el.type, this);
} }
}]); }]);
return w.type === el.type ? createWidget(w) : BI.createWidget(BI.extend({}, item, {type: w.type}, options)); return w.type === el.type ? createWidget(w, lazy) : BI.createWidget(BI.extend({}, item, {type: w.type}), options, context, lazy);
} }
if (item.el && (item.el.type || options.type)) { if (item.el && (item.el.type || options.type)) {
el = BI.extend({}, options, item.el); el = BI.extend({}, options, item.el);
@ -68,7 +68,7 @@
BI.Plugin.getObject(el.type, this); BI.Plugin.getObject(el.type, this);
} }
}]); }]);
return w.type === el.type ? createWidget(w) : BI.createWidget(BI.extend({}, item, {type: w.type}, options)); return w.type === el.type ? createWidget(w, lazy) : BI.createWidget(BI.extend({}, item, {type: w.type}), options, context, lazy);
} }
if (BI.isWidget(item.el)) { if (BI.isWidget(item.el)) {
return item.el; return item.el;
@ -76,6 +76,10 @@
throw new Error("无法根据item创建组件"); throw new Error("无法根据item创建组件");
}; };
BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) {
return BI.createWidget(item, options, context, true);
};
BI.createElement = BI.createElement || function () { BI.createElement = BI.createElement || function () {
var widget = BI.createWidget.apply(this, arguments); var widget = BI.createWidget.apply(this, arguments);
return widget.element; return widget.element;

42
src/core/widget.js

@ -35,6 +35,7 @@
if (!this._constructed) { if (!this._constructed) {
this._constructed = true; this._constructed = true;
this._init(); this._init();
this._initRef();
} }
}, },
@ -181,7 +182,7 @@
} }
if (BI.isArray(els)) { if (BI.isArray(els)) {
BI.each(els, function (i, el) { BI.each(els, function (i, el) {
BI.createWidget(el, { BI._lazyCreateWidget(el, {
element: self element: self
}); });
}); });
@ -337,7 +338,9 @@
throw new Error("name has already been existed"); throw new Error("name has already been existed");
} }
widget._setParent && widget._setParent(this); widget._setParent && widget._setParent(this);
BI.Widget.pushContext(widget);
widget._lazyConstructor(); widget._lazyConstructor();
BI.Widget.popContext();
widget.on(BI.Events.DESTROY, function () { widget.on(BI.Events.DESTROY, function () {
BI.remove(self._children, this); BI.remove(self._children, this);
}); });
@ -505,36 +508,47 @@
this.purgeListeners(); this.purgeListeners();
} }
}); });
var context = null; var context = null, current = null;
var contextStack = []; var contextStack = [], currentStack = [];
function pushTarget (_context) { BI.Widget.pushContext = function (_context) {
if (context) contextStack.push(context); if (context) contextStack.push(context);
BI.Widget.current = context = _context; BI.Widget.context = context = _context;
};
BI.Widget.popContext = function () {
contextStack.pop();
BI.Widget.context = context = null;
};
function pushTarget (_current) {
if (current) currentStack.push(current);
BI.Widget.current = current = _current;
} }
function popTarget () { function popTarget () {
BI.Widget.current = context = contextStack.pop(); currentStack.pop();
BI.Widget.current = current = null;
} }
BI.onBeforeMount = function (beforeMount) { BI.onBeforeMount = function (beforeMount) {
if (context) { if (current) {
context.beforeMount = beforeMount; current.beforeMount = beforeMount;
} }
}; };
BI.onMounted = function (mounted) { BI.onMounted = function (mounted) {
if (context) { if (current) {
context.mounted = mounted; current.mounted = mounted;
} }
}; };
BI.onBeforeUnmount = function (beforeDestroy) { BI.onBeforeUnmount = function (beforeDestroy) {
if (context) { if (current) {
context.beforeDestroy = beforeDestroy; current.beforeDestroy = beforeDestroy;
} }
}; };
BI.onUnmounted = function (destroyed) { BI.onUnmounted = function (destroyed) {
if (context) { if (current) {
context.destroyed = destroyed; current.destroyed = destroyed;
} }
}; };

2
src/core/wrapper/layout.js

@ -89,7 +89,7 @@ BI.Layout = BI.inherit(BI.Widget, {
_addElement: function (i, item, context) { _addElement: function (i, item, context) {
var self = this, w; var self = this, w;
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
w = BI.createWidget(item, context); w = BI._lazyCreateWidget(item, context);
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) {

4
src/core/wrapper/layout/adapt/adapt.table.js

@ -37,9 +37,9 @@ BI.TableAdaptLayout = BI.inherit(BI.Layout, {
var td; var td;
var width = o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i]; var width = o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i];
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({position: "relative", top: "0", left: "0", margin: "0px auto"}); w.element.css({position: "relative", top: "0", left: "0", margin: "0px auto"});
td = BI.createWidget({ td = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
width: width, width: width,
items: [w] items: [w]

8
src/core/wrapper/layout/adapt/float.horizontal.js

@ -33,7 +33,7 @@ BI.FloatHorizontalLayout = BI.inherit(BI.Layout, {
delete self._children[i]; delete self._children[i];
} }
}); });
BI.createWidget({ BI._lazyCreateWidget({
type: "bi.horizontal_auto", type: "bi.horizontal_auto",
element: this, element: this,
items: [this.left] items: [this.left]
@ -42,7 +42,7 @@ BI.FloatHorizontalLayout = BI.inherit(BI.Layout, {
_addElement: function (i, item) { _addElement: function (i, item) {
var self = this, o = this.options; var self = this, o = this.options;
this.left = BI.createWidget({ this.left = BI._lazyCreateWidget({
type: "bi.vertical", type: "bi.vertical",
items: [item], items: [item],
hgap: o.hgap, hgap: o.hgap,
@ -53,7 +53,7 @@ BI.FloatHorizontalLayout = BI.inherit(BI.Layout, {
rgap: o.rgap rgap: o.rgap
}); });
this.container = BI.createWidget({ this.container = BI._lazyCreateWidget({
type: "bi.left", type: "bi.left",
element: this, element: this,
items: [this.left] items: [this.left]
@ -67,4 +67,4 @@ BI.FloatHorizontalLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.horizontal_float", BI.FloatHorizontalLayout); BI.shortcut("bi.horizontal_float", BI.FloatHorizontalLayout);

12
src/core/wrapper/layout/layout.border.js

@ -36,7 +36,7 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
if (item != null) { if (item != null) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this.getName() + "north")) { if (!this.hasWidget(this.getName() + "north")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
this.addWidget(this.getName() + "north", w); this.addWidget(this.getName() + "north", w);
} }
this.getWidgetByName(this.getName() + "north").element.height(item.height) this.getWidgetByName(this.getName() + "north").element.height(item.height)
@ -56,7 +56,7 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
if (item != null) { if (item != null) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this.getName() + "south")) { if (!this.hasWidget(this.getName() + "south")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
this.addWidget(this.getName() + "south", w); this.addWidget(this.getName() + "south", w);
} }
this.getWidgetByName(this.getName() + "south").element.height(item.height) this.getWidgetByName(this.getName() + "south").element.height(item.height)
@ -76,7 +76,7 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
if (item != null) { if (item != null) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this.getName() + "west")) { if (!this.hasWidget(this.getName() + "west")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
this.addWidget(this.getName() + "west", w); this.addWidget(this.getName() + "west", w);
} }
this.getWidgetByName(this.getName() + "west").element.width(item.width) this.getWidgetByName(this.getName() + "west").element.width(item.width)
@ -96,7 +96,7 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
if (item != null) { if (item != null) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this.getName() + "east")) { if (!this.hasWidget(this.getName() + "east")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
this.addWidget(this.getName() + "east", w); this.addWidget(this.getName() + "east", w);
} }
this.getWidgetByName(this.getName() + "east").element.width(item.width) this.getWidgetByName(this.getName() + "east").element.width(item.width)
@ -115,7 +115,7 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
item = regions["center"]; item = regions["center"];
if (item != null) { if (item != null) {
if (!this.hasWidget(this.getName() + "center")) { if (!this.hasWidget(this.getName() + "center")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
this.addWidget(this.getName() + "center", w); this.addWidget(this.getName() + "center", w);
} }
this.getWidgetByName(this.getName() + "center").element this.getWidgetByName(this.getName() + "center").element
@ -132,4 +132,4 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.border", BI.BorderLayout); BI.shortcut("bi.border", BI.BorderLayout);

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

@ -28,7 +28,7 @@ BI.CardLayout = BI.inherit(BI.Layout, {
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item) { if (item) {
if (!self.hasWidget(item.cardName)) { if (!self.hasWidget(item.cardName)) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.on(BI.Events.DESTROY, function () { w.on(BI.Events.DESTROY, function () {
var index = BI.findIndex(o.items, function (i, tItem) { var index = BI.findIndex(o.items, function (i, tItem) {
return tItem.cardName == item.cardName; return tItem.cardName == item.cardName;
@ -98,7 +98,7 @@ BI.CardLayout = BI.inherit(BI.Layout, {
if (this.isCardExisted(cardName)) { if (this.isCardExisted(cardName)) {
throw new Error("cardName is already exist"); throw new Error("cardName is already exist");
} }
var widget = BI.createWidget(cardItem, this); var widget = BI._lazyCreateWidget(cardItem, this);
widget.element.css({ widget.element.css({
position: "relative", position: "relative",
top: "0", top: "0",
@ -206,4 +206,4 @@ BI.CardLayout = BI.inherit(BI.Layout, {
} }
} }
}); });
BI.shortcut("bi.card", BI.CardLayout); BI.shortcut("bi.card", BI.CardLayout);

4
src/core/wrapper/layout/layout.division.js

@ -115,7 +115,7 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
throw new Error("item be required"); throw new Error("item be required");
} }
if (!this.hasWidget(this.getName() + i + "_" + j)) { if (!this.hasWidget(this.getName() + i + "_" + j)) {
var w = BI.createWidget(map[i][j]); var w = BI._lazyCreateWidget(map[i][j]);
this.addWidget(this.getName() + i + "_" + j, w); this.addWidget(this.getName() + i + "_" + j, w);
} else { } else {
w = this.getWidgetByName(this.getName() + i + "_" + j); w = this.getWidgetByName(this.getName() + i + "_" + j);
@ -159,4 +159,4 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.division", BI.DivisionLayout); BI.shortcut("bi.division", BI.DivisionLayout);

8
src/core/wrapper/layout/layout.grid.js

@ -93,16 +93,16 @@ BI.GridLayout = BI.inherit(BI.Layout, {
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (BI.isArray(item)) { if (BI.isArray(item)) {
BI.each(item, function (j, el) { BI.each(item, function (j, el) {
els[i][j] = BI.createWidget(el); els[i][j] = BI._lazyCreateWidget(el);
}); });
return; return;
} }
els[item.row][item.column] = BI.createWidget(item); els[item.row][item.column] = BI._lazyCreateWidget(item);
}); });
for (var i = 0; i < rows; i++) { for (var i = 0; i < rows; i++) {
for (var j = 0; j < columns; j++) { for (var j = 0; j < columns; j++) {
if (!els[i][j]) { if (!els[i][j]) {
els[i][j] = BI.createWidget({ els[i][j] = BI._lazyCreateWidget({
type: "bi.layout" type: "bi.layout"
}); });
} }
@ -127,4 +127,4 @@ BI.GridLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.grid", BI.GridLayout); BI.shortcut("bi.grid", BI.GridLayout);

4
src/core/wrapper/layout/layout.horizontal.js

@ -41,9 +41,9 @@ BI.HorizontalLayout = BI.inherit(BI.Layout, {
var td; var td;
var width = o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i]; var width = o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i];
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({position: "relative", margin: "0px auto"}); w.element.css({position: "relative", margin: "0px auto"});
td = BI.createWidget({ td = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
tagName: "td", tagName: "td",
attributes: { attributes: {

4
src/core/wrapper/layout/layout.table.js

@ -110,7 +110,7 @@ BI.TableLayout = BI.inherit(BI.Layout, {
right: right <= 1 ? right * 100 + "%" : right right: right <= 1 ? right * 100 + "%" : right
}, arr[i])); }, arr[i]));
} }
var w = BI.createWidget({ var w = BI._lazyCreateWidget({
type: "bi.absolute", type: "bi.absolute",
height: BI.isArray(o.rowSize) ? o.rowSize[this.rows] : o.rowSize, height: BI.isArray(o.rowSize) ? o.rowSize[this.rows] : o.rowSize,
items: abs items: abs
@ -146,4 +146,4 @@ BI.TableLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.table", BI.TableLayout); BI.shortcut("bi.table", BI.TableLayout);

6
src/core/wrapper/layout/layout.tape.js

@ -47,7 +47,7 @@ BI.HTapeLayout = BI.inherit(BI.Layout, {
items = BI.compact(items); items = BI.compact(items);
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (!self.hasWidget(self.getName() + i + "")) { if (!self.hasWidget(self.getName() + i + "")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
self.addWidget(self.getName() + i + "", w); self.addWidget(self.getName() + i + "", w);
} else { } else {
w = self.getWidgetByName(self.getName() + i + ""); w = self.getWidgetByName(self.getName() + i + "");
@ -160,7 +160,7 @@ BI.VTapeLayout = BI.inherit(BI.Layout, {
items = BI.compact(items); items = BI.compact(items);
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (!self.hasWidget(self.getName() + i + "")) { if (!self.hasWidget(self.getName() + i + "")) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
self.addWidget(self.getName() + i + "", w); self.addWidget(self.getName() + i + "", w);
} else { } else {
w = self.getWidgetByName(self.getName() + i + ""); w = self.getWidgetByName(self.getName() + i + "");
@ -216,4 +216,4 @@ BI.VTapeLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.vtape", BI.VTapeLayout); BI.shortcut("bi.vtape", BI.VTapeLayout);

8
src/core/wrapper/layout/layout.td.js

@ -77,13 +77,13 @@ BI.TdLayout = BI.inherit(BI.Layout, {
} }
} }
var tr = BI.createWidget({ var tr = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
tagName: "tr" tagName: "tr"
}); });
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var w = BI.createWidget(arr[i]); var w = BI._lazyCreateWidget(arr[i]);
w.element.css({position: "relative", top: "0", left: "0", margin: "0px auto"}); w.element.css({position: "relative", top: "0", left: "0", margin: "0px auto"});
if (arr[i].lgap) { if (arr[i].lgap) {
w.element.css({"margin-left": arr[i].lgap + "px"}); w.element.css({"margin-left": arr[i].lgap + "px"});
@ -98,7 +98,7 @@ BI.TdLayout = BI.inherit(BI.Layout, {
w.element.css({"margin-bottom": arr[i].bgap + "px"}); w.element.css({"margin-bottom": arr[i].bgap + "px"});
} }
first(w, this.rows++, i); first(w, this.rows++, i);
var td = BI.createWidget({ var td = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
attributes: { attributes: {
width: o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i] width: o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i]
@ -143,4 +143,4 @@ BI.TdLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.td", BI.TdLayout); BI.shortcut("bi.td", BI.TdLayout);

4
src/core/wrapper/layout/layout.window.js

@ -95,7 +95,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
throw new Error("item be required"); throw new Error("item be required");
} }
if (!this.hasWidget(this.getName() + i + "_" + j)) { if (!this.hasWidget(this.getName() + i + "_" + j)) {
var w = BI.createWidget(o.items[i][j]); var w = BI._lazyCreateWidget(o.items[i][j]);
w.element.css({position: "absolute"}); w.element.css({position: "absolute"});
this.addWidget(this.getName() + i + "_" + j, w); this.addWidget(this.getName() + i + "_" + j, w);
} }
@ -188,4 +188,4 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
this._mount(); this._mount();
} }
}); });
BI.shortcut("bi.window", BI.WindowLayout); BI.shortcut("bi.window", BI.WindowLayout);

6
src/core/wrapper/layout/middle/middle.center.js

@ -24,7 +24,7 @@ BI.CenterLayout = BI.inherit(BI.Layout, {
list.push({ list.push({
column: i, column: i,
row: 0, row: 0,
el: BI.createWidget({ el: BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "") cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "")
}) })
@ -32,7 +32,7 @@ BI.CenterLayout = BI.inherit(BI.Layout, {
}); });
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item) { if (item) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: o.hgap + o.lgap, left: o.hgap + o.lgap,
@ -73,4 +73,4 @@ BI.CenterLayout = BI.inherit(BI.Layout, {
this.wrapper.populate.apply(this.wrapper, arguments); this.wrapper.populate.apply(this.wrapper, arguments);
} }
}); });
BI.shortcut("bi.center", BI.CenterLayout); BI.shortcut("bi.center", BI.CenterLayout);

6
src/core/wrapper/layout/middle/middle.float.center.js

@ -20,7 +20,7 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, {
var self = this, o = this.options, items = o.items; var self = this, o = this.options, items = o.items;
var list = [], width = 100 / items.length; var list = [], width = 100 / items.length;
BI.each(items, function (i) { BI.each(items, function (i) {
var widget = BI.createWidget({ var widget = BI._lazyCreateWidget({
type: "bi.default" type: "bi.default"
}); });
widget.element.addClass("center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "")).css({ widget.element.addClass("center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "")).css({
@ -33,7 +33,7 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, {
}); });
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item) { if (item) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: o.hgap + o.lgap, left: o.hgap + o.lgap,
@ -72,4 +72,4 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, {
this.wrapper.populate.apply(this.wrapper, arguments); this.wrapper.populate.apply(this.wrapper, arguments);
} }
}); });
BI.shortcut("bi.float_center", BI.FloatCenterLayout); BI.shortcut("bi.float_center", BI.FloatCenterLayout);

6
src/core/wrapper/layout/middle/middle.horizontal.js

@ -23,7 +23,7 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, {
list.push({ list.push({
column: i, column: i,
row: 0, row: 0,
el: BI.createWidget({ el: BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "") cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "")
}) })
@ -31,7 +31,7 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, {
}); });
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item) { if (item) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: o.hgap + o.lgap, left: o.hgap + o.lgap,
@ -71,4 +71,4 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, {
this.wrapper.populate.apply(this.wrapper, arguments); this.wrapper.populate.apply(this.wrapper, arguments);
} }
}); });
BI.shortcut("bi.horizontal_center", BI.HorizontalCenterLayout); BI.shortcut("bi.horizontal_center", BI.HorizontalCenterLayout);

6
src/core/wrapper/layout/middle/middle.vertical.js

@ -24,7 +24,7 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, {
list.push({ list.push({
column: 0, column: 0,
row: i, row: i,
el: BI.createWidget({ el: BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "") cls: "center-element " + (i === 0 ? "first-element " : "") + (i === items.length - 1 ? "last-element" : "")
}) })
@ -32,7 +32,7 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, {
}); });
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item) { if (item) {
var w = BI.createWidget(item); var w = BI._lazyCreateWidget(item);
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: o.hgap + o.lgap, left: o.hgap + o.lgap,
@ -72,4 +72,4 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, {
this.wrapper.populate.apply(this.wrapper, arguments); this.wrapper.populate.apply(this.wrapper, arguments);
} }
}); });
BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout); BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout);

Loading…
Cancel
Save