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.

171 lines
5.3 KiB

8 years ago
/**
* guy 表示一行数据通过position来定位位置的数据
* @class BI.Text
* @extends BI.Single
*/
4 years ago
!(function () {
BI.Text = BI.inherit(BI.Single, {
4 years ago
props: {
baseCls: "bi-text",
textAlign: "left",
whiteSpace: "normal",
lineHeight: null,
handler: null, // 如果传入handler,表示处理文字的点击事件,不是区域的
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
py: "",
highLight: false
},
8 years ago
4 years ago
render: function () {
var self = this, o = this.options;
if (o.hgap + o.lgap > 0) {
this.element.css({
"padding-left": o.hgap + o.lgap + "px"
});
}
if (o.hgap + o.rgap > 0) {
this.element.css({
"padding-right": o.hgap + o.rgap + "px"
});
}
if (o.vgap + o.tgap > 0) {
this.element.css({
"padding-top": o.vgap + o.tgap + "px"
});
}
if (o.vgap + o.bgap > 0) {
this.element.css({
"padding-bottom": o.vgap + o.bgap + "px"
});
}
if (BI.isNumber(o.height)) {
this.element.css({lineHeight: o.height + "px"});
}
if (BI.isNumber(o.lineHeight)) {
this.element.css({lineHeight: o.lineHeight + "px"});
}
if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({maxWidth: o.maxWidth});
}
7 years ago
this.element.css({
4 years ago
textAlign: o.textAlign,
whiteSpace: this._getTextWrap(),
textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "",
overflow: o.whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(o.height) ? "auto" : "")
7 years ago
});
4 years ago
if (o.handler && o.handler !== BI.emptyFn) {
this.text = BI.createWidget({
type: "bi.layout",
tagName: "span"
});
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
4 years ago
var text = this._getShowText();
if (!BI.isUndefined(text)) {
4 years ago
this.setText(text);
} else if (BI.isKey(o.value)) {
this.setText(o.value);
4 years ago
}
if (BI.isKey(o.keyword)) {
this.doRedMark(o.keyword);
}
if (o.highLight) {
this.doHighLight();
}
},
8 years ago
4 years ago
_getTextWrap: function () {
var o = this.options;
switch (o.whiteSpace) {
case "nowrap":
return "pre";
case "normal":
default:
return "pre-wrap";
}
},
5 years ago
4 years ago
_getShowText: function () {
var o = this.options;
4 years ago
var text = BI.isFunction(o.text) ? o.text() : o.text;
return BI.isKey(text) ? BI.Text.formatText(text + "") : text;
4 years ago
},
4 years ago
_doRedMark: function (keyword) {
4 years ago
var o = this.options;
// render之后做的doredmark,这个时候虽然标红了,但是之后text mounted执行的时候并没有keyword
o.keyword = keyword;
4 years ago
this.text.element.__textKeywordMarked__(this._getShowText(), keyword, o.py);
4 years ago
},
8 years ago
4 years ago
doRedMark: function (keyword) {
4 years ago
if (BI.isKey(keyword)) {
this._doRedMark(keyword);
4 years ago
}
},
4 years ago
unRedMark: function () {
var o = this.options;
o.keyword = "";
4 years ago
this.text.element.__textKeywordMarked__(this._getShowText(), "", o.py);
4 years ago
},
8 years ago
4 years ago
doHighLight: function () {
this.text.element.addClass("bi-high-light");
},
8 years ago
4 years ago
unHighLight: function () {
this.text.element.removeClass("bi-high-light");
},
8 years ago
4 years ago
setValue: function (text) {
BI.Text.superclass.setValue.apply(this, arguments);
if (!this.isReadOnly()) {
this.setText(text);
}
},
8 years ago
4 years ago
setStyle: function (css) {
this.text.element.css(css);
},
4 years ago
setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments);
// 为textContext赋值为undefined时在ie和edge下会真的显示undefined
this.options.text = BI.isNotNull(text) ? text : "";
4 years ago
this._doRedMark(this.options.keyword);
4 years ago
}
});
var formatters = [];
BI.Text.addTextFormatter = function (formatter) {
formatters.push(formatter);
};
BI.Text.formatText = function (text) {
4 years ago
if (formatters.length > 0) {
for (var i = 0, len = formatters.length; i < len; i++) {
text = formatters[i](text);
}
}
4 years ago
return text;
};
BI.shortcut("bi.text", BI.Text);
}());