|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { Single } from "../0.single" |
|
|
|
|
import { emptyFn, shortcut, extend, isFunction, createWidget, Widget, isObject, Controller } from "../../../core" |
|
|
|
|
import { Single } from "../0.single"; |
|
|
|
|
import { emptyFn, shortcut, extend, isFunction, createWidget, Widget, isObject, Controller } from "../../../core"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* guy |
|
|
|
@ -10,7 +10,6 @@ import { emptyFn, shortcut, extend, isFunction, createWidget, Widget, isObject,
|
|
|
|
|
*/ |
|
|
|
|
@shortcut() |
|
|
|
|
export class BasicButton extends Single { |
|
|
|
|
|
|
|
|
|
static xtype = "bi.basic_button"; |
|
|
|
|
|
|
|
|
|
static EVENT_CHANGE = "BasicButton.EVENT_CHANGE"; |
|
|
|
@ -19,7 +18,7 @@ export class BasicButton extends Single {
|
|
|
|
|
const conf = super._defaultConfig(arguments); |
|
|
|
|
|
|
|
|
|
return extend(conf, { |
|
|
|
|
_baseCls: (conf._baseCls || "") + " bi-basic-button" + (conf.invalid ? "" : " cursor-pointer") + ((BI.isIE() && BI.getIEVersion() < 10) ? " hack" : ""), |
|
|
|
|
_baseCls: `${conf._baseCls || ""} bi-basic-button${conf.invalid ? "" : " cursor-pointer"}${(BI.isIE() && BI.getIEVersion() < 10) ? " hack" : ""}`, |
|
|
|
|
// el: {} // 可以通过el来创建button元素
|
|
|
|
|
value: "", |
|
|
|
|
stopEvent: false, |
|
|
|
@ -35,7 +34,7 @@ export class BasicButton extends Single {
|
|
|
|
|
trigger: null, |
|
|
|
|
handler: emptyFn, |
|
|
|
|
bubble: null, |
|
|
|
|
debounce: true |
|
|
|
|
debounce: true, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -50,7 +49,7 @@ export class BasicButton extends Single {
|
|
|
|
|
this._createShadow(); |
|
|
|
|
} |
|
|
|
|
if (opts.level) { |
|
|
|
|
this.element.addClass("button-" + opts.level); |
|
|
|
|
this.element.addClass(`button-${opts.level}`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -92,7 +91,7 @@ export class BasicButton extends Single {
|
|
|
|
|
}], |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.element.mouseup(() => { |
|
|
|
|
if (!this._hover && !o.isShadowShowingOnSelected) { |
|
|
|
@ -100,7 +99,7 @@ export class BasicButton extends Single {
|
|
|
|
|
this.$mask.invisible(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.element.on("mouseenter." + this.getName(), (e) => { |
|
|
|
|
this.element.on(`mouseenter.${this.getName()}`, e => { |
|
|
|
|
if (this.element.__isMouseInBounds__(e)) { |
|
|
|
|
if (this.isEnabled() && !this._hover && (o.isShadowShowingOnSelected || !this.isSelected())) { |
|
|
|
|
assertMask(); |
|
|
|
@ -108,7 +107,7 @@ export class BasicButton extends Single {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.element.on("mousemove." + this.getName(), (e) => { |
|
|
|
|
this.element.on(`mousemove.${this.getName()}`, e => { |
|
|
|
|
if (!this.element.__isMouseInBounds__(e)) { |
|
|
|
|
if (this.isEnabled() && !this._hover) { |
|
|
|
|
assertMask(); |
|
|
|
@ -116,7 +115,7 @@ export class BasicButton extends Single {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.element.on("mouseleave." + this.getName(), () => { |
|
|
|
|
this.element.on(`mouseleave.${this.getName()}`, () => { |
|
|
|
|
if (this.isEnabled() && !this._hover) { |
|
|
|
|
assertMask(); |
|
|
|
|
this.$mask.invisible(); |
|
|
|
@ -139,9 +138,9 @@ export class BasicButton extends Single {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return bubble; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const clk = (e) => { |
|
|
|
|
const clk = e => { |
|
|
|
|
ev(e); |
|
|
|
|
if (!this.isEnabled() || !this.isValid()) { |
|
|
|
|
return; |
|
|
|
@ -161,7 +160,7 @@ export class BasicButton extends Single {
|
|
|
|
|
trigger: "", |
|
|
|
|
// bubble的提示不需要一直存在在界面上
|
|
|
|
|
destroyWhenHide: true, |
|
|
|
|
ref: (_ref) => { |
|
|
|
|
ref: _ref => { |
|
|
|
|
this.combo = _ref; |
|
|
|
|
}, |
|
|
|
|
el: { |
|
|
|
@ -171,7 +170,7 @@ export class BasicButton extends Single {
|
|
|
|
|
popup: { |
|
|
|
|
type: "bi.text_bubble_bar_popup_view", |
|
|
|
|
text: getBubble(), |
|
|
|
|
ref: (_ref) => { |
|
|
|
|
ref: _ref => { |
|
|
|
|
popup = _ref; |
|
|
|
|
}, |
|
|
|
|
listeners: [{ |
|
|
|
@ -187,7 +186,7 @@ export class BasicButton extends Single {
|
|
|
|
|
}, |
|
|
|
|
listeners: [{ |
|
|
|
|
eventName: BI.BubbleCombo.EVENT_BEFORE_POPUPVIEW, |
|
|
|
|
action: function () { |
|
|
|
|
action () { |
|
|
|
|
popup.populate(getBubble()); |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
@ -208,19 +207,21 @@ export class BasicButton extends Single {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
onClick.apply(this, arguments); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const triggerArr = (o.trigger || "").split(","); |
|
|
|
|
triggerArr.forEach((trigger) => { |
|
|
|
|
triggerArr.forEach(trigger => { |
|
|
|
|
let mouseDown = false; |
|
|
|
|
let selected = false; |
|
|
|
|
let interval; |
|
|
|
|
switch (trigger) { |
|
|
|
|
case "mouseup": |
|
|
|
|
hand.mousedown(function () { |
|
|
|
|
hand.mousedown(() => { |
|
|
|
|
mouseDown = true; |
|
|
|
|
}); |
|
|
|
|
hand.mouseup(function (e) { |
|
|
|
|
hand.mouseup(e => { |
|
|
|
|
if (mouseDown === true) { |
|
|
|
|
clk(e); |
|
|
|
|
} |
|
|
|
@ -230,17 +231,16 @@ export class BasicButton extends Single {
|
|
|
|
|
break; |
|
|
|
|
case "mousedown": |
|
|
|
|
// let mouseDown = false;
|
|
|
|
|
let selected = false; |
|
|
|
|
hand.mousedown((e) => { |
|
|
|
|
hand.mousedown(e => { |
|
|
|
|
// if (e.button === 0) {
|
|
|
|
|
Widget._renderEngine.createElement(document).bind("mouseup." + this.getName(), (e) => { |
|
|
|
|
Widget._renderEngine.createElement(document).bind(`mouseup.${this.getName()}`, e => { |
|
|
|
|
// if (e.button === 0) {
|
|
|
|
|
if (BI.DOM.isExist(this) && !hand.__isMouseInBounds__(e) && mouseDown === true && !selected) { |
|
|
|
|
// self.setSelected(!self.isSelected());
|
|
|
|
|
this._trigger(); |
|
|
|
|
} |
|
|
|
|
mouseDown = false; |
|
|
|
|
Widget._renderEngine.createElement(document).unbind("mouseup." + this.getName()); |
|
|
|
|
Widget._renderEngine.createElement(document).unbind(`mouseup.${this.getName()}`); |
|
|
|
|
// }
|
|
|
|
|
}); |
|
|
|
|
if (mouseDown === true) { |
|
|
|
@ -255,14 +255,14 @@ export class BasicButton extends Single {
|
|
|
|
|
ev(e); |
|
|
|
|
// }
|
|
|
|
|
}); |
|
|
|
|
hand.mouseup((e) => { |
|
|
|
|
hand.mouseup(e => { |
|
|
|
|
// if (e.button === 0) {
|
|
|
|
|
if (BI.DOM.isExist(this) && mouseDown === true && selected === true) { |
|
|
|
|
clk(e); |
|
|
|
|
} |
|
|
|
|
mouseDown = false; |
|
|
|
|
selected = false; |
|
|
|
|
Widget._renderEngine.createElement(document).unbind("mouseup." + this.getName()); |
|
|
|
|
Widget._renderEngine.createElement(document).unbind(`mouseup.${this.getName()}`); |
|
|
|
|
// }
|
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
@ -270,13 +270,12 @@ export class BasicButton extends Single {
|
|
|
|
|
hand.dblclick(clk); |
|
|
|
|
break; |
|
|
|
|
case "lclick": |
|
|
|
|
let interval; |
|
|
|
|
hand.mousedown((e) => { |
|
|
|
|
Widget._renderEngine.createElement(document).bind("mouseup." + this.getName(), () => { |
|
|
|
|
hand.mousedown(e => { |
|
|
|
|
Widget._renderEngine.createElement(document).bind(`mouseup.${this.getName()}`, () => { |
|
|
|
|
interval && clearInterval(interval); |
|
|
|
|
interval = null; |
|
|
|
|
mouseDown = false; |
|
|
|
|
Widget._renderEngine.createElement(document).unbind("mouseup." + this.getName()); |
|
|
|
|
Widget._renderEngine.createElement(document).unbind(`mouseup.${this.getName()}`); |
|
|
|
|
}); |
|
|
|
|
if (mouseDown === true) { |
|
|
|
|
return; |
|
|
|
@ -287,8 +286,8 @@ export class BasicButton extends Single {
|
|
|
|
|
if (this.isOnce() && this.isSelected()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
interval = setInterval(function () { |
|
|
|
|
clk(e) |
|
|
|
|
interval = setInterval(() => { |
|
|
|
|
clk(e); |
|
|
|
|
}, 180); |
|
|
|
|
mouseDown = true; |
|
|
|
|
ev(e); |
|
|
|
@ -296,13 +295,13 @@ export class BasicButton extends Single {
|
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
if (o.stopEvent || o.stopPropagation) { |
|
|
|
|
hand.mousedown(function (e) { |
|
|
|
|
hand.mousedown(e => { |
|
|
|
|
ev(e); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
hand.click(clk); |
|
|
|
|
// enter键等同于点击
|
|
|
|
|
o.attributes && o.attributes.zIndex >= 0 && hand.keyup(function (e) { |
|
|
|
|
o.attributes && o.attributes.zIndex >= 0 && hand.keyup(e => { |
|
|
|
|
if (e.keyCode === BI.KeyCode.ENTER) { |
|
|
|
|
clk(e); |
|
|
|
|
} |
|
|
|
@ -312,9 +311,9 @@ export class BasicButton extends Single {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 之后的300ms点击无效
|
|
|
|
|
let onClick = o.debounce ? BI.debounce(this._doClick, BI.EVENT_RESPONSE_TIME, { |
|
|
|
|
"leading": true, |
|
|
|
|
"trailing": false, |
|
|
|
|
const onClick = o.debounce ? BI.debounce(this._doClick, BI.EVENT_RESPONSE_TIME, { |
|
|
|
|
leading: true, |
|
|
|
|
trailing: false, |
|
|
|
|
}) : this._doClick; |
|
|
|
|
|
|
|
|
|
function ev(e) { |
|
|
|
@ -325,10 +324,6 @@ export class BasicButton extends Single {
|
|
|
|
|
e.stopPropagation(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_trigger(e) { |
|
|
|
@ -458,7 +453,7 @@ export class BasicButton extends Single {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
empty() { |
|
|
|
|
Widget._renderEngine.createElement(document).unbind("mouseup." + this.getName()); |
|
|
|
|
Widget._renderEngine.createElement(document).unbind(`mouseup.${this.getName()}`); |
|
|
|
|
super.empty.apply(this, arguments); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|