|
|
@ -1,3 +1,8 @@ |
|
|
|
|
|
|
|
(function () { |
|
|
|
|
|
|
|
function isVertical(position) { |
|
|
|
|
|
|
|
return position === "top" || position === "bottom"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文字类型的按钮 |
|
|
|
* 文字类型的按钮 |
|
|
|
* @class BI.Button |
|
|
|
* @class BI.Button |
|
|
@ -9,18 +14,20 @@ |
|
|
|
BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
|
|
|
|
|
|
|
|
_const: { |
|
|
|
_const: { |
|
|
|
iconWidth: 18 |
|
|
|
iconWidth: 16 |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_defaultConfig: function (props) { |
|
|
|
_defaultConfig: function (props) { |
|
|
|
var conf = BI.Button.superclass._defaultConfig.apply(this, arguments); |
|
|
|
var conf = BI.Button.superclass._defaultConfig.apply(this, arguments); |
|
|
|
|
|
|
|
|
|
|
|
return BI.extend(conf, { |
|
|
|
return BI.extend(conf, { |
|
|
|
baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""), |
|
|
|
baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""), |
|
|
|
attributes: { |
|
|
|
attributes: { |
|
|
|
tabIndex: 1 |
|
|
|
tabIndex: 1 |
|
|
|
}, |
|
|
|
}, |
|
|
|
minWidth: (props.block === true || props.clear === true) ? 0 : 80, |
|
|
|
minWidth: (props.block === true || props.clear === true) ? 0 : 80, |
|
|
|
height: 24, |
|
|
|
// 44 = 垂直间距 6 + 边框 2 + 图标 16 + 图标和文字间隔 8 + 文字 12
|
|
|
|
|
|
|
|
height: isVertical(props.iconPosition) ? 44 + ((props.iconGap || 8) - 8) : 24, |
|
|
|
shadow: props.clear !== true, |
|
|
|
shadow: props.clear !== true, |
|
|
|
isShadowShowingOnSelected: true, |
|
|
|
isShadowShowingOnSelected: true, |
|
|
|
readonly: true, |
|
|
|
readonly: true, |
|
|
@ -29,6 +36,7 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
block: false, // 是否块状显示,即不显示边框,没有最小宽度的限制
|
|
|
|
block: false, // 是否块状显示,即不显示边框,没有最小宽度的限制
|
|
|
|
clear: false, // 是否去掉边框和背景
|
|
|
|
clear: false, // 是否去掉边框和背景
|
|
|
|
ghost: false, // 是否幽灵显示, 即正常状态无背景
|
|
|
|
ghost: false, // 是否幽灵显示, 即正常状态无背景
|
|
|
|
|
|
|
|
loading: false, // 是否处于加载中
|
|
|
|
textAlign: "center", |
|
|
|
textAlign: "center", |
|
|
|
whiteSpace: "nowrap", |
|
|
|
whiteSpace: "nowrap", |
|
|
|
textWidth: null, |
|
|
|
textWidth: null, |
|
|
@ -38,21 +46,27 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
tgap: 0, |
|
|
|
tgap: 0, |
|
|
|
bgap: 0, |
|
|
|
bgap: 0, |
|
|
|
lgap: 0, |
|
|
|
lgap: 0, |
|
|
|
rgap: 0 |
|
|
|
rgap: 0, |
|
|
|
|
|
|
|
iconGap: 8, |
|
|
|
|
|
|
|
iconPosition: "left" |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
render: function () { |
|
|
|
render: function () { |
|
|
|
var o = this.options, self = this; |
|
|
|
var o = this.options; |
|
|
|
|
|
|
|
|
|
|
|
// 由于button默认情况下有个边框,所以要主动算行高
|
|
|
|
// 由于button默认情况下有个边框,所以要主动算行高
|
|
|
|
var lineHeight, textHeight = o.textHeight; |
|
|
|
var lineHeight, textHeight = o.textHeight; |
|
|
|
if (BI.isNumber(o.height)) { |
|
|
|
if (BI.isNumber(o.height)) { |
|
|
|
|
|
|
|
if (!isVertical(o.iconPosition)) { |
|
|
|
if (o.clear || o.block) { |
|
|
|
if (o.clear || o.block) { |
|
|
|
lineHeight = o.height; |
|
|
|
lineHeight = o.height; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
lineHeight = o.height - 2; |
|
|
|
lineHeight = o.height - 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lineHeight = textHeight; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!textHeight) { |
|
|
|
if (!textHeight) { |
|
|
|
if (o.whiteSpace === "nowrap") { |
|
|
|
if (o.whiteSpace === "nowrap") { |
|
|
@ -65,9 +79,7 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
cls: o.iconCls, |
|
|
|
cls: o.iconCls, |
|
|
|
width: this._const.iconWidth, |
|
|
|
width: this._const.iconWidth, |
|
|
|
height: lineHeight, |
|
|
|
height: lineHeight, |
|
|
|
lineHeight: lineHeight, |
|
|
|
lineHeight: lineHeight |
|
|
|
iconWidth: o.iconWidth, |
|
|
|
|
|
|
|
iconHeight: o.iconHeight |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
this.text = BI.createWidget({ |
|
|
|
this.text = BI.createWidget({ |
|
|
|
type: "bi.label", |
|
|
|
type: "bi.label", |
|
|
@ -77,15 +89,30 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
height: lineHeight, |
|
|
|
height: lineHeight, |
|
|
|
value: o.value |
|
|
|
value: o.value |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
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({ |
|
|
|
BI.createWidget({ |
|
|
|
type: "bi.center_adapt", |
|
|
|
type: "bi.center_adapt", |
|
|
|
element: this, |
|
|
|
element: this, |
|
|
|
hgap: o.hgap, |
|
|
|
hgap: o.hgap, |
|
|
|
vgap: o.vgap, |
|
|
|
vgap: o.vgap, |
|
|
|
items: [{ |
|
|
|
items: [{ |
|
|
|
type: "bi.horizontal", |
|
|
|
type: layoutType, |
|
|
|
columnSize: ["", "fill"], |
|
|
|
horizontalAlign: "center", |
|
|
|
items: [this.icon, this.text] |
|
|
|
verticalAlign: "middle", |
|
|
|
|
|
|
|
items: items |
|
|
|
}] |
|
|
|
}] |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -116,6 +143,9 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
if (o.ghost === true) { |
|
|
|
if (o.ghost === true) { |
|
|
|
this.element.addClass("ghost"); |
|
|
|
this.element.addClass("ghost"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (o.loading === true) { |
|
|
|
|
|
|
|
this.element.addClass("loading"); |
|
|
|
|
|
|
|
} |
|
|
|
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}); |
|
|
|
} |
|
|
|
} |
|
|
@ -137,6 +167,14 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setLoading: function (loading) { |
|
|
|
|
|
|
|
if(loading) { |
|
|
|
|
|
|
|
this.element.addClass("loading"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.element.removeClass("loading"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setText: function (text) { |
|
|
|
setText: function (text) { |
|
|
|
BI.Button.superclass.setText.apply(this, arguments); |
|
|
|
BI.Button.superclass.setText.apply(this, arguments); |
|
|
|
this.text.setText(text); |
|
|
|
this.text.setText(text); |
|
|
@ -167,3 +205,4 @@ BI.Button = BI.inherit(BI.BasicButton, { |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.shortcut("bi.button", BI.Button); |
|
|
|
BI.shortcut("bi.button", BI.Button); |
|
|
|
BI.Button.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.Button.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
}()); |
|
|
|