Browse Source

KERNEL-13158: 优化button

es6
guy 2 years ago
parent
commit
cd0ce2d02a
  1. 31
      src/base/single/button/button.basic.js

31
src/base/single/button/button.basic.js

@ -184,7 +184,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
var mouseDown = false; var mouseDown = false;
var interval; var interval;
hand.mousedown(function (e) { hand.mousedown(function (e) {
BI.Widget._renderEngine.createElement(document).bind("mouseup." + self.getName(), function (e) { BI.Widget._renderEngine.createElement(document).bind("mouseup." + self.getName(), function () {
interval && clearInterval(interval); interval && clearInterval(interval);
interval = null; interval = null;
mouseDown = false; mouseDown = false;
@ -193,13 +193,14 @@ BI.BasicButton = BI.inherit(BI.Single, {
if (mouseDown === true) { if (mouseDown === true) {
return; return;
} }
if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { if (!self.isEnabled() || !self.isValid()) {
return;
}
if (self.isOnce() && self.isSelected()) {
return; return;
} }
interval = setInterval(function () { interval = setInterval(function () {
if (self.isEnabled()) { clk(e)
self.doClick();
}
}, 180); }, 180);
mouseDown = true; mouseDown = true;
ev(e); ev(e);
@ -239,7 +240,10 @@ BI.BasicButton = BI.inherit(BI.Single, {
function clk(e) { function clk(e) {
ev(e); ev(e);
if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { if (!self.isEnabled() || !self.isValid()) {
return;
}
if (self.isOnce() && self.isSelected()) {
return; return;
} }
if (BI.isKey(o.bubble) || BI.isFunction(o.bubble)) { if (BI.isKey(o.bubble) || BI.isFunction(o.bubble)) {
@ -335,16 +339,17 @@ BI.BasicButton = BI.inherit(BI.Single, {
}, },
_doClick: function (e) { _doClick: function (e) {
if (this.isValid()) { if (!this.isEnabled() || !this.isValid()) {
var isIntercepted = this.beforeClick(e); return;
// 如果事件已经被消费掉了,就不再触发点击事件 }
if (isIntercepted) { var isIntercepted = this.beforeClick(e);
return; // 如果事件已经被消费掉了,就不再触发点击事件
} if (isIntercepted) {
return;
} }
this._trigger(e); this._trigger(e);
if (this.isValid()) { if (this.isEnabled() && this.isValid()) {
this.doClick(e); this.doClick(e);
} }
}, },

Loading…
Cancel
Save