Browse Source

Fixed merge conflict

es6
Zhenfei.Li-李振飞 2 years ago
parent
commit
0890d11ff0
  1. 2
      .eslintrc
  2. 54
      src/base/0.base.js
  3. 88
      src/base/1.pane.js
  4. 15
      src/base/index.js
  5. 226
      src/base/single/0.single.js
  6. 330
      src/base/single/1.text.js
  7. 2359
      src/core/2.base.js
  8. 397
      src/core/3.ob.js
  9. 1889
      src/core/4.widget.js
  10. 21
      src/core/action/action.js
  11. 11
      src/core/action/action.show.js
  12. 16
      src/core/behavior/0.behavior.js
  13. 11
      src/core/behavior/behavior.highlight.js
  14. 9
      src/core/behavior/behavior.redmark.js
  15. 7
      src/core/controller/0.controller.js
  16. 35
      src/core/controller/controller.broadcast.js
  17. 49
      src/core/controller/controller.bubbles.js
  18. 95
      src/core/controller/controller.drawer.js
  19. 89
      src/core/controller/controller.layer.js
  20. 9
      src/core/controller/controller.masker.js
  21. 96
      src/core/controller/controller.popover.js
  22. 41
      src/core/controller/controller.resizer.js
  23. 76
      src/core/controller/controller.tooltips.js
  24. 8
      src/core/decorator.js
  25. 59
      src/core/index.js
  26. 34
      src/core/loader/loader.style.js
  27. 3
      tsconfig.json

2
.eslintrc

