Browse Source

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

* commit 'c8157c5853d8c26651c4ba0109e3c095b9f05ee3':
  KERNEL-13947 refactor: OB和Widget从index export
  KERNEL-13947 refactor: 统一挂载
  KERNEL-13947 refactor: ob和widget的es6化
es6
Joker.Wang-王顺 2 years ago
parent
commit
eb02dc2d82
  1. 2
      .eslintrc
  2. 2345
      src/core/2.base.js
  3. 397
      src/core/3.ob.js
  4. 1889
      src/core/4.widget.js
  5. 21
      src/core/action/action.js
  6. 11
      src/core/action/action.show.js
  7. 16
      src/core/behavior/0.behavior.js
  8. 11
      src/core/behavior/behavior.highlight.js
  9. 9
      src/core/behavior/behavior.redmark.js
  10. 7
      src/core/controller/0.controller.js
  11. 35
      src/core/controller/controller.broadcast.js
  12. 49
      src/core/controller/controller.bubbles.js
  13. 87
      src/core/controller/controller.drawer.js
  14. 82
      src/core/controller/controller.layer.js
  15. 9
      src/core/controller/controller.masker.js
  16. 87
      src/core/controller/controller.popover.js
  17. 41
      src/core/controller/controller.resizer.js
  18. 74
      src/core/controller/controller.tooltips.js
  19. 54
      src/core/index.js

2
.eslintrc

