Browse Source

Pull request #3287: KERNEL-13928 refactor: es6化0.single.js

Merge in VISUAL/fineui from ~IMPACT/fine_ui:es6 to es6

* commit 'a941b90118c0e27f6f54e4c1d927056836133a78':
  KERNEL-13928 refactor: 去掉多余的引入
  KERNEL-13928 refactor: 修改解构赋值错误的地方
  KERNEL-13928 refactor: es6化1.text.js
  KERNEL-13928 refactor: es6化0.single.js
  KERNEL-13928 refactor: 重构一些用到的方法
es6
Impact-吴家豪 2 years ago
parent
commit
052894228f
  1. 54
      src/base/0.base.js
  2. 6
      src/base/index.js
  3. 226
      src/base/single/0.single.js
  4. 330
      src/base/single/1.text.js
  5. 6
      src/core/controller/controller.tooltips.js
  6. 3
      src/core/index.js
  7. 34
      src/core/loader/loader.style.js

54
src/base/0.base.js

@ -1,9 +1,45 @@
BI.Resizers = new BI.ResizeController(); import {
BI.Layers = new BI.LayerController(); BroadcastController,
BI.Maskers = new BI.MaskersController(); BubblesController,
BI.Bubbles = new BI.BubblesController(); DrawerController,
BI.Tooltips = new BI.TooltipsController(); LayerController,
BI.Popovers = new BI.PopoverController(); MaskersController,
BI.Drawers = new BI.DrawerController(); PopoverController,
BI.Broadcasts = new BI.BroadcastController(); ResizeController,
BI.StyleLoaders = new BI.StyleLoaderManager(); TooltipsController,
StyleLoaderManager
} from "../core";
const Resizers = new ResizeController();
const Layers = new LayerController();
const Maskers = new MaskersController();
const Bubbles = new BubblesController();
const Tooltips = new TooltipsController();
const Popovers = new PopoverController();
const Drawers = new DrawerController();
const Broadcasts = new BroadcastController();
const StyleLoaders = new StyleLoaderManager();
BI.extend(BI, {
Resizers,
Layers,
Maskers,
Bubbles,
Tooltips,
Popovers,
Drawers,
Broadcasts,
StyleLoaders
});
export {
Resizers,
Layers,
Maskers,
Bubbles,
Tooltips,
Popovers,
Drawers,
Broadcasts,
StyleLoaders
};

6
src/base/index.js

@ -1,9 +1,15 @@
import Pane from "./1.pane"; import Pane from "./1.pane";
import Single from "./single/0.single";
import Text from "./single/1.text";
BI.extend(BI, { BI.extend(BI, {
Pane, Pane,
Single,
Text,
}); });
export { export {
Pane, Pane,
Single,
Text,
} }

226
src/base/single/0.single.js

