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.

149 lines
4.4 KiB

8 years ago
/**
* guy 表示一行数据通过position来定位位置的数据
* @class BI.Text
* @extends BI.Single
*/
BI.Text = BI.inherit(BI.Single, {
_defaultConfig: function () {
var conf = BI.Text.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text",
textAlign: "left",
whiteSpace: "normal",
lineHeight: null,
7 years ago
handler: null, // 如果传入handler,表示处理文字的点击事件,不是区域的
8 years ago
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
text: "",
py: "",
highLight: false
7 years ago
});
8 years ago
},
render: function () {
7 years ago
var self = this, o = this.options;
8 years ago
if (o.hgap + o.lgap > 0) {
7 years ago
this.element.css({
"padding-left": o.hgap + o.lgap + "px"
7 years ago
});
8 years ago
}
if (o.hgap + o.rgap > 0) {
7 years ago
this.element.css({
"padding-right": o.hgap + o.rgap + "px"
7 years ago
});
8 years ago
}
if (o.vgap + o.tgap > 0) {
7 years ago
this.element.css({
"padding-top": o.vgap + o.tgap + "px"
7 years ago
});
8 years ago
}
if (o.vgap + o.bgap > 0) {
7 years ago
this.element.css({
"padding-bottom": o.vgap + o.bgap + "px"
7 years ago
});
8 years ago
}
if (BI.isNumber(o.height)) {
7 years ago
this.element.css({lineHeight: o.height + "px"});
8 years ago
}
if (BI.isNumber(o.lineHeight)) {
7 years ago
this.element.css({lineHeight: o.lineHeight + "px"});
8 years ago
}
if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({maxWidth: o.maxWidth});
}
8 years ago
this.element.css({
7 years ago
textAlign: o.textAlign,
whiteSpace: o.whiteSpace,
textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "",
overflow: o.whiteSpace === "nowrap" ? "" : "auto"
8 years ago
});
7 years ago
if (o.handler) {
this.text = BI.createWidget({
type: "bi.layout",
7 years ago
tagName: "span"
7 years ago
});
this.text.element.click(function () {
o.handler(self.getValue());
});
BI.createWidget({
type: "bi.default",
element: this,
items: [this.text]
});
} else {
this.text = this;
}
6 years ago
var text = this._getShowText();
if (BI.isKey(text)) {
this.setText(text);
7 years ago
} else if (BI.isKey(o.value)) {
this.setText(o.value);
}
8 years ago
if (BI.isKey(o.keyword)) {
this.text.element.__textKeywordMarked__(text, o.keyword, o.py);
8 years ago
}
if (o.highLight) {
this.doHighLight();
}
8 years ago
},
_getShowText: function () {
var o = this.options;
return BI.isFunction(o.text) ? o.text() : o.text;
},
8 years ago
doRedMark: function (keyword) {
var o = this.options;
6 years ago
// render之后做的doredmark,这个时候虽然标红了,但是之后text mounted执行的时候并没有keyword
o.keyword = keyword;
this.text.element.__textKeywordMarked__(this._getShowText() || o.value, keyword, o.py);
8 years ago
},
unRedMark: function () {
var o = this.options;
o.keyword = "";
this.text.element.__textKeywordMarked__(this._getShowText() || o.value, "", o.py);
8 years ago
},
doHighLight: function () {
this.text.element.addClass("bi-high-light");
},
unHighLight: function () {
this.text.element.removeClass("bi-high-light");
},
setValue: function (text) {
BI.Text.superclass.setValue.apply(this, arguments);
if (!this.isReadOnly()) {
8 years ago
this.setText(text);
8 years ago
}
},
setStyle: function (css) {
7 years ago
this.text.element.css(css);
},
8 years ago
setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text;
if (BI.isIE9Below()) {
this.text.element.html(BI.htmlEncode(this._getShowText()));
return;
}
6 years ago
if (/\s/.test(text)) {
this.text.element[0].innerHTML = BI.htmlEncode(this._getShowText());
} else {
6 years ago
// textContent性能更好,并且原生防xss
this.text.element[0].textContent = this._getShowText();
}
8 years ago
}
});
8 years ago
BI.shortcut("bi.text", BI.Text);