|
|
|
@ -14,14 +14,14 @@ import {
|
|
|
|
|
isNull, |
|
|
|
|
isFunction, |
|
|
|
|
contains, |
|
|
|
|
bind |
|
|
|
|
bind, |
|
|
|
|
Events, |
|
|
|
|
emptyFn, |
|
|
|
|
LogicFactory, |
|
|
|
|
EVENT_RESPONSE_TIME, |
|
|
|
|
EVENT_BLUR |
|
|
|
|
} from "@/core"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @class BI.Bubble |
|
|
|
|
* @extends BI.Widget |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
@shortcut() |
|
|
|
|
export class Bubble extends Widget { |
|
|
|
|
static xtype = "bi.bubble"; |
|
|
|
@ -65,7 +65,7 @@ export class Bubble extends Widget {
|
|
|
|
|
adjustLength: 0, // 调整的距离
|
|
|
|
|
adjustXOffset: 0, |
|
|
|
|
adjustYOffset: 0, |
|
|
|
|
hideChecker: BI.emptyFn, |
|
|
|
|
hideChecker: emptyFn, |
|
|
|
|
offsetStyle: "left", // left,right,center
|
|
|
|
|
el: {}, |
|
|
|
|
popup: {}, |
|
|
|
@ -83,32 +83,32 @@ export class Bubble extends Widget {
|
|
|
|
|
}); |
|
|
|
|
this.combo.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { |
|
|
|
|
if (this.isEnabled() && this.isValid()) { |
|
|
|
|
if (type === BI.Events.EXPAND) { |
|
|
|
|
if (type === Events.EXPAND) { |
|
|
|
|
this._popupView(); |
|
|
|
|
} |
|
|
|
|
if (type === BI.Events.COLLAPSE) { |
|
|
|
|
if (type === Events.COLLAPSE) { |
|
|
|
|
this._hideView(); |
|
|
|
|
} |
|
|
|
|
if (type === BI.Events.EXPAND) { |
|
|
|
|
if (type === Events.EXPAND) { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); |
|
|
|
|
this.fireEvent(Bubble.EVENT_EXPAND); |
|
|
|
|
} |
|
|
|
|
if (type === BI.Events.COLLAPSE) { |
|
|
|
|
if (type === Events.COLLAPSE) { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); |
|
|
|
|
this.isViewVisible() && this.fireEvent(Bubble.EVENT_COLLAPSE); |
|
|
|
|
} |
|
|
|
|
if (type === BI.Events.CLICK) { |
|
|
|
|
if (type === Events.CLICK) { |
|
|
|
|
this.fireEvent(Bubble.EVENT_TRIGGER_CHANGE, obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { |
|
|
|
|
this.element.addClass(hoverClass); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, e => { |
|
|
|
|
if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { |
|
|
|
|
this.element.removeClass(hoverClass); |
|
|
|
|
} |
|
|
|
@ -120,7 +120,7 @@ export class Bubble extends Widget {
|
|
|
|
|
element: this, |
|
|
|
|
scrolly: false, |
|
|
|
|
}, |
|
|
|
|
BI.LogicFactory.createLogic( |
|
|
|
|
LogicFactory.createLogic( |
|
|
|
|
"vertical", |
|
|
|
|
extend(logic, { |
|
|
|
|
items: [{ el: this.combo }], |
|
|
|
@ -146,7 +146,7 @@ export class Bubble extends Widget {
|
|
|
|
|
const { stopEvent, stopPropagation, toggle } = this.options; |
|
|
|
|
const evs = (this.options.trigger || "").split(","); |
|
|
|
|
|
|
|
|
|
const st = (e) => { |
|
|
|
|
const st = e => { |
|
|
|
|
if (stopEvent) { |
|
|
|
|
e.stopEvent(); |
|
|
|
|
} |
|
|
|
@ -157,7 +157,7 @@ export class Bubble extends Widget {
|
|
|
|
|
|
|
|
|
|
let enterPopup = false; |
|
|
|
|
|
|
|
|
|
const hide = (e) => { |
|
|
|
|
const hide = e => { |
|
|
|
|
if ( |
|
|
|
|
this.isEnabled() && |
|
|
|
|
this.isValid() && |
|
|
|
@ -166,7 +166,7 @@ export class Bubble extends Widget {
|
|
|
|
|
toggle === true |
|
|
|
|
) { |
|
|
|
|
this._hideView(e); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.COLLAPSE, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_COLLAPSE); |
|
|
|
|
} |
|
|
|
|
this.popupView && |
|
|
|
@ -178,18 +178,18 @@ export class Bubble extends Widget {
|
|
|
|
|
let debounced; |
|
|
|
|
switch (ev) { |
|
|
|
|
case "hover": |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { |
|
|
|
|
this._popupView(e); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_EXPAND); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, e => { |
|
|
|
|
if (this.popupView) { |
|
|
|
|
this.popupView.element.on(`mouseenter.${this.getName()}`, (e) => { |
|
|
|
|
this.popupView.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
enterPopup = true; |
|
|
|
|
this.popupView.element.on(`mouseleave.${this.getName()}`, (e) => { |
|
|
|
|
this.popupView.element.on(`mouseleave.${this.getName()}`, e => { |
|
|
|
|
hide(e); |
|
|
|
|
}); |
|
|
|
|
this.popupView.element.off(`mouseenter.${this.getName()}`); |
|
|
|
@ -204,7 +204,7 @@ export class Bubble extends Widget {
|
|
|
|
|
break; |
|
|
|
|
case "click": |
|
|
|
|
debounced = debounce( |
|
|
|
|
(e) => { |
|
|
|
|
e => { |
|
|
|
|
if (this.combo.element.__isMouseInBounds__(e)) { |
|
|
|
|
if ( |
|
|
|
|
this.isEnabled() && |
|
|
|
@ -217,29 +217,29 @@ export class Bubble extends Widget {
|
|
|
|
|
// }
|
|
|
|
|
toggle ? this._toggle(e) : this._popupView(e); |
|
|
|
|
if (this.isViewVisible()) { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_EXPAND); |
|
|
|
|
} else { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.COLLAPSE, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_COLLAPSE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
BI.EVENT_RESPONSE_TIME, |
|
|
|
|
EVENT_RESPONSE_TIME, |
|
|
|
|
{ |
|
|
|
|
leading: true, |
|
|
|
|
trailing: false, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
this.element.off(`${ev}.${this.getName()}`).on(`${ev}.${this.getName()}`, (e) => { |
|
|
|
|
this.element.off(`${ev}.${this.getName()}`).on(`${ev}.${this.getName()}`, e => { |
|
|
|
|
debounced(e); |
|
|
|
|
st(e); |
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
|
case "click-hover": |
|
|
|
|
debounced = debounce( |
|
|
|
|
(e) => { |
|
|
|
|
e => { |
|
|
|
|
if (this.combo.element.__isMouseInBounds__(e)) { |
|
|
|
|
if ( |
|
|
|
|
this.isEnabled() && |
|
|
|
@ -252,27 +252,27 @@ export class Bubble extends Widget {
|
|
|
|
|
// }
|
|
|
|
|
this._popupView(e); |
|
|
|
|
if (this.isViewVisible()) { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_EXPAND); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
BI.EVENT_RESPONSE_TIME, |
|
|
|
|
EVENT_RESPONSE_TIME, |
|
|
|
|
{ |
|
|
|
|
leading: true, |
|
|
|
|
trailing: false, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
this.element.off(`click.${this.getName()}`).on(`click.${this.getName()}`, (e) => { |
|
|
|
|
this.element.off(`click.${this.getName()}`).on(`click.${this.getName()}`, e => { |
|
|
|
|
debounced(e); |
|
|
|
|
st(e); |
|
|
|
|
}); |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, e => { |
|
|
|
|
if (this.popupView) { |
|
|
|
|
this.popupView.element.on(`mouseenter.${this.getName()}`, (e) => { |
|
|
|
|
this.popupView.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
enterPopup = true; |
|
|
|
|
this.popupView.element.on(`mouseleave.${this.getName()}`, (e) => { |
|
|
|
|
this.popupView.element.on(`mouseleave.${this.getName()}`, e => { |
|
|
|
|
hide(e); |
|
|
|
|
}); |
|
|
|
|
this.popupView.element.off(`mouseenter.${this.getName()}`); |
|
|
|
@ -286,10 +286,10 @@ export class Bubble extends Widget {
|
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
|
case "hover-click": |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, (e) => { |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { |
|
|
|
|
this._popupView(e); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.EXPAND, "", this.combo); |
|
|
|
|
this.fireEvent(Bubble.EVENT_EXPAND); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -319,7 +319,7 @@ export class Bubble extends Widget {
|
|
|
|
|
this |
|
|
|
|
); |
|
|
|
|
this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { |
|
|
|
|
if (type === BI.Events.CLICK) { |
|
|
|
|
if (type === Events.CLICK) { |
|
|
|
|
this.combo.setValue(this.getValue()); |
|
|
|
|
this.fireEvent(Bubble.EVENT_CHANGE, value, obj); |
|
|
|
|
} |
|
|
|
@ -404,7 +404,7 @@ export class Bubble extends Widget {
|
|
|
|
|
.createElement(document) |
|
|
|
|
.unbind(`mousedown.${this.getName()}`) |
|
|
|
|
.unbind(`mousewheel.${this.getName()}`); |
|
|
|
|
BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind(`blur.${this.getName()}`); |
|
|
|
|
EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind(`blur.${this.getName()}`); |
|
|
|
|
this.fireEvent(Bubble.EVENT_AFTER_HIDEVIEW); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -427,7 +427,7 @@ export class Bubble extends Widget {
|
|
|
|
|
options: { |
|
|
|
|
offset: () => [adjustXOffset, (showArrow ? 12 : 0) + (adjustYOffset + adjustLength)], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
]; |
|
|
|
|
if (this.options.showArrow) { |
|
|
|
|
modifiers.push({ |
|
|
|
@ -448,11 +448,11 @@ export class Bubble extends Widget {
|
|
|
|
|
|
|
|
|
|
this.element.addClass(this.options.comboClass); |
|
|
|
|
hideWhenClickOutside && Widget._renderEngine.createElement(document).unbind(`mousedown.${this.getName()}`); |
|
|
|
|
BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind(`blur.${this.getName()}`); |
|
|
|
|
EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind(`blur.${this.getName()}`); |
|
|
|
|
|
|
|
|
|
hideWhenClickOutside && |
|
|
|
|
Widget._renderEngine.createElement(document).bind(`mousedown.${this.getName()}`, bind(this._hideIf, this)); |
|
|
|
|
BI.EVENT_BLUR && |
|
|
|
|
EVENT_BLUR && |
|
|
|
|
hideWhenBlur && |
|
|
|
|
Widget._renderEngine.createElement(window).bind(`blur.${this.getName()}`, bind(this._hideIf, this)); |
|
|
|
|
this.fireEvent(Bubble.EVENT_AFTER_POPUPVIEW); |
|
|
|
@ -500,8 +500,8 @@ export class Bubble extends Widget {
|
|
|
|
|
|
|
|
|
|
populate(items) { |
|
|
|
|
this._assertPopupView(); |
|
|
|
|
this.popupView.populate.apply(this.popupView, arguments); |
|
|
|
|
this.combo.populate && this.combo.populate.apply(this.combo, arguments); |
|
|
|
|
this.popupView.populate(...arguments); |
|
|
|
|
this.combo.populate && this.combo.populate(...arguments); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_setEnable(arg) { |
|
|
|
|