Browse Source

KERNEL-13947 refactor: ob和widget的es6化

es6
Zhenfei.Li 2 years ago
parent
commit
da4a0ffac0
  1. 2
      .eslintrc
  2. 109
      src/core/2.base.js
  3. 153
      src/core/3.ob.js
  4. 585
      src/core/4.widget.js
  5. 17
      src/core/action/action.js
  6. 13
      src/core/action/action.show.js
  7. 17
      src/core/behavior/0.behavior.js
  8. 12
      src/core/behavior/behavior.highlight.js
  9. 10
      src/core/behavior/behavior.redmark.js
  10. 8
      src/core/controller/0.controller.js
  11. 36
      src/core/controller/controller.broadcast.js
  12. 50
      src/core/controller/controller.bubbles.js
  13. 84
      src/core/controller/controller.drawer.js
  14. 81
      src/core/controller/controller.layer.js
  15. 10
      src/core/controller/controller.masker.js
  16. 84
      src/core/controller/controller.popover.js
  17. 43
      src/core/controller/controller.resizer.js
  18. 75
      src/core/controller/controller.tooltips.js

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"],

109
src/core/2.base.js

@ -3,27 +3,26 @@
* Create By GUY 2014\11\17 * Create By GUY 2014\11\17
* *
*/ */
!(function (undefined) { var traverse = function (func, context) {
var traverse = function (func, context) {
return function (value, key, obj) { return function (value, key, obj) {
return func.call(context, key, value, obj); return func.call(context, key, value, obj);
}; };
}; };
var _apply = function (name) { var _apply = function (name) {
return function () { return function () {
return BI._[name].apply(BI._, arguments); return BI._[name].apply(BI._, arguments);
}; };
}; };
var _applyFunc = function (name) { var _applyFunc = function (name) {
return function () { return function () {
var args = Array.prototype.slice.call(arguments, 0); var args = Array.prototype.slice.call(arguments, 0);
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1];
return BI._[name].apply(BI._, args); return BI._[name].apply(BI._, args);
}; };
}; };
// Utility // Utility
BI._.extend(BI, { BI._.extend(BI, {
assert: function (v, is) { assert: function (v, is) {
if (this.isFunction(is)) { if (this.isFunction(is)) {
if (!is(v)) { if (!is(v)) {
@ -143,21 +142,21 @@
return wi.element; return wi.element;
}); });
} }
}); });
// 集合相关方法 // 集合相关方法
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) {
BI[name] = _apply(name); BI[name] = _apply(name);
}); });
BI._.each(["get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", BI._.each(["get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min",
"sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp"], function (name) { "sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp"], function (name) {
if (name === "any") { if (name === "any") {
BI[name] = _applyFunc("some"); BI[name] = _applyFunc("some");
} else { } else {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);
} }
}); });
BI._.extend(BI, { BI._.extend(BI, {
// 数数 // 数数
count: function (from, to, predicate) { count: function (from, to, predicate) {
var t; var t;
@ -344,17 +343,17 @@
} }
return str; return str;
} }
}); });
// 数组相关的方法 // 数组相关的方法
BI._.each(["first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", BI._.each(["first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection",
"difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy"], function (name) { "difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy"], function (name) {
BI[name] = _apply(name); BI[name] = _apply(name);
}); });
BI._.each(["findIndex", "findLastIndex"], function (name) { BI._.each(["findIndex", "findLastIndex"], function (name) {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);
}); });
BI._.extend(BI, { BI._.extend(BI, {
// 构建一个长度为length的数组 // 构建一个长度为length的数组
makeArray: function (length, value) { makeArray: function (length, value) {
var res = []; var res = [];
@ -409,19 +408,19 @@
iteratee && (iteratee = traverse(iteratee, context)); iteratee && (iteratee = traverse(iteratee, context));
return BI._.uniq.call(BI._, array, isSorted, iteratee, context); return BI._.uniq.call(BI._, array, isSorted, iteratee, context);
} }
}); });
// 对象相关方法 // 对象相关方法
BI._.each(["keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", BI._.each(["keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn",
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", "defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty",
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", "isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite",
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep"], function (name) { "isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep"], function (name) {
BI[name] = _apply(name); BI[name] = _apply(name);
}); });
BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], function (name) { BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], function (name) {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);
}); });
BI._.extend(BI, { BI._.extend(BI, {
inherit: function (sp, overrides) { inherit: function (sp, overrides) {
var sb = function () { var sb = function () {
@ -529,10 +528,10 @@
isPromise: function (obj) { isPromise: function (obj) {
return !!obj && (BI.isObject(obj) || BI.isFunction(obj)) && BI.isFunction(obj.then); return !!obj && (BI.isObject(obj) || BI.isFunction(obj)) && BI.isFunction(obj.then);
} }
}); });
// deep方法 // deep方法
BI._.extend(BI, { BI._.extend(BI, {
deepClone: BI._.cloneDeep, deepClone: BI._.cloneDeep,
deepExtend: BI._.merge, deepExtend: BI._.merge,
@ -648,23 +647,23 @@
} }
return result; return result;
} }
}); });
// 通用方法 // 通用方法
BI._.each(["uniqueId", "result", "chain", "iteratee", "escape", "unescape", "before", "after", "chunk"], function (name) { BI._.each(["uniqueId", "result", "chain", "iteratee", "escape", "unescape", "before", "after", "chunk"], function (name) {
BI[name] = function () { BI[name] = function () {
return BI._[name].apply(BI._, arguments); return BI._[name].apply(BI._, arguments);
}; };
}); });
// 事件相关方法 // 事件相关方法
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], function (name) { BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], function (name) {
BI[name] = function () { BI[name] = function () {
return BI._[name].apply(BI._, arguments); return BI._[name].apply(BI._, arguments);
}; };
}); });
BI._.extend(BI, { BI._.extend(BI, {
nextTick: (function () { nextTick: (function () {
var callbacks = []; var callbacks = [];
var pending = false; var pending = false;
@ -732,13 +731,13 @@
} }
}; };
})() })()
}); });
// 数字相关方法 // 数字相关方法
BI._.each(["random"], function (name) { BI._.each(["random"], function (name) {
BI[name] = _apply(name); BI[name] = _apply(name);
}); });
BI._.extend(BI, { BI._.extend(BI, {
parseInt: function (number) { parseInt: function (number) {
var radix = 10; var radix = 10;
@ -838,10 +837,10 @@
var sum = BI.sum(array, iteratee, context); var sum = BI.sum(array, iteratee, context);
return sum / array.length; return sum / array.length;
} }
}); });
// 字符串相关方法 // 字符串相关方法
BI._.extend(BI, { BI._.extend(BI, {
trim: function () { trim: function () {
return BI._.trim.apply(BI._, arguments); return BI._.trim.apply(BI._, arguments);
}, },
@ -966,10 +965,10 @@
return args[i]; return args[i];
}); });
} }
}); });
// 日期相关方法 // 日期相关方法
BI._.extend(BI, { BI._.extend(BI, {
/** /**
* 是否是闰年 * 是否是闰年
* @param year * @param year
@ -1276,5 +1275,7 @@
return dt.getTime(); return dt.getTime();
} }
}); });
})();
// TODO: 暂时先直接export全部,下一步拆function
export default BI;

153
src/core/3.ob.js

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

585
src/core/4.widget.js

File diff suppressed because it is too large Load Diff

17
src/core/action/action.js

@ -5,22 +5,23 @@
* @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.extend(BI, { Action });
BI.ActionFactory = { BI.ActionFactory = {
createAction: function (key, options) { createAction: function (key, options) {

13
src/core/action/action.show.js

@ -4,16 +4,19 @@
* @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();
} }
}); }
BI.extend(BI, { ShowAction });

17
src/core/behavior/0.behavior.js

@ -19,14 +19,17 @@ 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() {
} }
}); }
BI.extend(BI, { Behavior });

12
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,5 @@ BI.HighlightBehavior = BI.inherit(BI.Behavior, {
} }
}); });
} }
}); }
BI.extend(BI, { HighlightBehavior });

10
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,5 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, {
} }
}); });
} }
}); }
BI.extend(BI, { RedMarkBehavior })

8
src/core/controller/0.controller.js

@ -6,6 +6,8 @@
* @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__";
}
BI.extend(BI, { Controller })

36
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,5 @@ BI.BroadcastController = BI.inherit(BI.Controller, {
} }
return this; return this;
} }
}); }
BI.extend(BI, { BroadcastController })

50
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);
} }
@ -69,18 +70,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;
} }
@ -88,17 +89,14 @@ 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;
} }
}); }
BI.extend(BI, { BubblesController });

84
src/core/controller/controller.drawer.js

@ -4,62 +4,61 @@
* @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 { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body"
}; }
},
init: function () { init() {
this.modal = this.options.modal; this.modal = this.options.modal;
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 +68,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;
@ -105,9 +103,7 @@ BI.DrawerController = BI.inherit(BI.Controller, {
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
(function (key) { (function (key) {
popover.on(BI.Drawer.EVENT_CLOSE, function () { popover.on(BI.Drawer.EVENT_CLOSE, () => this.close(key));
self.close(key);
});
})(name); })(name);
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
@ -121,17 +117,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 +139,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 +153,5 @@ BI.DrawerController = BI.inherit(BI.Controller, {
this.zindexMap = {}; this.zindexMap = {};
return this; return this;
} }
}); }
BI.extend(BI, { DrawerController });

81
src/core/controller/controller.layer.js

@ -4,32 +4,31 @@
* 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 { props = {
render: "body" render: "body"
}; }
},
init: function () { 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 +37,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 +56,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: [{
@ -102,31 +101,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");
} }
@ -135,21 +134,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;
} }
@ -158,16 +157,16 @@ 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;
} }
}); }
BI.extend(BI, { LayerController });

10
src/core/controller/controller.masker.js

@ -4,9 +4,11 @@
* 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;
} }
}); }
BI.extend(BI, { MaskersController });

84
src/core/controller/controller.popover.js

@ -4,15 +4,14 @@
* @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 { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body"
}; }
},
init: function () { init() {
this.modal = this.options.modal; this.modal = this.options.modal;
this.floatManager = {}; this.floatManager = {};
this.floatLayer = {}; this.floatLayer = {};
@ -20,38 +19,38 @@ BI.PopoverController = BI.inherit(BI.Controller, {
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; const left = (W - w) / 2, top = (H - h) / 2;
if (left < 0) { if (left < 0) {
left = 0; left = 0;
} }
@ -65,9 +64,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 +76,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;
@ -113,9 +111,7 @@ BI.PopoverController = BI.inherit(BI.Controller, {
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
(function (key) { (function (key) {
popover.on(BI.Popover.EVENT_CLOSE, function () { popover.on(BI.Popover.EVENT_CLOSE, () => self.close(key));
self.close(key);
});
})(name); })(name);
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
@ -129,17 +125,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 +147,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 +160,10 @@ 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++;
} }
}); }
BI.extend(BI, { PopoverController });

43
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,33 @@ 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;
} }
}); }
BI.extend(BI, { ResizeController });

75
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,31 @@ 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"));
} }
if (!opt.belowMouse) { if (!opt.belowMouse) {
var offset = context.element.offset(); const offset = context.element.offset();
var 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;
} }
var top = offset.top + bounds.height + 5; const 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 +55,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; const 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 +73,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 +88,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 +104,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 +143,5 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
this.showingTips = {}; this.showingTips = {};
return this; return this;
} }
}); }
BI.extend(BI, { TooltipsController });

Loading…
Cancel
Save