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.
100 lines
2.8 KiB
100 lines
2.8 KiB
7 years ago
|
/**
|
||
|
* 内联布局
|
||
|
* @class BI.InlineCenterAdaptLayout
|
||
|
* @extends BI.Layout
|
||
|
*
|
||
|
* @cfg {JSON} options 配置属性
|
||
|
* @cfg {Number} [hgap=0] 水平间隙
|
||
|
* @cfg {Number} [vgap=0] 垂直间隙
|
||
|
*/
|
||
|
BI.InlineCenterAdaptLayout = BI.inherit(BI.Layout, {
|
||
|
|
||
|
props: function () {
|
||
|
return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), {
|
||
|
baseCls: "bi-inline-center-adapt-layout",
|
||
|
hgap: 0,
|
||
|
vgap: 0,
|
||
|
lgap: 0,
|
||
|
rgap: 0,
|
||
|
tgap: 0,
|
||
|
bgap: 0
|
||
|
});
|
||
|
},
|
||
|
|
||
|
render: function () {
|
||
|
BI.InlineCenterAdaptLayout.superclass.render.apply(this, arguments);
|
||
|
this.element.css({
|
||
|
whiteSpace: "nowrap"
|
||
|
});
|
||
|
this.populate(this.options.items);
|
||
|
},
|
||
|
|
||
|
_addElement: function (i, item, length) {
|
||
|
var o = this.options;
|
||
|
if (!this.hasWidget(this.getName() + i)) {
|
||
|
var t = BI.createWidget(item);
|
||
|
t.element.css({
|
||
|
position: "relative"
|
||
|
});
|
||
|
var w = BI.createWidget({
|
||
|
type: "bi.horizontal_auto",
|
||
|
items: [t]
|
||
|
});
|
||
|
this.addWidget(this.getName() + i, w);
|
||
|
} else {
|
||
|
var w = this.getWidgetByName(this.getName() + i);
|
||
|
}
|
||
|
w.element.css({
|
||
|
position: "relative",
|
||
|
display: "inline-block",
|
||
|
"vertical-align": "middle",
|
||
|
"*display": "inline",
|
||
|
"*zoom": 1,
|
||
|
"min-width": 100 / length + "%"
|
||
|
});
|
||
|
if (o.hgap + o.lgap + (item.lgap || 0) > 0) {
|
||
|
w.element.css({
|
||
|
"margin-left": o.hgap + o.lgap + (item.lgap || 0) + "px"
|
||
|
});
|
||
|
}
|
||
|
if (o.hgap + o.rgap + (item.rgap || 0) > 0) {
|
||
|
w.element.css({
|
||
|
"margin-right": o.hgap + o.rgap + (item.rgap || 0) + "px"
|
||
|
});
|
||
|
}
|
||
|
if (o.vgap + o.tgap + (item.tgap || 0) > 0) {
|
||
|
w.element.css({
|
||
|
"margin-top": o.vgap + o.tgap + (item.tgap || 0) + "px"
|
||
|
});
|
||
|
}
|
||
|
if (o.vgap + o.bgap + (item.bgap || 0) > 0) {
|
||
|
w.element.css({
|
||
|
"margin-bottom": o.vgap + o.bgap + (item.bgap || 0) + "px"
|
||
|
});
|
||
|
}
|
||
|
return w;
|
||
|
},
|
||
|
|
||
|
resize: function () {
|
||
|
this.stroke(this.options.items);
|
||
|
},
|
||
|
|
||
|
addItem: function (item) {
|
||
|
throw new Error("不能添加元素");
|
||
|
},
|
||
|
|
||
|
stroke: function (items) {
|
||
|
var self = this;
|
||
|
BI.each(items, function (i, item) {
|
||
|
if (item) {
|
||
|
self._addElement(i, item, items.length);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
populate: function (items) {
|
||
|
BI.InlineCenterAdaptLayout.superclass.populate.apply(this, arguments);
|
||
|
this._mount();
|
||
|
}
|
||
|
});
|
||
|
BI.shortcut("bi.inline_center_adapt", BI.InlineCenterAdaptLayout);
|