@ -27,7 +27,7 @@
"plugins": ["@typescript-eslint/eslint-plugin"],
"overrides": [{
"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": {
"no-param-reassign": "off",
"quotes": [2, "double"],

2345
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 () {
function extend() {
var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy;
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if (target === copy) {
continue;
}
import BI from "./2.base";
function extend() {
let target = arguments[0] || {}, length = arguments.length, i = 1, name, copy;
for (; i < length; i++) {
// Only deal with non-null/undefined values
const options = arguments[i];
if (options !== null) {
// Extend the base object
for (name in options) {
copy = options[name];
// Prevent never-ending loop
if (target === copy) {
continue;
}
if (copy !== undefined) {
target[name] = copy;
}
if (copy !== undefined) {
target[name] = copy;
}
}
}
return target;
}
/**
* 客户端观察者主要处理事件的添加删除执行等
* @class BI.OB
* @abstract
*/
var OB = function (config) {
this._constructor(config);
};
BI._.extend(OB.prototype, {
props: {},
return target;
}
init: null,
export default class OB {
// props = {};
destroyed: null,
// init = null;
_constructor: function (config) {
this._initProps(config);
this._init();
this._initRef();
},
// destroyed = null;
_defaultConfig: function (config) {
return {};
},
constructor(config) {
this._constructor(config);
}
_initProps: function (config) {
var props = this.props;
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;
}
},
_constructor(config) {
this._initProps(config);
this._init();
this._initRef();
}
// 获得一个当前对象的引用
_initRef: function () {
var 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: 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;
}
},
_defaultConfig(config) {
return {};
}
_getEvents: function () {
if (!BI._.isObject(this.events)) {
this.events = {};
}
return this.events;
},
/**
* 给观察者绑定一个事件
* @param {String} eventName 事件的名字
* @param {Function} fn 事件对应的执行函数
*/
on: function (eventName, fn) {
var self = this;
eventName = eventName.toLowerCase();
var fns = this._getEvents()[eventName];
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);
}
_initProps(config) {
let props = this.props;
if (BI.isFunction(this.props)) {
props = this.props(config);
}
const defaultProps = extend(this._defaultConfig(config), props);
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));
}, {}) : null;
this.options = extend(defaultProps, modifiedDefaultProps, config);
}
_init() {
this._initListeners();
this.init && this.init();
}
_initListeners() {
if (this.options.listeners !== null) {
BI._.each(this.options.listeners, (lis, eventName) => {
if (BI._.isFunction(lis)) {
this.on(eventName, lis);
return;
}
if (BI._.isArray(lis)) {
BI._.each(lis, (l) => {
this.on(eventName, l);
});
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;
}
}
/**
* 清除观察者的所有事件绑定
*/
purgeListeners: function () {
/* alex:清空events*/
// 释放当前对象
_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)) {
this.events = {};
},
/**
* 触发绑定过的事件
*
* @param {String} eventName 要触发的事件的名字
* @returns {Boolean} 如果事件函数返回false则返回false并中断其他同名事件的执行否则执行所有的同名事件并返回true
*/
fireEvent: function () {
var eventName = arguments[0].toLowerCase();
var fns = this._getEvents()[eventName];
if (BI.isArray(fns)) {
if (BI.isArguments(arguments[1])) {
for (var i = 0; i < fns.length; i++) {
if (fns[i].apply(this, arguments[1]) === false) {
return false;
}
}
return this.events;
}
/**
* 给观察者绑定一个事件
* @param {String} eventName 事件的名字
* @param {Function} fn 事件对应的执行函数
*/
on(eventName, fn) {
eventName = eventName.toLowerCase();
let fns = this._getEvents()[eventName];
if (!BI._.isArray(fns)) {
fns = [];
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);
}
} else {
var args = Array.prototype.slice.call(arguments, 1);
for (var i = 0; i < fns.length; i++) {
if (fns[i].apply(this, args) === false) {
return false;
}
});
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 {
const args = Array.prototype.slice.call(arguments, 1);
for (let i = 0; i < fns.length; i++) {
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
* @abstract
*/
BI.Action = BI.inherit(BI.OB, {
props: function () {
return {
src: null,
tar: null
};
},
import OB from "../3.ob";
export default class Action extends OB {
props = {
src: null,
tar: null
};
actionPerformed: function (src, tar, callback) {
actionPerformed(src, tar, callback) {
},
}
actionBack: function (tar, src, callback) {
actionBack(tar, src, callback) {
}
});
}
BI.ActionFactory = {
createAction: function (key, options) {

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

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

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

@ -19,14 +19,16 @@ BI.BehaviorFactory = {
* @class BI.Behavior
* @extends BI.OB
*/
BI.Behavior = BI.inherit(BI.OB, {
_defaultConfig: function () {
return BI.extend(BI.Behavior.superclass._defaultConfig.apply(this, arguments), {
rule: function () {return true;}
import OB from "../3.ob";
export default class Behavior extends OB {
_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
* @extends BI.Behavior
*/
BI.HighlightBehavior = BI.inherit(BI.Behavior, {
doBehavior: function (items) {
var args = Array.prototype.slice.call(arguments, 1),
import Behavior from "./0.behavior";
export default class HighlightBehavior extends Behavior {
doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
o = this.options;
BI.each(items, function (i, item) {
if (item instanceof BI.Single) {
var rule = o.rule(item.getValue(), item);
const rule = o.rule(item.getValue(), item);
function doBe (run) {
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
* @extends BI.Behavior
*/
BI.RedMarkBehavior = BI.inherit(BI.Behavior, {
doBehavior: function (items) {
var args = Array.prototype.slice.call(arguments, 1),
import Behavior from "./0.behavior";
export default class RedMarkBehavior extends Behavior {
doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
o = this.options;
BI.each(items, function (i, item) {
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
* @abstract
*/
BI.Controller = BI.inherit(BI.OB, {
});
BI.Controller.EVENT_CHANGE = "__EVENT_CHANGE__";
import OB from "../3.ob";
export default class Controller extends OB {
static EVENT_CHANGE = "__EVENT_CHANGE__";
}

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

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

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

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

87
src/core/controller/controller.drawer.js

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

82
src/core/controller/controller.layer.js

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

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

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

87
src/core/controller/controller.popover.js

@ -4,15 +4,14 @@
* @class BI.popoverController
* @extends BI.Controller
*/
BI.PopoverController = BI.inherit(BI.Controller, {
props: function () {
return {
modal: true, // 模态窗口
render: "body"
};
},
import Controller from "./0.controller";
export default class PopoverController extends Controller {
props = {
modal: true, // 模态窗口
render: "body"
}
init: function () {
init() {
this.modal = this.options.modal;
this.floatManager = {};
this.floatLayer = {};
@ -20,38 +19,38 @@ BI.PopoverController = BI.inherit(BI.Controller, {
this.floatOpened = {};
this.zindex = BI.zIndex_popover;
this.zindexMap = {};
},
}
create: function (name, options, context) {
create(name, options, context) {
if (this.has(name)) {
return this;
}
var popover = BI.createWidget(options || {}, {
const popover = BI.createWidget(options || {}, {
type: "bi.popover"
}, context);
this.add(name, popover, options, context);
return this;
},
}
open: function (name) {
open(name) {
if (!this.has(name)) {
return this;
}
if (!this.floatOpened[name]) {
this.floatOpened[name] = true;
var container = this.floatContainer[name];
const container = this.floatContainer[name];
container.element.css("zIndex", this.zindex++);
this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]);
this.zindexMap[name] = this.zindex;
this.modal && container.element.__buildZIndexMask__(this.zindex++);
this.get(name).setZindex(this.zindex++);
this.floatContainer[name].visible();
var popover = this.get(name);
const popover = this.get(name);
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();
var w = popover.element.width(), h = popover.element.height();
var left = (W - w) / 2, top = (H - h) / 2;
const w = popover.element.width(), h = popover.element.height();
const left = (W - w) / 2, top = (H - h) / 2;
if (left < 0) {
left = 0;
}
@ -65,9 +64,9 @@ BI.PopoverController = BI.inherit(BI.Controller, {
});
}
return this;
},
}
close: function (name) {
close(name) {
if (!this.has(name)) {
return this;
}
@ -77,22 +76,21 @@ BI.PopoverController = BI.inherit(BI.Controller, {
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}
return this;
},
}
show: function (name) {
show(name) {
return this.open(name);
},
}
hide: function (name) {
hide(name) {
return this.close(name);
},
}
isVisible: function (name) {
isVisible(name) {
return this.has(name) && this.floatOpened[name] === true;
},
}
add: function (name, popover, options, context) {
var self = this;
add(name, popover, options, context) {
options || (options = {});
if (this.has(name)) {
return this;
@ -113,9 +111,7 @@ BI.PopoverController = BI.inherit(BI.Controller, {
});
this.floatManager[name] = popover;
(function (key) {
popover.on(BI.Popover.EVENT_CLOSE, function () {
self.close(key);
});
popover.on(BI.Popover.EVENT_CLOSE, () => self.close(key));
})(name);
BI.createWidget({
type: "bi.absolute",
@ -129,17 +125,17 @@ BI.PopoverController = BI.inherit(BI.Controller, {
}]
});
return this;
},
}
get: function (name) {
get(name) {
return this.floatManager[name];
},
}
has: function (name) {
has(name) {
return BI.isNotNull(this.floatManager[name]);
},
}
remove: function (name) {
remove(name) {
if (!this.has(name)) {
return this;
}
@ -151,13 +147,12 @@ BI.PopoverController = BI.inherit(BI.Controller, {
delete this.floatContainer[name];
delete this.floatOpened[name];
return this;
},
}
removeAll: function () {
var self = this;
BI.each(this.floatContainer, function (name, container) {
removeAll() {
BI.each(this.floatContainer, (name, container) => {
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.floatLayer = {};
@ -165,9 +160,9 @@ BI.PopoverController = BI.inherit(BI.Controller, {
this.floatOpened = {};
this.zindexMap = {};
return this;
},
}
_getZIndex: function () {
_getZIndex() {
return this.zindex++;
}
});
}

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

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

74
src/core/controller/controller.tooltips.js

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

54
src/core/index.js

@ -0,0 +1,54 @@
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";
BI.extend(BI, {
OB,
Widget,
Action,
ShowAction,
Behavior,
HighlightBehavior,
RedMarkBehavior,
Controller,
BroadcastController,
BubblesController,
DrawerController,
LayerController,
MaskersController,
PopoverController,
ResizeController,
TooltipsController,
});
export {
OB,
Widget,
Action,
ShowAction,
Behavior,
HighlightBehavior,
RedMarkBehavior,
Controller,
BroadcastController,
BubblesController,
DrawerController,
LayerController,
MaskersController,
PopoverController,
ResizeController,
TooltipsController,
}
Loading…
Cancel
Save