@ -10,11 +10,15 @@
* @abstract * @abstract
*/ */
var delayingTooltips; import { Widget, shortcut } from "../../core";
import { Tooltips } from "../0.base";
BI.Single = BI.inherit(BI.Widget, { @shortcut()
_defaultConfig: function () { export default class Single extends Widget {
var conf = BI.Single.superclass._defaultConfig.apply(this, arguments); static xtype = "bi.single";
_defaultConfig() {
const conf = super._defaultConfig(arguments);
return BI.extend(conf, { return BI.extend(conf, {
readonly: false, readonly: false,
@ -24,13 +28,22 @@ BI.Single = BI.inherit(BI.Widget, {
belowMouse: false, // title是否跟随鼠标 belowMouse: false, // title是否跟随鼠标
enableHover: false, enableHover: false,
}); });
}, }
_showToolTip: function (e, opt) { _showToolTip(e, opt) {
opt || (opt = {}); opt || (opt = {});
var self = this; const { action } = this.options;
var o = this.options; const title = this.getTitle();
var title = this.getTitle();
const showToolTip = (tooltipOpt) => {
if (BI.isKey(tooltipOpt.text) && !Tooltips.has(this.getName())) {
Tooltips.show(e, this.getName(), tooltipOpt, this, opt);
if (action) {
BI.Actions.runAction(action, "hover", this.options, this);
}
BI.Actions.runGlobalAction("hover", this.options, this);
}
}
if (title instanceof Promise) { if (title instanceof Promise) {
this.requestingTitle = title; this.requestingTitle = title;
@ -42,47 +55,37 @@ BI.Single = BI.inherit(BI.Widget, {
showToolTip(this._getTooltipOptions(title)); showToolTip(this._getTooltipOptions(title));
} }
function showToolTip(tooltipOpt) { }
if (BI.isKey(tooltipOpt.text) && !BI.Tooltips.has(self.getName())) {
BI.Tooltips.show(e, self.getName(), tooltipOpt, self, opt);
if (o.action) {
BI.Actions.runAction(o.action, "hover", o, self);
}
BI.Actions.runGlobalAction("hover", o, self);
}
}
},
_hideTooltip: function () { _hideTooltip() {
var self = this; const tooltip = Tooltips.get(this.getName());
var tooltip = BI.Tooltips.get(this.getName());
if (BI.isNotNull(tooltip)) { if (BI.isNotNull(tooltip)) {
tooltip.element.fadeOut(200, function () { tooltip.element.fadeOut(200, () => {
BI.Tooltips.remove(self.getName()); Tooltips.remove(this.getName());
}); });
} }
}, }
_init: function () { _init() {
var self = this, o = this.options; const { value } = this.options;
o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { this.options.value = BI.isFunction(value) ? this.__watch(value, (context, newValue) => {
self.setValue(newValue); this.setValue(newValue);
}) : o.value; }) : value;
BI.Single.superclass._init.apply(this, arguments); super._init(arguments);
}, }
_mounted: function () { _mounted() {
var o = this.options; const { enableHover, title, warningTitle, belowMouse, container } = this.options;
if (o.enableHover || BI.isKey(o.title) || BI.isKey(o.warningTitle) if (enableHover || BI.isKey(title) || BI.isKey(warningTitle)
|| BI.isFunction(o.title) || BI.isFunction(o.warningTitle)) { || BI.isFunction(title) || BI.isFunction(warningTitle)) {
this.enableHover({ this.enableHover({
belowMouse: o.belowMouse, belowMouse,
container: o.container, container,
}); });
} }
}, }
_clearTimeOut: function () { _clearTimeOut() {
if (BI.isNotNull(this.showTimeout)) { if (BI.isNotNull(this.showTimeout)) {
clearTimeout(this.showTimeout); clearTimeout(this.showTimeout);
this.showTimeout = null; this.showTimeout = null;
@ -91,88 +94,88 @@ BI.Single = BI.inherit(BI.Widget, {
clearTimeout(this.hideTimeout); clearTimeout(this.hideTimeout);
this.hideTimeout = null; this.hideTimeout = null;
} }
}, }
_getTooltipOptions: function (title) { _getTooltipOptions(title) {
var o = this.options; const { tipType } = this.options;
var tooltipOpt = {}; let tooltipOpt = {};
if (BI.isPlainObject(title)) { if (BI.isPlainObject(title)) {
tooltipOpt = title; tooltipOpt = title;
} else { } else {
tooltipOpt.level = this.getTipType() || "success"; tooltipOpt.level = this.getTipType() || "success";
// 由于以前的用法,存在大量disabled:true搭配warningTitle的情况,所以这里做一个兼容,disabled:true的情况下,依然优先显示warningTitle,避免只设置了warningTitle而没有设置title的情况 // 由于以前的用法,存在大量disabled:true搭配warningTitle的情况,所以这里做一个兼容,disabled:true的情况下,依然优先显示warningTitle,避免只设置了warningTitle而没有设置title的情况
if (BI.isNull(o.tipType) && !this.isEnabled()) { if (BI.isNull(tipType) && !this.isEnabled()) {
tooltipOpt.text = (this.getWarningTitle() || title); tooltipOpt.text = (this.getWarningTitle() || title);
} else { } else {
tooltipOpt.text = tooltipOpt.level === "success" ? title : (this.getWarningTitle() || title); tooltipOpt.text = tooltipOpt.level === "success" ? title : (this.getWarningTitle() || title);
} }
} }
return tooltipOpt; return tooltipOpt;
}, }
enableHover: function (opt) { enableHover(opt) {
opt || (opt = {}); opt || (opt = {});
var self = this; let delayingTooltips;
if (!this._hoverBinded) { if (!this._hoverBinded) {
this.element.unbind("mouseenter.title").on("mouseenter.title", function (e) { this.element.unbind("mouseenter.title").on("mouseenter.title", (e) => {
self._e = e; this._e = e;
self.mouseOver = true; this.mouseOver = true;
if (self.getTipType() === "warning" || (BI.isKey(self.getWarningTitle()) && !self.isEnabled())) { if (this.getTipType() === "warning" || (BI.isKey(this.getWarningTitle()) && !this.isEnabled())) {
delayingTooltips = self.getName(); delayingTooltips = this.getName();
self.showTimeout = BI.delay(function () { this.showTimeout = BI.delay(() => {
if (BI.isNotNull(self.showTimeout) && delayingTooltips === self.getName()) { if (BI.isNotNull(this.showTimeout) && delayingTooltips === this.getName()) {
self._showToolTip(self._e || e, opt); this._showToolTip(this._e || e, opt);
} }
}, 200); }, 200);
} else if (self.getTipType() === "success" || self.isEnabled()) { } else if (this.getTipType() === "success" || this.isEnabled()) {
delayingTooltips = self.getName(); delayingTooltips = this.getName();
self.showTimeout = BI.delay(function () { this.showTimeout = BI.delay(() => {
if (BI.isNotNull(self.showTimeout) && delayingTooltips === self.getName()) { if (BI.isNotNull(this.showTimeout) && delayingTooltips === this.getName()) {
self._showToolTip(self._e || e, opt); this._showToolTip(this._e || e, opt);
} }
}, 500); }, 500);
} }
}); });
this.element.unbind("mousemove.title").on("mousemove.title", function (e) { this.element.unbind("mousemove.title").on("mousemove.title", (e) => {
self._e = e; this._e = e;
if (BI.isNotNull(self.showTimeout)) { if (BI.isNotNull(this.showTimeout)) {
clearTimeout(self.showTimeout); clearTimeout(this.showTimeout);
self.showTimeout = null; this.showTimeout = null;
} }
if (BI.isNull(self.hideTimeout)) { if (BI.isNull(this.hideTimeout)) {
self.hideTimeout = BI.delay(function () { this.hideTimeout = BI.delay(() => {
if (BI.isNotNull(self.hideTimeout)) { if (BI.isNotNull(this.hideTimeout)) {
self._hideTooltip(); this._hideTooltip();
} }
}, 500); }, 500);
} }
self.showTimeout = BI.delay(function () { this.showTimeout = BI.delay(() => {
// DEC-5321 IE下如果回调已经进入事件队列,clearTimeout将不会起作用 // DEC-5321 IE下如果回调已经进入事件队列,clearTimeout将不会起作用
if (BI.isNotNull(self.showTimeout)) { if (BI.isNotNull(this.showTimeout)) {
if (BI.isNotNull(self.hideTimeout)) { if (BI.isNotNull(this.hideTimeout)) {
clearTimeout(self.hideTimeout); clearTimeout(this.hideTimeout);
self.hideTimeout = null; this.hideTimeout = null;
} }
// CHART-10611 在拖拽的情况下, 鼠标拖拽着元素离开了拖拽元素的容器,但是子元素在dom结构上仍然属于容器 // CHART-10611 在拖拽的情况下, 鼠标拖拽着元素离开了拖拽元素的容器,但是子元素在dom结构上仍然属于容器
// 这样会认为鼠标仍然在容器中, 500ms内放开的话,会在容器之外显示鼠标停留处显示容器的title // 这样会认为鼠标仍然在容器中, 500ms内放开的话,会在容器之外显示鼠标停留处显示容器的title
if (self.element.__isMouseInBounds__(self._e || e)) { if (this.element.__isMouseInBounds__(this._e || e)) {
self._showToolTip(self._e || e, opt); this._showToolTip(this._e || e, opt);
} }
} }
}, 500); }, 500);
}); });
this.element.unbind("mouseleave.title").on("mouseleave.title", function (e) { this.element.unbind("mouseleave.title").on("mouseleave.title", (e) => {
self._e = null; this._e = null;
self.mouseOver = false; this.mouseOver = false;
self._clearTimeOut(); this._clearTimeOut();
self._hideTooltip(); this._hideTooltip();
}); });
this._hoverBinded = true; this._hoverBinded = true;
} }
}, }
disabledHover: function () { disabledHover() {
// 取消hover事件 // 取消hover事件
this._clearTimeOut(); this._clearTimeOut();
this._hideTooltip(); this._hideTooltip();
@ -180,74 +183,73 @@ BI.Single = BI.inherit(BI.Widget, {
.unbind("mousemove.title") .unbind("mousemove.title")
.unbind("mouseleave.title"); .unbind("mouseleave.title");
this._hoverBinded = false; this._hoverBinded = false;
}, }
// opt: {container: '', belowMouse: false} // opt: {container: '', belowMouse: false}
setTitle: function (title, opt) { setTitle(title, opt) {
this.options.title = title; this.options.title = title;
if (BI.isKey(title) || BI.isFunction(title)) { if (BI.isKey(title) || BI.isFunction(title)) {
this.enableHover(opt); this.enableHover(opt);
} else { } else {
this.disabledHover(); this.disabledHover();
} }
}, }
setWarningTitle: function (title, opt) { setWarningTitle(title, opt) {
this.options.warningTitle = title; this.options.warningTitle = title;
if (BI.isKey(title) || BI.isFunction(title)) { if (BI.isKey(title) || BI.isFunction(title)) {
this.enableHover(opt); this.enableHover(opt);
} else { } else {
this.disabledHover(); this.disabledHover();
} }
}, }
setTipType: function (type) { setTipType(type) {
this.options.tipType = type; this.options.tipType = type;
}, }
getTipType: function () { getTipType() {
return this.options.tipType; return this.options.tipType;
}, }
isReadOnly: function () { isReadOnly() {
return !!this.options.readonly; return !!this.options.readonly;
}, }
getTitle: function () { getTitle() {
var title = this.options.title; const title = this.options.title;
if (BI.isFunction(title)) { if (BI.isFunction(title)) {
return title(); return title();
} }
return title; return title;
}, }
getWarningTitle: function () { getWarningTitle() {
var title = this.options.warningTitle; const title = this.options.warningTitle;
if (BI.isFunction(title)) { if (BI.isFunction(title)) {
return title(); return title();
} }
return title; return title;
}, }
setValue: function (val) { setValue(val) {
if (!this.options.readonly) { if (!this.options.readonly) {
this.options.value = val; this.options.value = val;
this.options.setValue && this.options.setValue(val); this.options.setValue && this.options.setValue(val);
} }
}, }
getValue: function () { getValue() {
return this.options.value; return this.options.value;
}, }
_destroyed: function () { _destroyed() {
if (BI.isNotNull(this.showTimeout)) { if (BI.isNotNull(this.showTimeout)) {
clearTimeout(this.showTimeout); clearTimeout(this.showTimeout);
this.showTimeout = null; this.showTimeout = null;
} }
BI.Tooltips.remove(this.getName()); Tooltips.remove(this.getName());
}, }
}); }
BI.shortcut("bi.single", BI.Single);

330
src/base/single/1.text.js

@ -3,172 +3,174 @@
* @class BI.Text * @class BI.Text
* @extends BI.Single * @extends BI.Single
*/ */
!(function () { import { shortcut } from "../../core/decorator";
BI.Text = BI.inherit(BI.Single, { import { Single } from "../index";
props: { @shortcut()
baseCls: "bi-text", export default class Text extends Single {
textAlign: "left", static xtype = "bi.text";
whiteSpace: "normal",
lineHeight: null, props = {
handler: null, // 如果传入handler,表示处理文字的点击事件,不是区域的 baseCls: "bi-text",
hgap: 0, textAlign: "left",
vgap: 0, whiteSpace: "normal",
lgap: 0, lineHeight: null,
rgap: 0, handler: null, // 如果传入handler,表示处理文字的点击事件,不是区域的
tgap: 0, hgap: 0,
bgap: 0, vgap: 0,
py: "", lgap: 0,
highLight: false, rgap: 0,
}, tgap: 0,
bgap: 0,
render: function () { py: "",
var self = this, o = this.options; highLight: false,
if (o.hgap + o.lgap > 0) { }
this.element.css({
"padding-left": BI.pixFormat(o.hgap + o.lgap), render() {
}); const { vgap, hgap, lgap, rgap, tgap, bgap, height, lineHeight, maxWidth, textAlign, whiteSpace, handler, disabled, invalid, text: optionsText, value, keyword, highLight } = this.options;
} if (hgap + lgap > 0) {
if (o.hgap + o.rgap > 0) {
this.element.css({
"padding-right": BI.pixFormat(o.hgap + o.rgap),
});
}
if (o.vgap + o.tgap > 0) {
this.element.css({
"padding-top": BI.pixFormat(o.vgap + o.tgap),
});
}
if (o.vgap + o.bgap > 0) {
this.element.css({
"padding-bottom": BI.pixFormat(o.vgap + o.bgap),
});
}
if (BI.isWidthOrHeight(o.height)) {
this.element.css({ lineHeight: BI.pixFormat(o.height) });
}
if (BI.isWidthOrHeight(o.lineHeight)) {
this.element.css({ lineHeight: BI.pixFormat(o.lineHeight) });
}
if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({ maxWidth: BI.pixFormat(o.maxWidth) });
}
this.element.css({ this.element.css({
textAlign: o.textAlign, "padding-left": BI.pixFormat(hgap + lgap),
whiteSpace: this._getTextWrap(),
textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "",
overflow: o.whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(o.height) ? "auto" : ""),
}); });
if (o.handler && o.handler !== BI.emptyFn) {
this.text = BI.createWidget({
type: "bi.layout",
tagName: "span",
});
this.text.element.click(function (e) {
!o.disabled && !o.invalid && o.handler.call(self, self.getValue(), self, e);
});
BI.createWidget({
type: "bi.default",
element: this,
items: [this.text],
});
} else {
this.text = this;
}
var text = BI.isFunction(o.text) ? this.__watch(o.text, function (context, newValue) {
self.setText(newValue);
}) : o.text;
// 只要不是undefined就可以显示text值,否则显示value
if (!BI.isUndefined(text)) {
this.setText(text);
} else if (BI.isKey(o.value)) {
this.setText(o.value);
}
if (BI.isKey(o.keyword)) {
this.doRedMark(o.keyword);
}
if (o.highLight) {
this.doHighLight();
}
},
_getTextWrap: function () {
var o = this.options;
switch (o.whiteSpace) {
case "nowrap":
return "pre";
case "normal":
return "pre-wrap";
default:
return o.whiteSpace;
}
},
_getShowText: function () {
var o = this.options;
var text = BI.isFunction(o.text) ? o.text() : o.text;
return BI.isKey(text) ? BI.Text.formatText(text + "") : text;
},
_doRedMark: function (keyword) {
var o = this.options;
// render之后做的doRedMark,这个时候虽然标红了,但是之后text mounted执行的时候并没有keyword
o.keyword = keyword;
this.text.element.__textKeywordMarked__(this._getShowText(), keyword, o.py);
},
doRedMark: function (keyword) {
if (BI.isKey(keyword)) {
this._doRedMark(keyword);
}
},
unRedMark: function () {
var o = this.options;
o.keyword = "";
this.text.element.__textKeywordMarked__(this._getShowText(), "", o.py);
},
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()) {
this.setText(text);
}
},
setStyle: function (css) {
this.text.element.css(css);
},
setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text;
this._doRedMark(this.options.keyword);
},
});
var formatters = [];
BI.Text.addTextFormatter = function (formatter) {
formatters.push(formatter);
};
BI.Text.formatText = function (text) {
if (formatters.length > 0) {
for (var i = 0, len = formatters.length; i < len; i++) {
text = formatters[i](text);
}
} }
if (hgap + rgap > 0) {
this.element.css({
"padding-right": BI.pixFormat(hgap + rgap),
});
}
if (vgap + tgap > 0) {
this.element.css({
"padding-top": BI.pixFormat(vgap + tgap),
});
}
if (vgap + bgap > 0) {
this.element.css({
"padding-bottom": BI.pixFormat(vgap + bgap),
});
}
if (BI.isWidthOrHeight(height)) {
this.element.css({ lineHeight: BI.pixFormat(height) });
}
if (BI.isWidthOrHeight(lineHeight)) {
this.element.css({ lineHeight: BI.pixFormat(lineHeight) });
}
if (BI.isWidthOrHeight(maxWidth)) {
this.element.css({ maxWidth: BI.pixFormat(maxWidth) });
}
this.element.css({
textAlign: textAlign,
whiteSpace: this._getTextWrap(),
textOverflow: whiteSpace === "nowrap" ? "ellipsis" : "",
overflow: whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(height) ? "auto" : ""),
});
if (handler && handler !== BI.emptyFn) {
this.text = BI.createWidget({
type: "bi.layout",
tagName: "span",
});
this.text.element.click((e) => {
!disabled && !invalid && handler.call(this, this.getValue(), this, e);
});
BI.createWidget({
type: "bi.default",
element: this,
items: [this.text],
});
} else {
this.text = this;
}
const text = BI.isFunction(optionsText) ? this.__watch(optionsText, (context, newValue) => {
this.setText(newValue);
}) : optionsText;
// 只要不是undefined就可以显示text值,否则显示value
if (!BI.isUndefined(text)) {
this.setText(text);
} else if (BI.isKey(value)) {
this.setText(value);
}
if (BI.isKey(keyword)) {
this.doRedMark(keyword);
}
if (highLight) {
this.doHighLight();
}
}
_getTextWrap() {
const { whiteSpace } = this.options;
switch (whiteSpace) {
case "nowrap":
return "pre";
case "normal":
return "pre-wrap";
default:
return whiteSpace;
}
}
return text; _getShowText() {
}; const { text: optionsText } = this.options;
BI.shortcut("bi.text", BI.Text); const text = BI.isFunction(optionsText) ? optionsText() : optionsText;
}());
return BI.isKey(text) ? Text.formatText(text + "") : text;
}
_doRedMark(keyword) {
const { py } = this.options;
// render之后做的doRedMark,这个时候虽然标红了,但是之后text mounted执行的时候并没有keyword
this.options.keyword = keyword;
this.text.element.__textKeywordMarked__(this._getShowText(), keyword, py);
}
doRedMark(keyword) {
if (BI.isKey(keyword)) {
this._doRedMark(keyword);
}
}
unRedMark() {
const { py } = this.options;
this.options.keyword = "";
this.text.element.__textKeywordMarked__(this._getShowText(), "", py);
}
doHighLight() {
this.text.element.addClass("bi-high-light");
}
unHighLight() {
this.text.element.removeClass("bi-high-light");
}
setValue(text) {
super.setValue(text);
if (!this.isReadOnly()) {
this.setText(text);
}
}
setStyle(css) {
this.text.element.css(css);
}
setText(text) {
super.setText(text);
this.options.text = text;
this._doRedMark(this.options.keyword);
}
}
const formatters = [];
Text.addTextFormatter = (formatter) => {
formatters.push(formatter);
};
Text.formatText = (text) => {
if (formatters.length > 0) {
for (let i = 0; i < formatters.length; i++) {
text = formatters[i](text);
}
}
return text;
};

6
src/core/controller/controller.tooltips.js

@ -38,13 +38,15 @@ export default class TooltipsController extends Controller {
if (!this.has(name)) { if (!this.has(name)) {
this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body")); this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body"));
} }
const offset = context.element.offset();
let top;
if (!opt.belowMouse) { if (!opt.belowMouse) {
const offset = context.element.offset();
const bounds = context.element.bounds(); const bounds = context.element.bounds();
if (bounds.height === 0 || bounds.width === 0) { if (bounds.height === 0 || bounds.width === 0) {
return; return;
} }
const top = offset.top + bounds.height + 5; top = offset.top + bounds.height + 5;
} }
const tooltip = this.get(name); const tooltip = this.get(name);
tooltip.element.css({ tooltip.element.css({

3
src/core/index.js

@ -15,6 +15,7 @@ import MaskersController from "./controller/controller.masker";
import PopoverController from "./controller/controller.popover"; import PopoverController from "./controller/controller.popover";
import ResizeController from "./controller/controller.resizer"; import ResizeController from "./controller/controller.resizer";
import TooltipsController from "./controller/controller.tooltips"; import TooltipsController from "./controller/controller.tooltips";
import StyleLoaderManager from "./loader/loader.style";
BI.extend(BI, { BI.extend(BI, {
OB, OB,
@ -33,6 +34,7 @@ BI.extend(BI, {
PopoverController, PopoverController,
ResizeController, ResizeController,
TooltipsController, TooltipsController,
StyleLoaderManager,
}); });
export { export {
@ -53,4 +55,5 @@ export {
PopoverController, PopoverController,
ResizeController, ResizeController,
TooltipsController, TooltipsController,
StyleLoaderManager,
} }

34
src/core/loader/loader.style.js

@ -4,21 +4,23 @@
* Created by GUY on 2015/9/7. * Created by GUY on 2015/9/7.
* @class * @class
*/ */
BI.StyleLoaderManager = BI.inherit(BI.OB, { import OB from "../3.ob";
_defaultConfig: function () {
return BI.extend(BI.StyleLoaderManager.superclass._defaultConfig.apply(this, arguments), {});
},
_init: function () { export default class StyleLoaderManager extends OB {
BI.StyleLoaderManager.superclass._init.apply(this, arguments); _defaultConfig() {
return BI.extend(super._defaultConfig(arguments), {});
}
_init() {
super._init(arguments);
this.stylesManager = {}; this.stylesManager = {};
}, }
loadStyle: function (name, styleString) { loadStyle(name, styleString) {
if(!_global.document) { if(!_global.document) {
return; return;
} }
var d = document, styles = d.createElement("style"); const d = document, styles = d.createElement("style");
d.getElementsByTagName("head")[0].appendChild(styles); d.getElementsByTagName("head")[0].appendChild(styles);
styles.setAttribute("type", "text/css"); styles.setAttribute("type", "text/css");
if (styles.styleSheet) { if (styles.styleSheet) {
@ -29,17 +31,17 @@ BI.StyleLoaderManager = BI.inherit(BI.OB, {
this.stylesManager[name] = styles; this.stylesManager[name] = styles;
return this; return this;
}, }
get: function (name) { get(name) {
return this.stylesManager[name]; return this.stylesManager[name];
}, }
has: function (name) { has(name) {
return this.stylesManager[name] != null; return this.stylesManager[name] != null;
}, }
removeStyle: function (name) { removeStyle(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -47,4 +49,4 @@ BI.StyleLoaderManager = BI.inherit(BI.OB, {
delete this.stylesManager[name]; delete this.stylesManager[name];
return this; return this;
} }
}); }

Loading…
Cancel
Save