@ -27,7 +27,7 @@
"plugins": ["@typescript-eslint/eslint-plugin"], "plugins": ["@typescript-eslint/eslint-plugin"],
"overrides": [{ "overrides": [{
"files": ["src/*.js","src/**/*.js", "demo/*.js", "demo/**/*.js", "i18n/**/*.js", "i18n/*.js", "test/**/*.js", "test/*.js", "examples/*.js", "examples/**/*.js"], "files": ["src/*.js","src/**/*.js", "demo/*.js", "demo/**/*.js", "i18n/**/*.js", "i18n/*.js", "test/**/*.js", "test/*.js", "examples/*.js", "examples/**/*.js"],
"extends": "plugin:@fui/es5", "extends": "plugin:@fui/es6",
"rules": { "rules": {
"no-param-reassign": "off", "no-param-reassign": "off",
"quotes": [2, "double"], "quotes": [2, "double"],

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
};

88
src/base/1.pane.js

@ -6,10 +6,16 @@
* @extends BI.Widget * @extends BI.Widget
* @abstract * @abstract
*/ */
BI.Pane = BI.inherit(BI.Widget, { import { Widget, shortcut } from "../core";
_defaultConfig: function () { @shortcut()
return BI.extend(BI.Pane.superclass._defaultConfig.apply(this, arguments), { export default class Pane extends Widget {
static xtype = "bi.pane";
static EVENT_LOADED = "EVENT_LOADED";
static EVENT_LOADING = "EVENT_LOADING";
_defaultConfig() {
return BI.extend(super._defaultConfig(), {
_baseCls: "bi-pane", _baseCls: "bi-pane",
tipText: BI.i18nText("BI-No_Selected_Item"), tipText: BI.i18nText("BI-No_Selected_Item"),
loadingText: "", loadingText: "",
@ -17,30 +23,29 @@ BI.Pane = BI.inherit(BI.Widget, {
overlap: true, overlap: true,
onLoaded: BI.emptyFn, onLoaded: BI.emptyFn,
}); });
}, }
_assertTip: function () { _assertTip() {
var self = this, o = this.options;
if (!this._tipText) { if (!this._tipText) {
BI.createWidget({ BI.createWidget({
type: "bi.absolute_center_adapt", type: "bi.absolute_center_adapt",
element: this, element: this,
items: [{ items: [{
type: "bi.label", type: "bi.label",
ref: function (_ref) { ref: (_ref) => {
self._tipText = _ref; this._tipText = _ref;
}, },
cls: "bi-tips", cls: "bi-tips",
text: o.tipText, text: this.options.tipText,
height: 25, height: 25,
}], }],
}); });
} }
}, }
loading: function () { loading() {
var self = this, o = this.options; const o = this.options;
var loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({ const loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({
loadingSize: o.loadingSize, loadingSize: o.loadingSize,
context: this, context: this,
})); }));
@ -56,7 +61,7 @@ BI.Pane = BI.inherit(BI.Widget, {
element: BI.Layers.make(this.getName() + "-loading", this), element: BI.Layers.make(this.getName() + "-loading", this),
}); });
} }
BI.Layers.show(self.getName() + "-loading"); BI.Layers.show(this.getName() + "-loading");
} else if (BI.isNull(this._loading)) { } else if (BI.isNull(this._loading)) {
loadingAnimation.element.css("zIndex", 1); loadingAnimation.element.css("zIndex", 1);
BI.createWidget({ BI.createWidget({
@ -66,17 +71,17 @@ BI.Pane = BI.inherit(BI.Widget, {
items: this._getLoadingTipItems(loadingAnimation), items: this._getLoadingTipItems(loadingAnimation),
}); });
} }
self.fireEvent(BI.Pane.EVENT_LOADING); this.fireEvent(Pane.EVENT_LOADING);
this.element.addClass("loading-status"); this.element.addClass("loading-status");
}, }
_getSize: function (v) { _getSize(v) {
return Math.ceil(v / (this.options.loadingSize === "small" ? 2 : 1)); return Math.ceil(v / (this.options.loadingSize === "small" ? 2 : 1));
}, }
_getLoadingTipItems: function (loadingTip) { _getLoadingTipItems(loadingTip) {
var self = this, o = this.options; const o = this.options;
var loadingTipItems = [{ const loadingTipItems = [{
type: "bi.horizontal_adapt", type: "bi.horizontal_adapt",
items: [loadingTip], items: [loadingTip],
}]; }];
@ -88,46 +93,41 @@ BI.Pane = BI.inherit(BI.Widget, {
return [{ return [{
type: "bi.vertical", type: "bi.vertical",
ref: function (_ref) { ref: (_ref) => {
self._loading = _ref; this._loading = _ref;
}, },
items: loadingTipItems, items: loadingTipItems,
}]; }];
}, }
loaded: function () { loaded() {
var self = this, o = this.options; BI.Layers.remove(this.getName() + "-loading");
BI.Layers.remove(self.getName() + "-loading");
this._loading && this._loading.destroy(); this._loading && this._loading.destroy();
o.onLoaded(); this.options.onLoaded();
self.fireEvent(BI.Pane.EVENT_LOADED); this.fireEvent(Pane.EVENT_LOADED);
this.element.removeClass("loading-status"); this.element.removeClass("loading-status");
}, }
check: function () { check() {
this.setTipVisible(BI.isEmpty(this.options.items)); this.setTipVisible(BI.isEmpty(this.options.items));
}, }
setTipVisible: function (b) { setTipVisible(b) {
if (b === true) { if (b === true) {
this._assertTip(); this._assertTip();
this._tipText && this._tipText.setVisible(true); this._tipText && this._tipText.setVisible(true);
} else { } else {
this._tipText && this._tipText.setVisible(false); this._tipText && this._tipText.setVisible(false);
} }
}, }
setTipText: function (text) { setTipText(text) {
this._assertTip(); this._assertTip();
this._tipText.setText(text); this._tipText.setText(text);
}, }
populate: function (items) { populate(items) {
this.options.items = items || []; this.options.items = items || [];
this.check(); this.check();
}, }
}); }
BI.Pane.EVENT_LOADED = "EVENT_LOADED";
BI.Pane.EVENT_LOADING = "EVENT_LOADING";
BI.shortcut("bi.pane", BI.Pane);

15
src/base/index.js

@ -0,0 +1,15 @@
import Pane from "./1.pane";
import Single from "./single/0.single";
import Text from "./single/1.text";
BI.extend(BI, {
Pane,
Single,
Text,
});
export {
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;
};

2359
src/core/2.base.js

File diff suppressed because it is too large Load Diff

397
src/core/3.ob.js

@ -1,220 +1,221 @@
!(function () { import BI from "./2.base";
function extend() {
var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy; function extend() {
for (; i < length; i++) { let target = arguments[0] || {}, length = arguments.length, i = 1, name, copy;
// Only deal with non-null/undefined values for (; i < length; i++) {
if ((options = arguments[i]) != null) { // Only deal with non-null/undefined values
// Extend the base object const options = arguments[i];
for (name in options) { if (options !== null) {
src = target[name]; // Extend the base object
copy = options[name]; for (name in options) {
copy = options[name];
// Prevent never-ending loop
if (target === copy) { // Prevent never-ending loop
continue; if (target === copy) {
} continue;
}
if (copy !== undefined) {
target[name] = copy; if (copy !== undefined) {
} target[name] = copy;
} }
} }
} }
return target;
} }
/** return target;
* 客户端观察者主要处理事件的添加删除执行等 }
* @class BI.OB
* @abstract
*/
var OB = function (config) {
this._constructor(config);
};
BI._.extend(OB.prototype, {
props: {},
init: null, export default class OB {
// props = {};
destroyed: null, // init = null;
_constructor: function (config) { // destroyed = null;
this._initProps(config);
this._init();
this._initRef();
},
_defaultConfig: function (config) { constructor(config) {
return {}; this._constructor(config);
}, }
_constructor(config) {
this._initProps(config);
this._init();
this._initRef();
}
_initProps: function (config) { _defaultConfig(config) {
var props = this.props; return {};
if (BI.isFunction(this.props)) { }
props = this.props(config);
}
var defaultProps = extend(this._defaultConfig(config), props);
var modifiedDefaultProps = (config && config.type && BI.OB.configFunctions[config.type + ".props"]) ? BI.reduce(BI.OB.configFunctions[config.type + ".props"], function (value, conf, index) {
return extend(conf, value.fn(defaultProps, config, value.opt));
}, {}) : null;
this.options = extend(defaultProps, modifiedDefaultProps, config);
},
_init: function () {
this._initListeners();
this.init && this.init();
},
_initListeners: function () {
var self = this;
if (this.options.listeners != null) {
BI._.each(this.options.listeners, function (lis, eventName) {
if (BI._.isFunction(lis)) {
self.on(eventName, lis);
return;
}
if (BI._.isArray(lis)) {
BI._.each(lis, function (l) {
self.on(eventName, l);
});
return;
}
(lis.target ? lis.target : self)[lis.once ? "once" : "on"](lis.eventName, BI._.bind(lis.action, self));
});
delete this.options.listeners;
}
},
// 获得一个当前对象的引用 _initProps(config) {
_initRef: function () { let props = this.props;
var o = this.options; if (BI.isFunction(this.props)) {
if (o.__ref) { props = this.props(config);
BI.isFunction(o.__ref) ? o.__ref.call(this, this) : o.__ref.current = this; }
} const defaultProps = extend(this._defaultConfig(config), props);
if (o.ref) { const modifiedDefaultProps = (config && config.type && OB.configFunctions[config.type + ".props"]) ? BI.reduce(OB.configFunctions[config.type + ".props"], function (value, conf, index) {
BI.isFunction(o.ref) ? o.ref.call(this, this) : o.ref.current = this; return extend(conf, value.fn(defaultProps, config, value.opt));
} }, {}) : null;
}, this.options = extend(defaultProps, modifiedDefaultProps, config);
}
//释放当前对象
_purgeRef: function () {
var o = this.options;
if (o.__ref) {
BI.isFunction(o.__ref) ? o.__ref.call(null, null) : o.__ref.current = null;
o.__ref = null;
}
if (o.ref) {
BI.isFunction(o.ref) ? o.ref.call(null, null) : o.ref.current = null;
o.ref = null;
}
},
_getEvents: function () { _init() {
if (!BI._.isObject(this.events)) { this._initListeners();
this.events = {}; this.init && this.init();
} }
return this.events;
}, _initListeners() {
if (this.options.listeners !== null) {
/** BI._.each(this.options.listeners, (lis, eventName) => {
* 给观察者绑定一个事件 if (BI._.isFunction(lis)) {
* @param {String} eventName 事件的名字 this.on(eventName, lis);
* @param {Function} fn 事件对应的执行函数
*/ return;
on: function (eventName, fn) { }
var self = this; if (BI._.isArray(lis)) {
eventName = eventName.toLowerCase(); BI._.each(lis, (l) => {
var fns = this._getEvents()[eventName]; this.on(eventName, l);
if (!BI._.isArray(fns)) {
fns = [];
this._getEvents()[eventName] = fns;
}
fns.push(fn);
return function () {
self.un(eventName, fn);
};
},
/**
* 给观察者绑定一个只执行一次的事件
* @param {String} eventName 事件的名字
* @param {Function} fn 事件对应的执行函数
*/
once: function (eventName, fn) {
var proxy = function () {
fn.apply(this, arguments);
this.un(eventName, proxy);
};
this.on(eventName, proxy);
},
/**
* 解除观察者绑定的指定事件
* @param {String} eventName 要解除绑定事件的名字
* @param {Function} fn 事件对应的执行函数该参数是可选的没有该参数时将解除绑定所有同名字的事件
*/
un: function (eventName, fn) {
eventName = eventName.toLowerCase();
/* alex:如果fn是null,就是把eventName上面所有方法都un掉*/
if (fn == null) {
delete this._getEvents()[eventName];
} else {
var fns = this._getEvents()[eventName];
if (BI._.isArray(fns)) {
var newFns = [];
BI._.each(fns, function (ifn) {
if (ifn != fn) {
newFns.push(ifn);
}
}); });
this._getEvents()[eventName] = newFns;
return;
} }
} (lis.target ? lis.target : this)[lis.once ? "once" : "on"](lis.eventName, BI._.bind(lis.action, this));
}, });
delete this.options.listeners;
}
}
// 获得一个当前对象的引用
_initRef() {
const o = this.options;
if (o.__ref) {
BI.isFunction(o.__ref) ? o.__ref.call(this, this) : o.__ref.current = this;
}
if (o.ref) {
BI.isFunction(o.ref) ? o.ref.call(this, this) : o.ref.current = this;
}
}
// 释放当前对象
_purgeRef() {
const o = this.options;
if (o.__ref) {
BI.isFunction(o.__ref) ? o.__ref.call(null, null) : o.__ref.current = null;
o.__ref = null;
}
if (o.ref) {
BI.isFunction(o.ref) ? o.ref.call(null, null) : o.ref.current = null;
o.ref = null;
}
}
/** _getEvents() {
* 清除观察者的所有事件绑定 if (!BI._.isObject(this.events)) {
*/
purgeListeners: function () {
/* alex:清空events*/
this.events = {}; this.events = {};
}, }
/** return this.events;
* 触发绑定过的事件 }
*
* @param {String} eventName 要触发的事件的名字 /**
* @returns {Boolean} 如果事件函数返回false则返回false并中断其他同名事件的执行否则执行所有的同名事件并返回true * 给观察者绑定一个事件
*/ * @param {String} eventName 事件的名字
fireEvent: function () { * @param {Function} fn 事件对应的执行函数
var eventName = arguments[0].toLowerCase(); */
var fns = this._getEvents()[eventName]; on(eventName, fn) {
if (BI.isArray(fns)) { eventName = eventName.toLowerCase();
if (BI.isArguments(arguments[1])) { let fns = this._getEvents()[eventName];
for (var i = 0; i < fns.length; i++) { if (!BI._.isArray(fns)) {
if (fns[i].apply(this, arguments[1]) === false) { fns = [];
return false; this._getEvents()[eventName] = fns;
} }
fns.push(fn);
return () => this.un(eventName, fn);
}
/**
* 给观察者绑定一个只执行一次的事件
* @param {String} eventName 事件的名字
* @param {Function} fn 事件对应的执行函数
*/
once(eventName, fn) {
const proxy = () => {
fn.apply(this, arguments);
this.un(eventName, proxy);
};
this.on(eventName, proxy);
}
/**
* 解除观察者绑定的指定事件
* @param {String} eventName 要解除绑定事件的名字
* @param {Function} fn 事件对应的执行函数该参数是可选的没有该参数时将解除绑定所有同名字的事件
*/
un(eventName, fn) {
eventName = eventName.toLowerCase();
/* alex:如果fn是null,就是把eventName上面所有方法都un掉*/
if (fn === null) {
delete this._getEvents()[eventName];
} else {
const fns = this._getEvents()[eventName];
if (BI._.isArray(fns)) {
const newFns = [];
BI._.each(fns, function (ifn) {
if (ifn !== fn) {
newFns.push(ifn);
}
});
this._getEvents()[eventName] = newFns;
}
}
}
/**
* 清除观察者的所有事件绑定
*/
purgeListeners() {
/* alex:清空events*/
this.events = {};
}
/**
* 触发绑定过的事件
*
* @param {String} eventName 要触发的事件的名字
* @returns {Boolean} 如果事件函数返回false则返回false并中断其他同名事件的执行否则执行所有的同名事件并返回true
*/
fireEvent() {
const eventName = arguments[0].toLowerCase();
const fns = this._getEvents()[eventName];
if (BI.isArray(fns)) {
if (BI.isArguments(arguments[1])) {
for (let i = 0; i < fns.length; i++) {
if (fns[i].apply(this, arguments[1]) === false) {
return false;
} }
} else { }
var args = Array.prototype.slice.call(arguments, 1); } else {
for (var i = 0; i < fns.length; i++) { const args = Array.prototype.slice.call(arguments, 1);
if (fns[i].apply(this, args) === false) { for (let i = 0; i < fns.length; i++) {
return false; if (fns[i].apply(this, args) === false) {
} return false;
} }
} }
} }
return true;
},
destroy: function () {
this.destroyed && this.destroyed();
this._purgeRef();
this.purgeListeners();
} }
});
BI.OB = BI.OB || OB; return true;
})(); }
destroy() {
this.destroyed && this.destroyed();
this._purgeRef();
this.purgeListeners();
}
}
// BI.OB = BI.OB || OB;
BI.extend(BI, { OB });

