Browse Source

BI-67919 refactor: BI.config 接收第三个参数 config widget 可选是否使用最新

es6
Young 5 years ago
parent
commit
c5b31b6d10
  1. 4
      src/core/inject.js
  2. 30
      src/core/platform/web/config.js
  3. 6
      src/core/plugin.js

4
src/core/inject.js

@ -48,7 +48,7 @@
}; };
var configFunctions = {}; var configFunctions = {};
BI.config = function (type, configFn) { BI.config = function (type, configFn, opt) {
if (BI.initialized) { if (BI.initialized) {
if (constantInjection[type]) { if (constantInjection[type]) {
return (constantInjection[type] = configFn(constantInjection[type])); return (constantInjection[type] = configFn(constantInjection[type]));
@ -63,7 +63,7 @@
} }
return configFn(providers[type]); return configFn(providers[type]);
} }
return BI.Plugin.configWidget(type, configFn); return BI.Plugin.configWidget(type, configFn, opt);
} }
if (!configFunctions[type]) { if (!configFunctions[type]) {
configFunctions[type] = []; configFunctions[type] = [];

30
src/core/platform/web/config.js

@ -13,7 +13,7 @@ BI.prepares.push(function () {
} }
return _isSupportFlex; return _isSupportFlex;
}; };
BI.Plugin.registerWidget("bi.horizontal", function (ob) { BI.Plugin.configWidget("bi.horizontal", function (ob) {
var isIE = BI.isIE(), supportFlex = isSupportFlex(), isLessIE8 = isIE && BI.getIEVersion() < 8; var isIE = BI.isIE(), supportFlex = isSupportFlex(), isLessIE8 = isIE && BI.getIEVersion() < 8;
// center_adapt // center_adapt
if (ob.verticalAlign === BI.VerticalAlign.Middle && ob.horizontalAlign === BI.HorizontalAlign.Center) { if (ob.verticalAlign === BI.VerticalAlign.Middle && ob.horizontalAlign === BI.HorizontalAlign.Center) {
@ -44,7 +44,7 @@ BI.prepares.push(function () {
} }
return ob; return ob;
}); });
BI.Plugin.registerWidget("bi.center_adapt", function (ob) { BI.Plugin.configWidget("bi.center_adapt", function (ob) {
var isIE = BI.isIE(), supportFlex = isSupportFlex(), justOneItem = (ob.items && ob.items.length <= 1); var isIE = BI.isIE(), supportFlex = isSupportFlex(), justOneItem = (ob.items && ob.items.length <= 1);
if (!isIE && supportFlex && justOneItem) { if (!isIE && supportFlex && justOneItem) {
// 有滚动条的情况下需要用到flex_scrollable_center_adapt布局 // 有滚动条的情况下需要用到flex_scrollable_center_adapt布局
@ -60,7 +60,7 @@ BI.prepares.push(function () {
} }
return ob; return ob;
}); });
BI.Plugin.registerWidget("bi.vertical_adapt", function (ob) { BI.Plugin.configWidget("bi.vertical_adapt", function (ob) {
var isIE = BI.isIE(), supportFlex = isSupportFlex(); var isIE = BI.isIE(), supportFlex = isSupportFlex();
if (!isIE && supportFlex) { if (!isIE && supportFlex) {
// 有滚动条的情况下需要用到flex_scrollable_center_adapt布局 // 有滚动条的情况下需要用到flex_scrollable_center_adapt布局
@ -72,13 +72,13 @@ BI.prepares.push(function () {
} }
return BI.extend(ob, {type: "bi.inline_vertical_adapt"}); return BI.extend(ob, {type: "bi.inline_vertical_adapt"});
}); });
BI.Plugin.registerWidget("bi.horizontal_adapt", function (ob) { BI.Plugin.configWidget("bi.horizontal_adapt", function (ob) {
if (ob.items && ob.items.length <= 1) { if (ob.items && ob.items.length <= 1) {
return BI.extend(ob, {type: "bi.horizontal_auto"}); return BI.extend(ob, {type: "bi.horizontal_auto"});
} }
return ob; return ob;
}); });
BI.Plugin.registerWidget("bi.float_center_adapt", function (ob) { BI.Plugin.configWidget("bi.float_center_adapt", function (ob) {
if (!BI.isIE() && isSupportFlex()) { if (!BI.isIE() && isSupportFlex()) {
// 有滚动条的情况下需要用到flex_scrollable_center_adapt布局 // 有滚动条的情况下需要用到flex_scrollable_center_adapt布局
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
@ -90,57 +90,57 @@ BI.prepares.push(function () {
return BI.extend(ob, {type: "bi.inline_center_adapt"}); return BI.extend(ob, {type: "bi.inline_center_adapt"});
}); });
BI.Plugin.registerWidget("bi.flex_horizontal", function (ob) { BI.Plugin.configWidget("bi.flex_horizontal", function (ob) {
if (ob.scrollable === true || ob.scrolly === true) { if (ob.scrollable === true || ob.scrolly === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_vertical", function (ob) { BI.Plugin.configWidget("bi.flex_vertical", function (ob) {
if (ob.scrollable === true || ob.scrollx === true) { if (ob.scrollable === true || ob.scrollx === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_horizontal_adapt", function (ob) { BI.Plugin.configWidget("bi.flex_horizontal_adapt", function (ob) {
if (ob.scrollable === true || ob.scrollx === true) { if (ob.scrollable === true || ob.scrollx === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal_adapt"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal_adapt"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_vertical_adapt", function (ob) { BI.Plugin.configWidget("bi.flex_vertical_adapt", function (ob) {
if (ob.scrollable === true || ob.scrolly === true) { if (ob.scrollable === true || ob.scrolly === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical_adapt"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical_adapt"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_horizontal_center_adapt", function (ob) { BI.Plugin.configWidget("bi.flex_horizontal_center_adapt", function (ob) {
if (ob.scrollable === true || ob.scrollx === true) { if (ob.scrollable === true || ob.scrollx === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal_adapt"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_horizontal_adapt"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_vertical_center_adapt", function (ob) { BI.Plugin.configWidget("bi.flex_vertical_center_adapt", function (ob) {
if (ob.scrollable === true || ob.scrolly === true) { if (ob.scrollable === true || ob.scrolly === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical_adapt"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_vertical_adapt"});
} }
}); });
BI.Plugin.registerWidget("bi.flex_center_adapt", function (ob) { BI.Plugin.configWidget("bi.flex_center_adapt", function (ob) {
if (ob.scrollable === true || ob.scrolly === true || ob.scrollx === true) { if (ob.scrollable === true || ob.scrolly === true || ob.scrollx === true) {
return BI.extend({}, ob, {type: "bi.flex_scrollable_center_adapt"}); return BI.extend({}, ob, {type: "bi.flex_scrollable_center_adapt"});
} }
}); });
BI.Plugin.registerWidget("bi.radio", function (ob) { BI.Plugin.configWidget("bi.radio", function (ob) {
if (BI.isIE() && BI.getIEVersion() < 9) { if (BI.isIE() && BI.getIEVersion() < 9) {
return BI.extend(ob, {type: "bi.image_radio"}); return BI.extend(ob, {type: "bi.image_radio"});
} }
return ob; return ob;
}); });
BI.Plugin.registerWidget("bi.checkbox", function (ob) { BI.Plugin.configWidget("bi.checkbox", function (ob) {
if (BI.isIE() && BI.getIEVersion() < 9) { if (BI.isIE() && BI.getIEVersion() < 9) {
return BI.extend(ob, {type: "bi.image_checkbox"}); return BI.extend(ob, {type: "bi.image_checkbox"});
} }
return ob; return ob;
}); });
BI.Plugin.registerWidget("bi.half_icon_button", function (ob) { BI.Plugin.configWidget("bi.half_icon_button", function (ob) {
if (BI.isIE() && BI.getIEVersion() < 9) { if (BI.isIE() && BI.getIEVersion() < 9) {
return ob; return ob;
} }

6
src/core/plugin.js

@ -39,13 +39,15 @@ BI.Plugin = BI.Plugin || {};
__GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(_.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]); __GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(_.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]);
}, },
configWidget: function (type, fn) { configWidget: function (type, fn, opt) {
if (!_ConfigPlugin[type]) { // opt.single: true 最后一次注册有效
if (!_ConfigPlugin[type] || (opt && opt.single)) {
_ConfigPlugin[type] = []; _ConfigPlugin[type] = [];
} }
_ConfigPlugin[type].push(fn); _ConfigPlugin[type].push(fn);
}, },
// Deprecated
registerWidget: function (type, fn) { registerWidget: function (type, fn) {
if (!_WidgetsPlugin[type]) { if (!_WidgetsPlugin[type]) {
_WidgetsPlugin[type] = []; _WidgetsPlugin[type] = [];

Loading…
Cancel
Save