Browse Source

整理代码

es6
guy 3 years ago
parent
commit
e801e4bee9
  1. 43
      src/core/wrapper/layout.js
  2. 4
      src/core/wrapper/layout/fill/float.fill.horizontal.js
  3. 4
      src/core/wrapper/layout/layout.border.js
  4. 4
      src/core/wrapper/layout/layout.card.js
  5. 27
      src/core/wrapper/layout/layout.division.js
  6. 22
      src/core/wrapper/layout/layout.grid.js
  7. 27
      src/core/wrapper/layout/layout.inline.js
  8. 4
      src/core/wrapper/layout/layout.table.js
  9. 8
      src/core/wrapper/layout/layout.tape.js
  10. 4
      src/core/wrapper/layout/layout.td.js
  11. 4
      src/core/wrapper/layout/layout.window.js
  12. 6
      src/core/wrapper/layout/middle/middle.center.js
  13. 6
      src/core/wrapper/layout/middle/middle.float.center.js
  14. 6
      src/core/wrapper/layout/middle/middle.horizontal.js
  15. 6
      src/core/wrapper/layout/middle/middle.vertical.js

43
src/core/wrapper/layout.js

@ -550,8 +550,15 @@ BI.Layout = BI.inherit(BI.Widget, {
return updated; return updated;
}, },
shouldUpdate: function () { forceUpdate: function (opt) {
return true; if (this._isMounted) {
BI.each(this._children, function (i, c) {
c.destroy();
});
this._children = {};
}
this.options.items = opt.items;
this.stroke(opt.items);
}, },
update: function (opt) { update: function (opt) {
@ -560,28 +567,6 @@ BI.Layout = BI.inherit(BI.Widget, {
var updated = this.updateChildren(o.items, items); var updated = this.updateChildren(o.items, items);
this.options.items = items; this.options.items = items;
return updated; return updated;
// var updated, i, len;
// for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) {
// if (!this._compare(o.items[i], items[i])) {
// updated = this.updateItemAt(i, items[i]) || updated;
// }
// }
// if (o.items.length > items.length) {
// var deleted = [];
// for (i = items.length; i < o.items.length; i++) {
// deleted.push(this._children[this._getChildName(i)]);
// delete this._children[this._getChildName(i)];
// }
// o.items.splice(items.length);
// BI.each(deleted, function (i, w) {
// w._destroy();
// })
// } else if (items.length > o.items.length) {
// for (i = o.items.length; i < items.length; i++) {
// this.addItemAt(i, items[i]);
// }
// }
// return updated;
}, },
stroke: function (items) { stroke: function (items) {
@ -620,19 +605,11 @@ BI.Layout = BI.inherit(BI.Widget, {
}, },
populate: function (items) { populate: function (items) {
var self = this, o = this.options;
items = items || []; items = items || [];
var shouldUpdate = this.shouldUpdate(); if (this._isMounted) {
if (this._isMounted && shouldUpdate) {
this.update({items: items}); this.update({items: items});
return; return;
} }
if (this._isMounted && !shouldUpdate){
BI.each(this._children, function (i, c) {
c.destroy();
});
this._children = {};
}
this.options.items = items; this.options.items = items;
this.stroke(items); this.stroke(items);
}, },

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

@ -123,8 +123,8 @@ BI.FloatHorizontalFillLayout = BI.inherit(BI.Layout, {
}); });
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -126,8 +126,8 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
} }
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -48,8 +48,8 @@ BI.CardLayout = BI.inherit(BI.Layout, {
}); });
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
empty: function () { empty: function () {

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

@ -11,29 +11,6 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
columns: null, columns: null,
rows: null, rows: null,
items: [] items: []
// [
// {
// column: 0,
// row: 0,
// width: 0.25,
// height: 0.33,
// el: {type: 'bi.button', text: 'button1'}
// },
// {
// column: 1,
// row: 1,
// width: 0.25,
// height: 0.33,
// el: {type: 'bi.button', text: 'button2'}
// },
// {
// column: 3,
// row: 2,
// width: 0.25,
// height: 0.33,
// el: {type: 'bi.button', text: 'button3'}
// }
// ]
}); });
}, },
render: function () { render: function () {
@ -147,8 +124,8 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
} }
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -11,23 +11,6 @@ BI.GridLayout = BI.inherit(BI.Layout, {
columns: null, columns: null,
rows: null, rows: null,
items: [] items: []
/* [
{
column: 0,
row: 0,
el: {type: 'bi.button', text: 'button1'}
},
{
column: 1,
row: 1,
el: {type: 'bi.button', text: 'button2'}
},
{
column: 3,
row: 2,
el: {type: 'bi.button', text: 'button3'}
}
]*/
}); });
}, },
render: function () { render: function () {
@ -40,7 +23,6 @@ BI.GridLayout = BI.inherit(BI.Layout, {
}, },
addItem: function () { addItem: function () {
// do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, },
@ -119,8 +101,8 @@ BI.GridLayout = BI.inherit(BI.Layout, {
} }
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

27
src/core/wrapper/layout/layout.inline.js

@ -52,19 +52,28 @@ BI.InlineLayout = BI.inherit(BI.Layout, {
}); });
w.element.addClass("i-item"); w.element.addClass("i-item");
if (columnSize === "fill" || columnSize === "") { if (columnSize === "fill" || columnSize === "") {
var left = o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0), var length = o.hgap;
right = o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0); var fillCount = 0, autoCount = 0;
for (var k = 0; k < i; k++) { for (var k = 0, len = o.columnSize.length || o.items.length; k < len; k++) {
left += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + (o.columnSize[k] || o.items[k].width); var cz = o.columnSize.length > 0 ? o.columnSize[k] : o.items[k].width;
} if (cz === "fill") {
for (var k = i + 1, len = o.columnSize.length || o.items.length; k < len; k++) { fillCount++;
right += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + (o.columnSize[k] || o.items[k].width); cz = 0;
} else if (cz === "" || BI.isNull(cz)) {
autoCount++;
cz = 0;
}
length += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + cz;
} }
if (columnSize === "fill") { if (columnSize === "fill") {
w.element.css("min-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")"); w.element.css("min-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")");
} }
if (o.horizontalAlign === BI.HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) { if (o.horizontalAlign === BI.HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) {
w.element.css("max-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")"); if (columnSize === "fill") {
w.element.css("max-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")");
} else {
w.element.css("max-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (autoCount > 1 ? "/" + autoCount : "") + ")");
}
} }
} }
this._handleGap(w, item, i); this._handleGap(w, item, i);

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

