fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
7.4 KiB

7 years ago
/**
* 水平tape布局
* @class BI.HTapeLayout
* @extends BI.Layout
*/
BI.HTapeLayout = BI.inherit(BI.Layout, {
7 years ago
props: function () {
return BI.extend(BI.HTapeLayout.superclass.props.apply(this, arguments), {
7 years ago
baseCls: "bi-h-tape-layout",
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
items: [
{
width: 100,
7 years ago
el: {type: "bi.button", text: "button1"}
7 years ago
},
{
7 years ago
width: "fill",
el: {type: "bi.button", text: "button2"}
7 years ago
},
{
width: 200,
7 years ago
el: {type: "bi.button", text: "button3"}
7 years ago
}
]
});
},
7 years ago
render: function () {
BI.HTapeLayout.superclass.render.apply(this, arguments);
7 years ago
this.populate(this.options.items);
},
resize: function () {
this.stroke(this.options.items);
},
addItem: function (item) {
// do nothing
7 years ago
throw new Error("cannot be added");
7 years ago
},
stroke: function (items) {
var self = this, o = this.options;
items = BI.compact(items);
BI.each(items, function (i, item) {
if (!self.hasWidget(self._getChildName(i))) {
4 years ago
var w = BI._lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w);
7 years ago
} else {
w = self.getWidgetByName(self._getChildName(i));
7 years ago
}
w.element.css({position: "absolute", top: (item.vgap || 0) + (item.tgap || 0) + o.vgap + o.tgap + "px", bottom: (item.bgap || 0) + (item.vgap || 0) + o.vgap + o.bgap + "px"});
7 years ago
});
var left = {}, right = {};
left[0] = 0;
right[items.length - 1] = 0;
BI.any(items, function (i, item) {
var w = self.getWidgetByName(self._getChildName(i));
7 years ago
if (BI.isNull(left[i])) {
left[i] = left[i - 1] + items[i - 1].width + (items[i - 1].lgap || 0) + 2 * (items[i - 1].hgap || 0) + o.hgap + o.lgap + o.rgap;
7 years ago
}
if (item.width < 1 && item.width >= 0) {
7 years ago
w.element.css({left: left[i] * 100 + "%", width: item.width * 100 + "%"});
7 years ago
} else {
w.element.css({
left: left[i] + (item.lgap || 0) + (item.hgap || 0) + o.hgap + o.lgap + "px",
7 years ago
width: BI.isNumber(item.width) ? item.width : ""
});
}
if (!BI.isNumber(item.width)) {
return true;
}
});
BI.backAny(items, function (i, item) {
var w = self.getWidgetByName(self._getChildName(i));
7 years ago
if (BI.isNull(right[i])) {
right[i] = right[i + 1] + items[i + 1].width + (items[i + 1].rgap || 0) + 2 * (items[i + 1].hgap || 0) + o.hgap + o.lgap + o.rgap;
7 years ago
}
if (item.width < 1 && item.width >= 0) {
7 years ago
w.element.css({right: right[i] * 100 + "%", width: item.width * 100 + "%"});
7 years ago
} else {
w.element.css({
right: right[i] + (item.rgap || 0) + (item.hgap || 0) + o.hgap + o.rgap + "px",
7 years ago
width: BI.isNumber(item.width) ? item.width : ""
});
}
if (!BI.isNumber(item.width)) {
return true;
}
7 years ago
});
7 years ago
},
5 years ago
update: function () {
var updated;
BI.each(this._children, function (i, child) {
updated = child.update() || updated;
});
return updated;
},
7 years ago
populate: function (items) {
BI.HTapeLayout.superclass.populate.apply(this, arguments);
7 years ago
this._mount();
7 years ago
}
});
7 years ago
BI.shortcut("bi.htape", BI.HTapeLayout);
7 years ago
/**
* 垂直tape布局
* @class BI.VTapeLayout
* @extends BI.Layout
*/
BI.VTapeLayout = BI.inherit(BI.Layout, {
7 years ago
props: function () {
return BI.extend(BI.VTapeLayout.superclass.props.apply(this, arguments), {
7 years ago
baseCls: "bi-v-tape-layout",
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
items: [
{
height: 100,
7 years ago
el: {type: "bi.button", text: "button1"}
7 years ago
},
{
7 years ago
height: "fill",
el: {type: "bi.button", text: "button2"}
7 years ago
},
{
height: 200,
7 years ago
el: {type: "bi.button", text: "button3"}
7 years ago
}
]
});
},
7 years ago
render: function () {
BI.VTapeLayout.superclass.render.apply(this, arguments);
7 years ago
this.populate(this.options.items);
},
resize: function () {
this.stroke(this.options.items);
},
addItem: function (item) {
// do nothing
7 years ago
throw new Error("cannot be added");
7 years ago
},
stroke: function (items) {
var self = this, o = this.options;
items = BI.compact(items);
BI.each(items, function (i, item) {
if (!self.hasWidget(self._getChildName(i))) {
4 years ago
var w = BI._lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w);
7 years ago
} else {
w = self.getWidgetByName(self._getChildName(i));
7 years ago
}
w.element.css({position: "absolute", left: (item.lgap || 0) + (item.hgap || 0) + o.hgap + o.lgap + "px", right: + (item.hgap || 0) + (item.rgap || 0) + o.hgap + o.rgap + "px"});
7 years ago
});
var top = {}, bottom = {};
top[0] = 0;
bottom[items.length - 1] = 0;
BI.any(items, function (i, item) {
var w = self.getWidgetByName(self._getChildName(i));
7 years ago
if (BI.isNull(top[i])) {
top[i] = top[i - 1] + items[i - 1].height + (items[i - 1].tgap || 0) + 2 * (items[i - 1].vgap || 0) + o.vgap + o.tgap + o.bgap;
7 years ago
}
if (item.height < 1 && item.height >= 0) {
7 years ago
w.element.css({top: top[i] * 100 + "%", height: item.height * 100 + "%"});
7 years ago
} else {
w.element.css({
top: top[i] + (item.vgap || 0) + (item.tgap || 0) + o.vgap + o.tgap + "px",
7 years ago
height: BI.isNumber(item.height) ? item.height : ""
});
}
if (!BI.isNumber(item.height)) {
return true;
}
});
BI.backAny(items, function (i, item) {
var w = self.getWidgetByName(self._getChildName(i));
7 years ago
if (BI.isNull(bottom[i])) {
bottom[i] = bottom[i + 1] + items[i + 1].height + (items[i + 1].bgap || 0) + 2 * (items[i + 1].vgap || 0) + o.vgap + o.tgap + o.bgap;
7 years ago
}
if (item.height < 1 && item.height >= 0) {
7 years ago
w.element.css({bottom: bottom[i] * 100 + "%", height: item.height * 100 + "%"});
7 years ago
} else {
w.element.css({
bottom: bottom[i] + (item.vgap || 0) + (item.bgap || 0) + o.vgap + o.bgap + "px",
7 years ago
height: BI.isNumber(item.height) ? item.height : ""
});
}
if (!BI.isNumber(item.height)) {
return true;
}
7 years ago
});
7 years ago
},
5 years ago
update: function () {
},
7 years ago
populate: function (items) {
BI.VTapeLayout.superclass.populate.apply(this, arguments);
7 years ago
this._mount();
7 years ago
}
});
4 years ago
BI.shortcut("bi.vtape", BI.VTapeLayout);