Browse Source

KERNEL-13928 refactor: 重构一些用到的方法

es6
impact 2 years ago
parent
commit
ff266d9864
  1. 54
      src/base/0.base.js
  2. 6
      src/core/controller/controller.tooltips.js
  3. 3
      src/core/index.js
  4. 34
      src/core/loader/loader.style.js

54
src/base/0.base.js

@ -1,9 +1,45 @@
BI.Resizers = new BI.ResizeController(); import {
BI.Layers = new BI.LayerController(); BroadcastController,
BI.Maskers = new BI.MaskersController(); BubblesController,
BI.Bubbles = new BI.BubblesController(); DrawerController,
BI.Tooltips = new BI.TooltipsController(); LayerController,
BI.Popovers = new BI.PopoverController(); MaskersController,
BI.Drawers = new BI.DrawerController(); PopoverController,
BI.Broadcasts = new BI.BroadcastController(); ResizeController,
BI.StyleLoaders = new BI.StyleLoaderManager(); TooltipsController,
StyleLoaderManager
} from "../core";
const Resizers = new ResizeController();
const Layers = new LayerController();
const Maskers = new MaskersController();
const Bubbles = new BubblesController();
const Tooltips = new TooltipsController();
const Popovers = new PopoverController();
const Drawers = new DrawerController();
const Broadcasts = new BroadcastController();
const StyleLoaders = new StyleLoaderManager();
BI.extend(BI, {
Resizers,
Layers,
Maskers,
Bubbles,
Tooltips,
Popovers,
Drawers,
Broadcasts,
StyleLoaders
});
export {
Resizers,
Layers,
Maskers,
Bubbles,
Tooltips,
Popovers,
Drawers,
Broadcasts,
StyleLoaders
};

6
src/core/controller/controller.tooltips.js

@ -38,13 +38,15 @@ export default class TooltipsController extends Controller {
if (!this.has(name)) { if (!this.has(name)) {
this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body")); this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body"));
} }
const offset = context.element.offset();
let top;
if (!opt.belowMouse) { if (!opt.belowMouse) {
const offset = context.element.offset();
const 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;
} }
const top = offset.top + bounds.height + 5; top = offset.top + bounds.height + 5;
} }
const tooltip = this.get(name); const tooltip = this.get(name);
tooltip.element.css({ tooltip.element.css({

3
src/core/index.js

@ -15,6 +15,7 @@ import MaskersController from "./controller/controller.masker";
import PopoverController from "./controller/controller.popover"; import PopoverController from "./controller/controller.popover";
import ResizeController from "./controller/controller.resizer"; import ResizeController from "./controller/controller.resizer";
import TooltipsController from "./controller/controller.tooltips"; import TooltipsController from "./controller/controller.tooltips";
import StyleLoaderManager from "./loader/loader.style";
BI.extend(BI, { BI.extend(BI, {
OB, OB,
@ -33,6 +34,7 @@ BI.extend(BI, {
PopoverController, PopoverController,
ResizeController, ResizeController,
TooltipsController, TooltipsController,
StyleLoaderManager,
}); });
export { export {
@ -53,4 +55,5 @@ export {
PopoverController, PopoverController,
ResizeController, ResizeController,
TooltipsController, TooltipsController,
StyleLoaderManager,
} }

34
src/core/loader/loader.style.js

@ -4,21 +4,23 @@
* Created by GUY on 2015/9/7. * Created by GUY on 2015/9/7.
* @class * @class
*/ */
BI.StyleLoaderManager = BI.inherit(BI.OB, { import OB from "../3.ob";
_defaultConfig: function () {
return BI.extend(BI.StyleLoaderManager.superclass._defaultConfig.apply(this, arguments), {});
},
_init: function () { export default class StyleLoaderManager extends OB {
BI.StyleLoaderManager.superclass._init.apply(this, arguments); _defaultConfig() {
return BI.extend(super._defaultConfig(arguments), {});
}
_init() {
super._init(arguments);
this.stylesManager = {}; this.stylesManager = {};
}, }
loadStyle: function (name, styleString) { loadStyle(name, styleString) {
if(!_global.document) { if(!_global.document) {
return; return;
} }
var d = document, styles = d.createElement("style"); const d = document, styles = d.createElement("style");
d.getElementsByTagName("head")[0].appendChild(styles); d.getElementsByTagName("head")[0].appendChild(styles);
styles.setAttribute("type", "text/css"); styles.setAttribute("type", "text/css");
if (styles.styleSheet) { if (styles.styleSheet) {
@ -29,17 +31,17 @@ BI.StyleLoaderManager = BI.inherit(BI.OB, {
this.stylesManager[name] = styles; this.stylesManager[name] = styles;
return this; return this;
}, }
get: function (name) { get(name) {
return this.stylesManager[name]; return this.stylesManager[name];
}, }
has: function (name) { has(name) {
return this.stylesManager[name] != null; return this.stylesManager[name] != null;
}, }
removeStyle: function (name) { removeStyle(name) {
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -47,4 +49,4 @@ BI.StyleLoaderManager = BI.inherit(BI.OB, {
delete this.stylesManager[name]; delete this.stylesManager[name];
return this; return this;
} }
}); }

Loading…
Cancel
Save