1889
src/core/4.widget.js

File diff suppressed because it is too large Load Diff

21
src/core/action/action.js

@ -5,22 +5,21 @@
* @extends BI.OB * @extends BI.OB
* @abstract * @abstract
*/ */
BI.Action = BI.inherit(BI.OB, { import OB from "../3.ob";
props: function () { export default class Action extends OB {
return { props = {
src: null, src: null,
tar: null tar: null
}; };
},
actionPerformed: function (src, tar, callback) { actionPerformed(src, tar, callback) {
}, }
actionBack: function (tar, src, callback) { actionBack(tar, src, callback) {
} }
}); }
BI.ActionFactory = { BI.ActionFactory = {
createAction: function (key, options) { createAction: function (key, options) {

11
src/core/action/action.show.js

@ -4,16 +4,17 @@
* @class BI.ShowAction * @class BI.ShowAction
* @extends BI.Action * @extends BI.Action
*/ */
BI.ShowAction = BI.inherit(BI.Action, { import Action from "./action";
actionPerformed: function (src, tar, callback) { export default class ShowAction extends Action {
actionPerformed(src, tar, callback) {
tar = tar || this.options.tar; tar = tar || this.options.tar;
tar.setVisible(true); tar.setVisible(true);
callback && callback(); callback && callback();
}, }
actionBack: function (tar, src, callback) { actionBack(tar, src, callback) {
tar = tar || this.options.tar; tar = tar || this.options.tar;
tar.setVisible(false); tar.setVisible(false);
callback && callback(); callback && callback();
} }
}); }

16
src/core/behavior/0.behavior.js

@ -19,14 +19,16 @@ BI.BehaviorFactory = {
* @class BI.Behavior * @class BI.Behavior
* @extends BI.OB * @extends BI.OB
*/ */
BI.Behavior = BI.inherit(BI.OB, {
_defaultConfig: function () { import OB from "../3.ob";
return BI.extend(BI.Behavior.superclass._defaultConfig.apply(this, arguments), { export default class Behavior extends OB {
rule: function () {return true;} _defaultConfig() {
return BI.extend(super._defaultConfig(arguments), {
rule: () => true
}); });
}, }
doBehavior: function () { doBehavior() {
} }
}); }

11
src/core/behavior/behavior.highlight.js

@ -4,13 +4,14 @@
* @class BI.HighlightBehavior * @class BI.HighlightBehavior
* @extends BI.Behavior * @extends BI.Behavior
*/ */
BI.HighlightBehavior = BI.inherit(BI.Behavior, { import Behavior from "./0.behavior";
doBehavior: function (items) { export default class HighlightBehavior extends Behavior {
var args = Array.prototype.slice.call(arguments, 1), doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
o = this.options; o = this.options;
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if (item instanceof BI.Single) { if (item instanceof BI.Single) {
var rule = o.rule(item.getValue(), item); const rule = o.rule(item.getValue(), item);
function doBe (run) { function doBe (run) {
if (run === true) { if (run === true) {
@ -30,4 +31,4 @@ BI.HighlightBehavior = BI.inherit(BI.Behavior, {
} }
}); });
} }
}); }

9
src/core/behavior/behavior.redmark.js

@ -4,9 +4,10 @@
* @class BI.RedMarkBehavior * @class BI.RedMarkBehavior
* @extends BI.Behavior * @extends BI.Behavior
*/ */
BI.RedMarkBehavior = BI.inherit(BI.Behavior, { import Behavior from "./0.behavior";
doBehavior: function (items) { export default class RedMarkBehavior extends Behavior {
var args = Array.prototype.slice.call(arguments, 1), doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
o = this.options; o = this.options;
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
if(item instanceof BI.Single) { if(item instanceof BI.Single) {
@ -20,4 +21,4 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, {
} }
}); });
} }
}); }

7
src/core/controller/0.controller.js

@ -6,6 +6,7 @@
* @extends BI.OB * @extends BI.OB
* @abstract * @abstract
*/ */
BI.Controller = BI.inherit(BI.OB, { import OB from "../3.ob";
}); export default class Controller extends OB {
BI.Controller.EVENT_CHANGE = "__EVENT_CHANGE__"; static EVENT_CHANGE = "__EVENT_CHANGE__";
}

35
src/core/controller/controller.broadcast.js

@ -4,35 +4,28 @@
* Created by GUY on 2015/12/23. * Created by GUY on 2015/12/23.
* @class * @class
*/ */
BI.BroadcastController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
init: function () { export default class BroadcastController extends Controller {
init() {
this._broadcasts = {}; this._broadcasts = {};
}, }
on: function (name, fn) { on(name, fn) {
var self = this;
if (!this._broadcasts[name]) { if (!this._broadcasts[name]) {
this._broadcasts[name] = []; this._broadcasts[name] = [];
} }
this._broadcasts[name].push(fn); this._broadcasts[name].push(fn);
return function () { return () => this.remove(name, fn);
self.remove(name, fn); }
};
},
send: function (name) { send(name) {
var args = [].slice.call(arguments, 1); const args = [].slice.call(arguments, 1);
BI.each(this._broadcasts[name], function (i, fn) { BI.each(this._broadcasts[name], (i, fn) => fn.apply(null, args));
fn.apply(null, args); }
});
},
remove: function (name, fn) { remove(name, fn) {
var self = this;
if (fn) { if (fn) {
BI.remove(this._broadcasts[name], function (index, cb) { BI.remove(this._broadcasts[name], (index, cb) => fn === cb);
return fn === cb;
});
if (this._broadcasts[name].length === 0) { if (this._broadcasts[name].length === 0) {
delete this._broadcasts[name]; delete this._broadcasts[name];
} }
@ -41,4 +34,4 @@ BI.BroadcastController = BI.inherit(BI.Controller, {
} }
return this; return this;
} }
}); }

49
src/core/controller/controller.bubbles.js

@ -5,11 +5,12 @@
* Created by GUY on 2015/8/21. * Created by GUY on 2015/8/21.
* @class * @class
*/ */
BI.BubblesController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
init: function () { export default class BubblesController extends Controller {
init() {
this.storeBubbles = {}; this.storeBubbles = {};
this.storePoppers = {}; this.storePoppers = {};
}, }
/** /**
* *
@ -19,14 +20,14 @@ BI.BubblesController = BI.inherit(BI.Controller, {
* @param offsetStyle center, left, right三种类型 默认left * @param offsetStyle center, left, right三种类型 默认left
* @returns {BI.BubblesController} * @returns {BI.BubblesController}
*/ */
show: function (name, text, context, opt) { show(name, text, context, opt) {
opt || (opt = {}); opt || (opt = {});
var container = opt.container || context; const container = opt.container || context;
var offsetStyle = opt.offsetStyle || "left"; const offsetStyle = opt.offsetStyle || "left";
var level = opt.level || "error"; const level = opt.level || "error";
var adjustYOffset = opt.adjustYOffset || 0; const adjustYOffset = opt.adjustYOffset || 0;
var adjustXOffset = opt.adjustXOffset || 0; const adjustXOffset = opt.adjustXOffset || 0;
// var fixed = opt.fixed !== false; // const fixed = opt.fixed !== false;
if (!this.storeBubbles[name]) { if (!this.storeBubbles[name]) {
this.storeBubbles[name] = BI.createWidget({ this.storeBubbles[name] = BI.createWidget({
@ -37,7 +38,7 @@ BI.BubblesController = BI.inherit(BI.Controller, {
height: 18 height: 18
}); });
} }
var bubble = this.storeBubbles[name]; const bubble = this.storeBubbles[name];
if (bubble.getText() !== text) { if (bubble.getText() !== text) {
bubble.setText(text); bubble.setText(text);
} }
@ -75,18 +76,18 @@ BI.BubblesController = BI.inherit(BI.Controller, {
] ]
}); });
return this; return this;
}, }
hide: function (name) { hide(name) {
this.remove(name); this.remove(name);
return this; return this;
}, }
has: function (name) { has(name) {
return this.storeBubbles[name] != null; return this.storeBubbles[name] != null;
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -94,17 +95,13 @@ BI.BubblesController = BI.inherit(BI.Controller, {
this.storePoppers[name] && this.storePoppers[name].destroy(); this.storePoppers[name] && this.storePoppers[name].destroy();
delete this.storeBubbles[name]; delete this.storeBubbles[name];
return this; return this;
}, }
removeAll: function () { removeAll() {
BI.each(this.storeBubbles, function (name, bubble) { BI.each(this.storeBubbles, (name, bubble) => bubble.destroy());
bubble.destroy(); BI.each(this.storePoppers, (name, popper) => popper.destroy());
});
BI.each(this.storePoppers, function (name, popper) {
popper.destroy();
});
this.storeBubbles = {}; this.storeBubbles = {};
this.storePoppers = {}; this.storePoppers = {};
return this; return this;
} }
}); }

