|
|
@ -3,6 +3,8 @@ |
|
|
|
return position === "top" || position === "bottom"; |
|
|
|
return position === "top" || position === "bottom"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var loadingCls = "button-loading-font anim-rotate"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文字类型的按钮 |
|
|
|
* 文字类型的按钮 |
|
|
|
* @class BI.Button |
|
|
|
* @class BI.Button |
|
|
@ -54,7 +56,7 @@ |
|
|
|
whiteSpace: "nowrap", |
|
|
|
whiteSpace: "nowrap", |
|
|
|
textWidth: null, |
|
|
|
textWidth: null, |
|
|
|
textHeight: null, |
|
|
|
textHeight: null, |
|
|
|
hgap: props.clear ? 0 : 10, |
|
|
|
hgap: props.clear ? 0 : (props.plain && !props.text ? 4 : 10), |
|
|
|
vgap: 0, |
|
|
|
vgap: 0, |
|
|
|
tgap: 0, |
|
|
|
tgap: 0, |
|
|
|
bgap: 0, |
|
|
|
bgap: 0, |
|
|
@ -86,71 +88,64 @@ |
|
|
|
textHeight = lineHeight; |
|
|
|
textHeight = lineHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.isKey(o.iconCls)) { |
|
|
|
|
|
|
|
this.icon = BI.createWidget({ |
|
|
|
var iconInvisible = !o.loading && !o.iconCls; |
|
|
|
type: "bi.icon_label", |
|
|
|
this.icon = BI.createWidget({ |
|
|
|
cls: o.iconCls, |
|
|
|
type: "bi.icon_label", |
|
|
|
width: this._const.iconWidth, |
|
|
|
cls: o.loading ? loadingCls : o.iconCls, |
|
|
|
height: lineHeight, |
|
|
|
width: this._const.iconWidth, |
|
|
|
lineHeight: lineHeight, |
|
|
|
height: lineHeight, |
|
|
|
// 不设置,自定义按钮无法居中
|
|
|
|
lineHeight: lineHeight, |
|
|
|
iconWidth: o.iconWidth, |
|
|
|
// 不设置,自定义按钮无法居中
|
|
|
|
iconHeight: o.iconHeight |
|
|
|
iconWidth: o.iconWidth, |
|
|
|
}); |
|
|
|
iconHeight: o.iconHeight, |
|
|
|
this.text = BI.createWidget({ |
|
|
|
invisible: iconInvisible |
|
|
|
type: "bi.label", |
|
|
|
}); |
|
|
|
text: o.text, |
|
|
|
// 用于 whiteSpace
|
|
|
|
textWidth: BI.isNotNull(o.textWidth) ? o.textWidth - this._const.iconWidth : null, |
|
|
|
var textWidth = iconInvisible && o.width ? o.width - o.hgap * 2 : null; |
|
|
|
textHeight: textHeight, |
|
|
|
if (BI.isNotNull(o.textWidth)) { |
|
|
|
height: lineHeight, |
|
|
|
// textWidth 需要减去图标
|
|
|
|
value: o.value |
|
|
|
textWidth = o.textWidth - (iconInvisible || isVertical(o.iconPosition) ? 0 : this._const.iconWidth); |
|
|
|
}); |
|
|
|
|
|
|
|
var layoutType = "bi.horizontal"; |
|
|
|
|
|
|
|
var gapContainer = { |
|
|
|
|
|
|
|
lgap: o.iconPosition === "left" && o.text ? o.iconGap : 0, |
|
|
|
|
|
|
|
rgap: o.iconPosition === "right" ? o.iconGap : 0, |
|
|
|
|
|
|
|
tgap: o.iconPosition === "top" ? o.iconGap : 0, |
|
|
|
|
|
|
|
bgap: o.iconPosition === "bottom" ? o.iconGap : 0 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var items = [this.icon, BI.extend({ el: this.text }, gapContainer)]; |
|
|
|
|
|
|
|
if (isVertical(o.iconPosition)) { |
|
|
|
|
|
|
|
layoutType = "bi.vertical"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (o.iconPosition === "right" || o.iconPosition === "bottom") { |
|
|
|
|
|
|
|
items = [BI.extend({ el: this.text }, gapContainer), this.icon]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BI.createWidget({ |
|
|
|
|
|
|
|
type: "bi.center_adapt", |
|
|
|
|
|
|
|
element: this, |
|
|
|
|
|
|
|
hgap: o.hgap, |
|
|
|
|
|
|
|
vgap: o.vgap, |
|
|
|
|
|
|
|
items: [{ |
|
|
|
|
|
|
|
type: layoutType, |
|
|
|
|
|
|
|
horizontalAlign: "center", |
|
|
|
|
|
|
|
verticalAlign: "middle", |
|
|
|
|
|
|
|
items: items |
|
|
|
|
|
|
|
}] |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.text = BI.createWidget({ |
|
|
|
|
|
|
|
type: "bi.label", |
|
|
|
|
|
|
|
height: o.height, |
|
|
|
|
|
|
|
textAlign: o.textAlign, |
|
|
|
|
|
|
|
whiteSpace: o.whiteSpace, |
|
|
|
|
|
|
|
textWidth: o.textWidth, |
|
|
|
|
|
|
|
textHeight: textHeight, |
|
|
|
|
|
|
|
hgap: o.hgap, |
|
|
|
|
|
|
|
vgap: o.vgap, |
|
|
|
|
|
|
|
tgap: o.tgap, |
|
|
|
|
|
|
|
bgap: o.bgap, |
|
|
|
|
|
|
|
lgap: o.lgap, |
|
|
|
|
|
|
|
rgap: o.rgap, |
|
|
|
|
|
|
|
element: this, |
|
|
|
|
|
|
|
text: o.text, |
|
|
|
|
|
|
|
value: o.value, |
|
|
|
|
|
|
|
title: null, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.text = BI.createWidget({ |
|
|
|
|
|
|
|
type: "bi.label", |
|
|
|
|
|
|
|
text: o.text, |
|
|
|
|
|
|
|
whiteSpace: o.whiteSpace, |
|
|
|
|
|
|
|
textAlign: o.textAlign, |
|
|
|
|
|
|
|
textWidth: textWidth, |
|
|
|
|
|
|
|
textHeight: textHeight, |
|
|
|
|
|
|
|
height: lineHeight, |
|
|
|
|
|
|
|
value: o.value, |
|
|
|
|
|
|
|
title: null |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
var layoutType = "bi.horizontal"; |
|
|
|
|
|
|
|
var gapContainer = { |
|
|
|
|
|
|
|
lgap: o.iconPosition === "left" && o.text ? o.iconGap : 0, |
|
|
|
|
|
|
|
rgap: o.iconPosition === "right" ? o.iconGap : 0, |
|
|
|
|
|
|
|
tgap: o.iconPosition === "top" ? o.iconGap : 0, |
|
|
|
|
|
|
|
bgap: o.iconPosition === "bottom" ? o.iconGap : 0 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var items = [this.icon, BI.extend({el: this.text}, gapContainer)]; |
|
|
|
|
|
|
|
if (isVertical(o.iconPosition)) { |
|
|
|
|
|
|
|
layoutType = "bi.vertical"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (o.iconPosition === "right" || o.iconPosition === "bottom") { |
|
|
|
|
|
|
|
items = [BI.extend({el: this.text}, gapContainer), this.icon]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// bi.center_adapt 作用:让 hgap 不影响 iconGap。
|
|
|
|
|
|
|
|
BI.createWidget({ |
|
|
|
|
|
|
|
type: "bi.center_adapt", |
|
|
|
|
|
|
|
element: this, |
|
|
|
|
|
|
|
hgap: o.hgap, |
|
|
|
|
|
|
|
vgap: o.vgap, |
|
|
|
|
|
|
|
items: [{ |
|
|
|
|
|
|
|
type: layoutType, |
|
|
|
|
|
|
|
horizontalAlign: "center", |
|
|
|
|
|
|
|
verticalAlign: "middle", |
|
|
|
|
|
|
|
items: items |
|
|
|
|
|
|
|
}] |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var classArr = ["block", "clear", "ghost", "plain", "loading", "light"]; |
|
|
|
var classArr = ["block", "clear", "ghost", "plain", "loading", "light"]; |
|
|
|
// 如果 options 对应的属性为 true 则给元素添加 class
|
|
|
|
// 如果 options 对应的属性为 true 则给元素添加 class
|
|
|
|
BI.each(classArr, function (_, clz) { |
|
|
|
BI.each(classArr, function (_, clz) { |
|
|
@ -160,7 +155,7 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (o.minWidth > 0) { |
|
|
|
if (o.minWidth > 0) { |
|
|
|
this.element.css({ "min-width": o.minWidth / BI.pixRatio + BI.pixUnit }); |
|
|
|
this.element.css({"min-width": o.minWidth / BI.pixRatio + BI.pixUnit}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -180,12 +175,27 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beforeClick: function () { |
|
|
|
|
|
|
|
return this.isLoading(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isLoading() { |
|
|
|
|
|
|
|
return this._loading === undefined ? this.options.loading : this._loading; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setLoading: function (loading) { |
|
|
|
setLoading: function (loading) { |
|
|
|
if (loading) { |
|
|
|
this._loading = true; |
|
|
|
this.element.addClass("loading"); |
|
|
|
this.element.addClass("loading"); |
|
|
|
} else { |
|
|
|
// loadingCls 可以覆盖 iconCls 所以不需要移除 iconCls
|
|
|
|
this.element.removeClass("loading"); |
|
|
|
this.icon.element.addClass(loadingCls); |
|
|
|
} |
|
|
|
this.icon.setVisible(true); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setLoaded() { |
|
|
|
|
|
|
|
this._loading = false; |
|
|
|
|
|
|
|
this.element.removeClass("loading"); |
|
|
|
|
|
|
|
this.icon.element.removeClass(loadingCls); |
|
|
|
|
|
|
|
this.icon.setVisible(!!this.options.iconCls); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setText: function (text) { |
|
|
|
setText: function (text) { |
|
|
|