Browse Source

Pull request #1364: 无JIRA feat: BI.Plugin 中全局组件配置改为数组

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit 'd99a4a7ae3d60dc5ea202ebb684b505d4512eea7':
  无JIRA feat: BI.Plugin 中全局组件配置改为数组
master
parent
commit
fe3034f2cd
  1. 27
      src/core/plugin.js

27
src/core/plugin.js

@ -3,13 +3,18 @@ BI.Plugin = BI.Plugin || {};
var _WidgetsPlugin = {};
var _ObjectPlugin = {};
var _ConfigPlugin = {};
var _GlobalWidgetConfigFn, _GlobalObjectConfigFn;
var _GlobalWidgetConfigFns = [];
var __GlobalObjectConfigFns = [];
BI.extend(BI.Plugin, {
getWidget: function (type, options) {
if (_GlobalWidgetConfigFn) {
_GlobalWidgetConfigFn(type, options);
if (_GlobalWidgetConfigFns.length > 0) {
var fns = _GlobalWidgetConfigFns.slice(0);
for (var i = fns.length - 1; i >= 0; i--) {
fns[i](type, options);
}
}
var res;
if (_ConfigPlugin[type]) {
for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) {
@ -30,8 +35,8 @@ BI.Plugin = BI.Plugin || {};
},
config: function (widgetConfigFn, objectConfigFn) {
_GlobalWidgetConfigFn = widgetConfigFn;
_GlobalObjectConfigFn = objectConfigFn;
_GlobalWidgetConfigFns = _GlobalWidgetConfigFns.concat(_.isArray(widgetConfigFn) ? widgetConfigFn : [widgetConfigFn]);
__GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(_.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]);
},
configWidget: function (type, fn) {
@ -56,15 +61,19 @@ BI.Plugin = BI.Plugin || {};
},
getObject: function (type, object) {
if (_GlobalObjectConfigFn) {
_GlobalObjectConfigFn(type, object);
if (__GlobalObjectConfigFns.length > 0) {
var fns = __GlobalObjectConfigFns.slice(0);
for (var i = fns.length - 1; i >= 0; i--) {
fns[i](type, object);
}
}
if (_ObjectPlugin[type]) {
var res;
for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) {
if (res = _ObjectPlugin[type][i](object)) {
object = res;
};
}
}
}
return res || object;
@ -84,4 +93,4 @@ BI.Plugin = BI.Plugin || {};
delete _ObjectPlugin[type];
}
});
})();
})();

Loading…
Cancel
Save