95
src/core/controller/controller.drawer.js

@ -4,62 +4,65 @@
* @class BI.popoverController * @class BI.popoverController
* @extends BI.Controller * @extends BI.Controller
*/ */
BI.DrawerController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
props: function () { export default class DrawerController extends Controller {
return { constructor() {
modal: true, // 模态窗口 super();
render: "body" this._constructor();
};
},
init: function () {
this.modal = this.options.modal; this.modal = this.options.modal;
}
props = {
modal: true, // 模态窗口
render: "body"
}
init() {
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
this.floatContainer = {}; this.floatContainer = {};
this.floatOpened = {}; this.floatOpened = {};
this.zindexMap = {}; this.zindexMap = {};
}, }
create: function (name, options, context) { create(name, options, context) {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
var popover = BI.createWidget(options || {}, { const popover = BI.createWidget(options || {}, {
type: "bi.drawer" type: "bi.drawer"
}, context); }, context);
this.add(name, popover, options, context); this.add(name, popover, options, context);
return this; return this;
}, }
open: function (name) { open(name) {
var self = this, o = this.options; const o = this.options;
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
if (!this.floatOpened[name]) { if (!this.floatOpened[name]) {
this.floatOpened[name] = true; this.floatOpened[name] = true;
var container = this.floatContainer[name]; const container = this.floatContainer[name];
var zIndex = BI.Popovers._getZIndex(); const zIndex = BI.Popovers._getZIndex();
container.element.css("zIndex", zIndex); container.element.css("zIndex", zIndex);
this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]);
this.zindexMap[name] = zIndex; this.zindexMap[name] = zIndex;
if (this.modal) { if (this.modal) {
var mask = container.element.__buildZIndexMask__(BI.Popovers._getZIndex()); const mask = container.element.__buildZIndexMask__(BI.Popovers._getZIndex());
mask.click(function () { mask.click(() => {
mask.destroy(); mask.destroy();
self.get(name).close(); this.get(name).close();
}); });
} }
this.get(name).setZindex(BI.Popovers._getZIndex()); this.get(name).setZindex(BI.Popovers._getZIndex());
this.floatContainer[name].visible(); this.floatContainer[name].visible();
var popover = this.get(name); const popover = this.get(name);
popover.show && popover.show(); popover.show && popover.show();
} }
return this; return this;
}, }
close: function (name) { close(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -69,22 +72,21 @@ BI.DrawerController = BI.inherit(BI.Controller, {
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
} }
return this; return this;
}, }
show: function (name) { show(name) {
return this.open(name); return this.open(name);
}, }
hide: function (name) { hide(name) {
return this.close(name); return this.close(name);
}, }
isVisible: function (name) { isVisible(name) {
return this.has(name) && this.floatOpened[name] === true; return this.has(name) && this.floatOpened[name] === true;
}, }
add: function (name, popover, options, context) { add(name, popover, options, context) {
var self = this;
options || (options = {}); options || (options = {});
if (this.has(name)) { if (this.has(name)) {
return this; return this;
@ -104,11 +106,7 @@ BI.DrawerController = BI.inherit(BI.Controller, {
}] }]
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
(function (key) { popover.on(BI.Drawer.EVENT_CLOSE, () => this.close(name));
popover.on(BI.Drawer.EVENT_CLOSE, function () {
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,
@ -121,17 +119,17 @@ BI.DrawerController = BI.inherit(BI.Controller, {
}] }]
}); });
return this; return this;
}, }
get: function (name) { get(name) {
return this.floatManager[name]; return this.floatManager[name];
}, }
has: function (name) { has(name) {
return BI.isNotNull(this.floatManager[name]); return BI.isNotNull(this.floatManager[name]);
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -143,13 +141,12 @@ BI.DrawerController = BI.inherit(BI.Controller, {
delete this.floatContainer[name]; delete this.floatContainer[name];
delete this.floatOpened[name]; delete this.floatOpened[name];
return this; return this;
}, }
removeAll: function () { removeAll() {
var self = this; BI.each(this.floatContainer, (name, container) => {
BI.each(this.floatContainer, function (name, container) {
container.destroy(); container.destroy();
self.modal && self.floatContainer[name].element.__releaseZIndexMask__(self.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}); });
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
@ -158,4 +155,4 @@ BI.DrawerController = BI.inherit(BI.Controller, {
this.zindexMap = {}; this.zindexMap = {};
return this; return this;
} }
}); }

89
src/core/controller/controller.layer.js

@ -4,32 +4,36 @@
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class * @class
*/ */
BI.LayerController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
props: function () { export default class LayerController extends Controller {
return { constructor() {
render: "body" super();
}; this._constructor();
}, }
init: function () { props = {
render: "body"
}
init() {
this.layerManager = {}; this.layerManager = {};
this.layouts = {}; this.layouts = {};
this.zindex = BI.zIndex_layer; this.zindex = BI.zIndex_layer;
}, }
_initResizer: function () { _initResizer() {
this.resizer = BI.Resizers.add("layerController" + BI.uniqueId(), BI.bind(this._resize, this)); this.resizer = BI.Resizers.add("layerController" + BI.uniqueId(), BI.bind(this._resize, this));
}, }
_resize: function () { _resize() {
BI.each(this.layouts, function (i, layer) { BI.each(this.layouts, function (i, layer) {
if (layer.element.is(":visible")) { if (layer.element.is(":visible")) {
layer.element.trigger("__resize__"); layer.element.trigger("__resize__");
} }
}); });
}, }
make: function (name, container, op, context) { make(name, container, op, context) {
if (BI.isWidget(container)) { if (BI.isWidget(container)) {
op = op || {}; op = op || {};
op.container = container; op.container = container;
@ -38,16 +42,16 @@ BI.LayerController = BI.inherit(BI.Controller, {
op = container; op = container;
} }
return this.create(name, null, op, context); return this.create(name, null, op, context);
}, }
create: function (name, from, op, context) { create(name, from, op, context) {
BI.isNull(this.resizer) && this._initResizer(); BI.isNull(this.resizer) && this._initResizer();
if (this.has(name)) { if (this.has(name)) {
return this.get(name); return this.get(name);
} }
op || (op = {}); op || (op = {});
var offset = op.offset || {}; const offset = op.offset || {};
var w = from; let w = from;
if (BI.isWidget(from)) { if (BI.isWidget(from)) {
w = from.element; w = from.element;
} }
@ -57,10 +61,10 @@ BI.LayerController = BI.inherit(BI.Controller, {
if (this.has(name)) { if (this.has(name)) {
return this.get(name); return this.get(name);
} }
var widget = BI.createWidget((op.render || {}), BI.extend({ const widget = BI.createWidget((op.render || {}), BI.extend({
type: "bi.layout" type: "bi.layout"
}, op), context); }, op), context);
var layout = BI.createWidget({ const layout = BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
invisible: true, invisible: true,
items: [ items: [
@ -115,31 +119,31 @@ BI.LayerController = BI.inherit(BI.Controller, {
} }
this.add(name, widget, layout); this.add(name, widget, layout);
return widget; return widget;
}, }
show: function (name, callback) { show(name, callback) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
this._getLayout(name).visible(); this._getLayout(name).visible();
this._getLayout(name).element.css("z-index", this.zindex++).show(0, callback).trigger("__resize__"); this._getLayout(name).element.css("z-index", this.zindex++).show(0, callback).trigger("__resize__");
return this; return this;
}, }
hide: function (name, callback) { hide(name, callback) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
this._getLayout(name).invisible(); this._getLayout(name).invisible();
this._getLayout(name).element.hide(0, callback); this._getLayout(name).element.hide(0, callback);
return this; return this;
}, }
isVisible: function (name) { isVisible(name) {
return this.has(name) && this._getLayout(name).isVisible(); return this.has(name) && this._getLayout(name).isVisible();
}, }
add: function (name, layer, layout) { add(name, layer, layout) {
if (this.has(name)) { if (this.has(name)) {
throw new Error("不能创建同名的Layer"); throw new Error("不能创建同名的Layer");
} }
@ -148,21 +152,21 @@ BI.LayerController = BI.inherit(BI.Controller, {
this.layouts[name] = layout; this.layouts[name] = layout;
layout.element.css("z-index", this.zindex++); layout.element.css("z-index", this.zindex++);
return this; return this;
}, }
_getLayout: function (name) { _getLayout(name) {
return this.layouts[name]; return this.layouts[name];
}, }
get: function (name) { get(name) {
return this.layerManager[name]; return this.layerManager[name];
}, }
has: function (name) { has(name) {
return this.layerManager[name] != null; return this.layerManager[name] != null;
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -171,16 +175,15 @@ BI.LayerController = BI.inherit(BI.Controller, {
delete this.layerManager[name]; delete this.layerManager[name];
delete this.layouts[name]; delete this.layouts[name];
return this; return this;
}, }
removeAll: function () { removeAll() {
var self = this; BI.each(BI.keys(this.layerManager), (index, name) => {
BI.each(BI.keys(this.layerManager), function (index, name) { this.layerManager[name].destroy();
self.layerManager[name].destroy(); this.layouts[name].destroy();
self.layouts[name].destroy();
}); });
this.layerManager = {}; this.layerManager = {};
this.layouts = {}; this.layouts = {};
return this; return this;
} }
}); }

9
src/core/controller/controller.masker.js

@ -4,9 +4,10 @@
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class * @class
*/ */
BI.MaskersController = BI.inherit(BI.LayerController, { import LayerController from "./controller.layer";
init: function () { export default class MaskersController extends LayerController {
BI.MaskersController.superclass.init.apply(this, arguments); init() {
super.init(arguments);
this.zindex = BI.zIndex_masker; this.zindex = BI.zIndex_masker;
} }
}); }

96
src/core/controller/controller.popover.js

@ -4,54 +4,58 @@
* @class BI.popoverController * @class BI.popoverController
* @extends BI.Controller * @extends BI.Controller
*/ */
BI.PopoverController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
props: function () { export default class PopoverController extends Controller {
return { constructor() {
modal: true, // 模态窗口 super();
render: "body" this._constructor();
};
},
init: function () {
this.modal = this.options.modal; this.modal = this.options.modal;
}
props = {
modal: true, // 模态窗口
render: "body"
}
init() {
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
this.floatContainer = {}; this.floatContainer = {};
this.floatOpened = {}; this.floatOpened = {};
this.zindex = BI.zIndex_popover; this.zindex = BI.zIndex_popover;
this.zindexMap = {}; this.zindexMap = {};
}, }
create: function (name, options, context) { create(name, options, context) {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
var popover = BI.createWidget(options || {}, { const popover = BI.createWidget(options || {}, {
type: "bi.popover" type: "bi.popover"
}, context); }, context);
this.add(name, popover, options, context); this.add(name, popover, options, context);
return this; return this;
}, }
open: function (name) { open(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
if (!this.floatOpened[name]) { if (!this.floatOpened[name]) {
this.floatOpened[name] = true; this.floatOpened[name] = true;
var container = this.floatContainer[name]; const container = this.floatContainer[name];
container.element.css("zIndex", this.zindex++); container.element.css("zIndex", this.zindex++);
this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]);
this.zindexMap[name] = this.zindex; this.zindexMap[name] = this.zindex;
this.modal && container.element.__buildZIndexMask__(this.zindex++); this.modal && container.element.__buildZIndexMask__(this.zindex++);
this.get(name).setZindex(this.zindex++); this.get(name).setZindex(this.zindex++);
this.floatContainer[name].visible(); this.floatContainer[name].visible();
var popover = this.get(name); const popover = this.get(name);
popover.show && popover.show(); popover.show && popover.show();
var 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();
var w = popover.element.width(), h = popover.element.height(); const w = popover.element.width(), h = popover.element.height();
var 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;
} }
@ -65,9 +69,9 @@ BI.PopoverController = BI.inherit(BI.Controller, {
}); });
} }
return this; return this;
}, }
close: function (name) { close(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -77,22 +81,21 @@ BI.PopoverController = BI.inherit(BI.Controller, {
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
} }
return this; return this;
}, }
show: function (name) { show(name) {
return this.open(name); return this.open(name);
}, }
hide: function (name) { hide(name) {
return this.close(name); return this.close(name);
}, }
isVisible: function (name) { isVisible(name) {
return this.has(name) && this.floatOpened[name] === true; return this.has(name) && this.floatOpened[name] === true;
}, }
add: function (name, popover, options, context) { add(name, popover, options, context) {
var self = this;
options || (options = {}); options || (options = {});
if (this.has(name)) { if (this.has(name)) {
return this; return this;
@ -112,11 +115,7 @@ BI.PopoverController = BI.inherit(BI.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, function () {
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,
@ -129,17 +128,17 @@ BI.PopoverController = BI.inherit(BI.Controller, {
}] }]
}); });
return this; return this;
}, }
get: function (name) { get(name) {
return this.floatManager[name]; return this.floatManager[name];
}, }
has: function (name) { has(name) {
return BI.isNotNull(this.floatManager[name]); return BI.isNotNull(this.floatManager[name]);
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -151,13 +150,12 @@ BI.PopoverController = BI.inherit(BI.Controller, {
delete this.floatContainer[name]; delete this.floatContainer[name];
delete this.floatOpened[name]; delete this.floatOpened[name];
return this; return this;
}, }
removeAll: function () { removeAll() {
var self = this; BI.each(this.floatContainer, (name, container) => {
BI.each(this.floatContainer, function (name, container) {
container.destroy(); container.destroy();
self.modal && self.floatContainer[name].element.__releaseZIndexMask__(self.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}); });
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
@ -165,9 +163,9 @@ BI.PopoverController = BI.inherit(BI.Controller, {
this.floatOpened = {}; this.floatOpened = {};
this.zindexMap = {}; this.zindexMap = {};
return this; return this;
}, }
_getZIndex: function () { _getZIndex() {
return this.zindex++; return this.zindex++;
} }
}); }

41
src/core/controller/controller.resizer.js

@ -4,25 +4,23 @@
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class * @class
*/ */
BI.ResizeController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
export default class ResizeController extends Controller {
init: function () { init() {
this.resizerManger = {}; this.resizerManger = {};
}, }
_initResizeListener: function () { _initResizeListener() {
var self = this; this.resizeHandler = BI.debounce((ev) => this._resize(ev), 30);
this.resizeHandler = BI.debounce(function (ev) {
self._resize(ev);
}, 30);
if ("onorientationchange" in _global) { if ("onorientationchange" in _global) {
_global.onorientationchange = this.resizeHandler; _global.onorientationchange = this.resizeHandler;
} else { } else {
BI.Widget._renderEngine.createElement(_global).resize(this.resizeHandler); BI.Widget._renderEngine.createElement(_global).resize(this.resizeHandler);
} }
}, }
_resize: function (ev) { _resize(ev) {
BI.each(this.resizerManger, function (key, resizer) { BI.each(this.resizerManger, function (key, resizer) {
if (resizer instanceof BI.$) { if (resizer instanceof BI.$) {
if (resizer.is(":visible")) { if (resizer.is(":visible")) {
@ -38,34 +36,31 @@ BI.ResizeController = BI.inherit(BI.Controller, {
resizer(ev); resizer(ev);
} }
}); });
}, }
add: function (name, resizer) { add(name, resizer) {
var self = this;
BI.isNull(this.resizeHandler) && this._initResizeListener(); BI.isNull(this.resizeHandler) && this._initResizeListener();
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
this.resizerManger[name] = resizer; this.resizerManger[name] = resizer;
return function () { return () => this.remove(name);
self.remove(name); }
};
},
get: function (name) { get(name) {
return this.resizerManger[name]; return this.resizerManger[name];
}, }
has: function (name) { has(name) {
return this.resizerManger[name] != null; return this.resizerManger[name] != null;
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
delete this.resizerManger[name]; delete this.resizerManger[name];
return this; return this;
} }
}); }

76
src/core/controller/controller.tooltips.js

@ -6,11 +6,12 @@
* @class BI.TooltipsController * @class BI.TooltipsController
* @extends BI.Controller * @extends BI.Controller
*/ */
BI.TooltipsController = BI.inherit(BI.Controller, { import Controller from "./0.controller";
init: function () { export default class TooltipsController extends Controller {
init() {
this.tooltipsManager = {}; this.tooltipsManager = {};
this.showingTips = {};// 存储正在显示的tooltip this.showingTips = {};// 存储正在显示的tooltip
}, }
/** /**
* *
@ -21,34 +22,33 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
* @returns {*} * @returns {*}
* @private * @private
*/ */
_createTooltip: function (opt) { _createTooltip(opt) {
return BI.createWidget({ return BI.createWidget({
type: "bi.tooltip", type: "bi.tooltip",
...opt, ...opt,
stopEvent: true stopEvent: true
}); });
}, }
// opt: {container: '', belowMouse: false} // opt: {container: '', belowMouse: false}
show: function (e, name, tooltipOpt, context, opt) { show(e, name, tooltipOpt, context, opt) {
opt || (opt = {}); opt || (opt = {});
var self = this; BI.each(this.showingTips, (i, tip) => this.hide(i));
BI.each(this.showingTips, function (i, tip) {
self.hide(i);
});
this.showingTips = {}; this.showingTips = {};
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) {
var offset = context.element.offset(); const bounds = context.element.bounds();
var bounds = context.element.bounds();
if (bounds.height === 0 || bounds.width === 0) { if (bounds.height === 0 || bounds.width === 0) {
return; return;
} }
var top = offset.top + bounds.height + 5; top = offset.top + bounds.height + 5;
} }
var tooltip = this.get(name); const tooltip = this.get(name);
tooltip.element.css({ tooltip.element.css({
left: "0px", left: "0px",
top: "0px" top: "0px"
@ -57,13 +57,13 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
tooltip.element.height(tooltip.element[0].scrollHeight); tooltip.element.height(tooltip.element[0].scrollHeight);
this.showingTips[name] = true; this.showingTips[name] = true;
// scale影响要计算在内 // scale影响要计算在内
// var scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left; // const scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left;
// var x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15; // const x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15;
var x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15; let x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15;
if (x + tooltip.element.outerWidth() > BI.Widget._renderEngine.createElement("body").outerWidth()) { if (x + tooltip.element.outerWidth() > BI.Widget._renderEngine.createElement("body").outerWidth()) {
x -= tooltip.element.outerWidth() + 15; x -= tooltip.element.outerWidth() + 15;
} }
var bodyHeight = BI.Widget._renderEngine.createElement("body").outerHeight(); const bodyHeight = BI.Widget._renderEngine.createElement("body").outerHeight();
if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) { if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) {
y -= tooltip.element.outerHeight() + 15; y -= tooltip.element.outerHeight() + 15;
!opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5)); !opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5));
@ -75,14 +75,14 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
left: x < 0 ? 0 : x + "px", left: x < 0 ? 0 : x + "px",
top: y < 0 ? 0 : y + "px" top: y < 0 ? 0 : y + "px"
}); });
tooltip.element.hover(function () { tooltip.element.hover(() => {
self.remove(name); this.remove(name);
context.element.trigger("mouseleave.title" + context.getName()); context.element.trigger("mouseleave.title" + context.getName());
}); });
return this; return this;
}, }
hide: function (name, callback) { hide(name, callback) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -90,11 +90,11 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
this.get(name).element.hide(0, callback); this.get(name).element.hide(0, callback);
this.get(name).invisible(); this.get(name).invisible();
return this; return this;
}, }
create: function (name, tooltipOpt, context) { create(name, tooltipOpt, context) {
if (!this.has(name)) { if (!this.has(name)) {
var tooltip = this._createTooltip(tooltipOpt); const tooltip = this._createTooltip(tooltipOpt);
this.add(name, tooltip); this.add(name, tooltip);
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
@ -106,38 +106,38 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
tooltip.invisible(); tooltip.invisible();
} }
return this.get(name); return this.get(name);
}, }
add: function (name, bubble) { add(name, bubble) {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
this.set(name, bubble); this.set(name, bubble);
return this; return this;
}, }
get: function (name) { get(name) {
return this.tooltipsManager[name]; return this.tooltipsManager[name];
}, }
set: function (name, bubble) { set(name, bubble) {
this.tooltipsManager[name] = bubble; this.tooltipsManager[name] = bubble;
}, }
has: function (name) { has(name) {
return this.tooltipsManager[name] != null; return this.tooltipsManager[name] != null;
}, }
remove: function (name) { remove(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
this.tooltipsManager[name].destroy(); this.tooltipsManager[name].destroy();
delete this.tooltipsManager[name]; delete this.tooltipsManager[name];
return this; return this;
}, }
removeAll: function () { removeAll() {
BI.each(this.tooltipsManager, function (name, tooltip) { BI.each(this.tooltipsManager, function (name, tooltip) {
tooltip.destroy(); tooltip.destroy();
}); });
@ -145,4 +145,4 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
this.showingTips = {}; this.showingTips = {};
return this; return this;
} }
}); }

