Browse Source

增加一个纯文本组件

es6
guy 4 years ago
parent
commit
ebfe202efb
  1. 43
      src/base/single/text.pure.js
  2. 5
      src/core/widget.js

43
src/base/single/text.pure.js

@ -0,0 +1,43 @@
/**
* 没有html标签的纯文本
*/
!(function () {
BI.PureText = BI.inherit(BI.Widget, {
props: {
tagName: null
},
render: function () {
var self = this, o = this.options;
var text = this._getShowText();
if (BI.isKey(text)) {
this.setText(text);
} else if (BI.isKey(o.value)) {
this.setText(o.value);
}
},
_getShowText: function () {
var o = this.options;
var text = BI.isFunction(o.text) ? o.text() : o.text;
text = BI.isKey(text) ? text : o.value;
if (!BI.isKey(text)) {
return "";
}
return BI.Text.formatText(text + "");
},
setValue: function (value) {
this.options.value = value;
this.setText(value);
},
setText: function (text) {
this.options.text = BI.isNotNull(text) ? text : "";
this.text.element.__textKeywordMarked__(this._getShowText());
}
});
BI.shortcut("bi.pure_text", BI.PureText);
}());

5
src/core/widget.js

@ -610,7 +610,10 @@
if (o.element) {
return BI.$(o.element);
}
return BI.$(document.createElement(o.tagName));
if (o.tagName) {
return BI.$(document.createElement(o.tagName));
}
return BI.$(document.createDocumentFragment());
}
return BI.$(widget);
},

Loading…
Cancel
Save