Browse Source

Merging in latest from upstream (VISUAL/fineui:refs/heads/es6)

* commit '517df399d56c006bf4ccba858634bde6b1f6c304':
  KERNEL-13947 refactor: 处理继承OB对象的执行顺序问题
  KERNEL-13928 refactor: 去掉多余的引入
  KERNEL-13928 refactor: 修改解构赋值错误的地方
  KERNEL-13928 refactor: es6化1.text.js
  KERNEL-13928 refactor: es6化0.single.js
  KERNEL-13928 refactor: 重构一些用到的方法
es6
Joker.Wang-王顺 2 years ago
parent
commit
8a3b7d6dbd
  1. 54
      src/base/0.base.js
  2. 6
      src/base/index.js
  3. 220
      src/base/single/0.single.js
  4. 156
      src/base/single/1.text.js
  5. 6
      src/core/controller/controller.drawer.js
  6. 5
      src/core/controller/controller.layer.js
  7. 13
      src/core/controller/controller.popover.js
  8. 6
      src/core/controller/controller.tooltips.js
  9. 3
      src/core/index.js
  10. 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,
} }

220
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);

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

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

6
src/core/controller/controller.drawer.js

@ -6,13 +6,17 @@
*/ */
import Controller from "./0.controller"; import Controller from "./0.controller";
export default class DrawerController extends Controller { export default class DrawerController extends Controller {
constructor() {
super();
this._constructor();
this.modal = this.options.modal;
}
props = { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body"
} }
init() { init() {
this.modal = this.options.modal;
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
this.floatContainer = {}; this.floatContainer = {};

5
src/core/controller/controller.layer.js

@ -6,6 +6,11 @@
*/ */
import Controller from "./0.controller"; import Controller from "./0.controller";
export default class LayerController extends Controller { export default class LayerController extends Controller {
constructor() {
super();
this._constructor();
}
props = { props = {
render: "body" render: "body"
} }

13
src/core/controller/controller.popover.js

@ -6,13 +6,18 @@
*/ */
import Controller from "./0.controller"; import Controller from "./0.controller";
export default class PopoverController extends Controller { export default class PopoverController extends Controller {
constructor() {
super();
this._constructor();
this.modal = this.options.modal;
}
props = { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body"
} }
init() { init() {
this.modal = this.options.modal;
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
this.floatContainer = {}; this.floatContainer = {};
@ -50,7 +55,7 @@ export default class PopoverController extends Controller {
const W = BI.Widget._renderEngine.createElement(this.options.render).width(), const W = BI.Widget._renderEngine.createElement(this.options.render).width(),
H = BI.Widget._renderEngine.createElement(this.options.render).height(); H = BI.Widget._renderEngine.createElement(this.options.render).height();
const w = popover.element.width(), h = popover.element.height(); const w = popover.element.width(), h = popover.element.height();
const left = (W - w) / 2, top = (H - h) / 2; let left = (W - w) / 2, top = (H - h) / 2;
if (left < 0) { if (left < 0) {
left = 0; left = 0;
} }
@ -110,9 +115,7 @@ export default class PopoverController extends Controller {
}] }]
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
(function (key) { popover.on(BI.Popover.EVENT_CLOSE, () => this.close(name));
popover.on(BI.Popover.EVENT_CLOSE, () => self.close(key));
})(name);
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
element: options.container || this.options.render, element: options.container || this.options.render,

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"));
} }
if (!opt.belowMouse) {
const offset = context.element.offset(); const offset = context.element.offset();
let top;
if (!opt.belowMouse) {
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