8
src/core/decorator.js

@ -0,0 +1,8 @@
/**
* 注册widget
*/
export function shortcut() {
return function decorator(Target) {
BI.shortcut(Target.xtype, Target);
};
}

59
src/core/index.js

@ -0,0 +1,59 @@
import { shortcut } from "./decorator";
import OB from "./3.ob";
import Widget from "./4.widget";
import Action from "./action/action";
import ShowAction from "./action/action.show";
import Behavior from "./behavior/0.behavior";
import HighlightBehavior from "./behavior/behavior.highlight";
import RedMarkBehavior from "./behavior/behavior.redmark";
import Controller from "./controller/0.controller";
import BroadcastController from "./controller/controller.broadcast";
import BubblesController from "./controller/controller.bubbles";
import DrawerController from "./controller/controller.drawer";
import LayerController from "./controller/controller.layer";
import MaskersController from "./controller/controller.masker";
import PopoverController from "./controller/controller.popover";
import ResizeController from "./controller/controller.resizer";
import TooltipsController from "./controller/controller.tooltips";
import StyleLoaderManager from "./loader/loader.style";
BI.extend(BI, {
OB,
Widget,
Action,
ShowAction,
Behavior,
HighlightBehavior,
RedMarkBehavior,
Controller,
BroadcastController,
BubblesController,
DrawerController,
LayerController,
MaskersController,
PopoverController,
ResizeController,
TooltipsController,
StyleLoaderManager,
});
export {
shortcut,
OB,
Widget,
Action,
ShowAction,
Behavior,
HighlightBehavior,
RedMarkBehavior,
Controller,
BroadcastController,
BubblesController,
DrawerController,
LayerController,
MaskersController,
PopoverController,
ResizeController,
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;
} }
}); }

3
tsconfig.json

@ -20,7 +20,8 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"emitDeclarationOnly": true "emitDeclarationOnly": true,
"allowJs": true,
}, },
"include": [ "include": [
"typescript/*.ts", "typescript/*.ts",

Loading…
Cancel
Save