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.

85 lines
3.3 KiB

/**
* 内联布局
* @class BI.InlineLayout
* @extends BI.Layout
*
* @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙
*/
BI.InlineLayout = BI.inherit(BI.Layout, {
props: function () {
return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), {
4 years ago
baseCls: "bi-i",
4 years ago
horizontalAlign: BI.HorizontalAlign.Left,
verticalAlign: BI.VerticalAlign.Top,
columnSize: [],
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
items: []
});
},
render: function () {
BI.InlineLayout.superclass.render.apply(this, arguments);
4 years ago
var o = this.options;
this.element.css({
textAlign: o.horizontalAlign
});
this.populate(o.items);
},
4 years ago
_addElement: function (i, item) {
var o = this.options;
var w = BI.InlineLayout.superclass._addElement.apply(this, arguments);
4 years ago
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width >= 1 ? null : item.width;
if (o.columnSize.length > 0) {
if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) {
columnSize = null;
}
}
if (columnSize > 0) {
w.element.width(columnSize < 1 ? ((columnSize * 100).toFixed(1) + "%") : (columnSize / BI.pixRatio + BI.pixUnit));
}
4 years ago
w.element.css({
position: "relative",
"vertical-align": o.verticalAlign
});
w.element.addClass("i-item");
4 years ago
if (columnSize === "fill" || columnSize === "") {
4 years ago
var left = o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0),
right = o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0);
4 years ago
for (var k = 0; k < i; k++) {
4 years ago
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);
4 years ago
}
4 years ago
for (var k = i + 1, len = o.columnSize.length || o.items.length; k < len; k++) {
4 years ago
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);
4 years ago
}
4 years ago
if (columnSize === "fill") {
4 years ago
w.element.css("min-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")");
}
if (o.horizontalAlign === BI.HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) {
4 years ago
w.element.css("max-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")");
4 years ago
}
4 years ago
}
4 years ago
this._handleGap(w, item, i);
4 years ago
if (o.verticalAlign === BI.VerticalAlign.Stretch) {
4 years ago
var top = o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0),
bottom = o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0);
4 years ago
w.element.css("height", "calc(100% - " + ((top + bottom) / BI.pixRatio + BI.pixUnit) + ")");
}
return w;
},
populate: function (items) {
BI.InlineLayout.superclass.populate.apply(this, arguments);
this._mount();
}
});
BI.shortcut("bi.inline", BI.InlineLayout);