@ -121,8 +121,8 @@ BI.TableLayout = BI.inherit(BI.Layout, {
// console.log("table布局不需要resize"); // console.log("table布局不需要resize");
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -119,8 +119,8 @@ BI.HTapeLayout = BI.inherit(BI.Layout, {
}); });
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {
@ -251,8 +251,8 @@ BI.VTapeLayout = BI.inherit(BI.Layout, {
}); });
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -172,8 +172,8 @@ BI.TdLayout = BI.inherit(BI.Layout, {
this.element.append(this.$table); this.element.append(this.$table);
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -167,8 +167,8 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
} }
}, },
shouldUpdate: function () { update: function (opt) {
return false; return this.forceUpdate(opt);
}, },
populate: function (items) { populate: function (items) {

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

@ -48,7 +48,7 @@ BI.CenterLayout = BI.inherit(BI.Layout, {
return { return {
type: "bi.grid", type: "bi.grid",
ref: function (_ref) { ref: function (_ref) {
self.wrapper = _ref; self.layout = _ref;
}, },
columns: list.length, columns: list.length,
rows: 1, rows: 1,
@ -66,11 +66,11 @@ BI.CenterLayout = BI.inherit(BI.Layout, {
}, },
update: function (opt) { update: function (opt) {
return this.wrapper.update(opt); return this.layout.update(opt);
}, },
populate: function (items) { populate: function (items) {
this.wrapper.populate.apply(this.wrapper, arguments); this.layout.populate.apply(this.layout, arguments);
} }
}); });
BI.shortcut("bi.center", BI.CenterLayout); BI.shortcut("bi.center", BI.CenterLayout);

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

@ -49,7 +49,7 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, {
return { return {
type: "bi.left", type: "bi.left",
ref: function (_ref) { ref: function (_ref) {
self.wrapper = _ref; self.layout = _ref;
}, },
items: list items: list
}; };
@ -65,11 +65,11 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, {
}, },
update: function (opt) { update: function (opt) {
return this.wrapper.update(opt); return this.layout.update(opt);
}, },
populate: function (items) { populate: function (items) {
this.wrapper.populate.apply(this.wrapper, arguments); this.layout.populate.apply(this.layout, arguments);
} }
}); });
BI.shortcut("bi.float_center", BI.FloatCenterLayout); BI.shortcut("bi.float_center", BI.FloatCenterLayout);

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

@ -46,7 +46,7 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, {
return { return {
type: "bi.grid", type: "bi.grid",
ref: function (_ref) { ref: function (_ref) {
self.wrapper = _ref; self.layout = _ref;
}, },
columns: list.length, columns: list.length,
rows: 1, rows: 1,
@ -64,11 +64,11 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, {
}, },
update: function (opt) { update: function (opt) {
return this.wrapper.update(opt); return this.layout.update(opt);
}, },
populate: function (items) { populate: function (items) {
this.wrapper.populate.apply(this.wrapper, arguments); this.layout.populate.apply(this.layout, arguments);
} }
}); });
BI.shortcut("bi.horizontal_center", BI.HorizontalCenterLayout); BI.shortcut("bi.horizontal_center", BI.HorizontalCenterLayout);

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

@ -47,7 +47,7 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, {
return { return {
type: "bi.grid", type: "bi.grid",
ref: function (_ref) { ref: function (_ref) {
self.wrapper = _ref; self.layout = _ref;
}, },
columns: 1, columns: 1,
rows: list.length, rows: list.length,
@ -65,11 +65,11 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, {
}, },
update: function (opt) { update: function (opt) {
return this.wrapper.update(opt); return this.layout.update(opt);
}, },
populate: function (items) { populate: function (items) {
this.wrapper.populate.apply(this.wrapper, arguments); this.layout.populate.apply(this.layout, arguments);
} }
}); });
BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout); BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout);

Loading…
Cancel
Save