|
|
|
@ -5,12 +5,12 @@
|
|
|
|
|
* 2、title的控制 |
|
|
|
|
* 3、文字超过边界显示3个点 |
|
|
|
|
* 4、cursor默认pointor |
|
|
|
|
* @class BI.Single |
|
|
|
|
* @extends BI.Widget |
|
|
|
|
* @class Single |
|
|
|
|
* @extends Widget |
|
|
|
|
* @abstract |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
import { Widget, shortcut } from "../../core"; |
|
|
|
|
import { Widget, shortcut, Actions, extend, isKey, isNotNull, isFunction, isPlainObject, isNull, delay } from "../../core"; |
|
|
|
|
import { Tooltips } from "../0.base"; |
|
|
|
|
|
|
|
|
|
@shortcut() |
|
|
|
@ -20,7 +20,7 @@ export class Single extends Widget {
|
|
|
|
|
_defaultConfig() { |
|
|
|
|
const conf = super._defaultConfig(...arguments); |
|
|
|
|
|
|
|
|
|
return BI.extend(conf, { |
|
|
|
|
return extend(conf, { |
|
|
|
|
readonly: false, |
|
|
|
|
title: null, |
|
|
|
|
warningTitle: null, // deprecated
|
|
|
|
@ -36,12 +36,12 @@ export class Single extends Widget {
|
|
|
|
|
const title = this.getTitle(); |
|
|
|
|
|
|
|
|
|
const showToolTip = (tooltipOpt) => { |
|
|
|
|
if (BI.isKey(tooltipOpt.text) && !Tooltips.has(this.getName())) { |
|
|
|
|
if (isKey(tooltipOpt.text) && !Tooltips.has(this.getName())) { |
|
|
|
|
Tooltips.show(e, this.getName(), tooltipOpt, this, opt); |
|
|
|
|
if (action) { |
|
|
|
|
BI.Actions.runAction(action, "hover", this.options, this); |
|
|
|
|
Actions.runAction(action, "hover", this.options, this); |
|
|
|
|
} |
|
|
|
|
BI.Actions.runGlobalAction("hover", this.options, this); |
|
|
|
|
Actions.runGlobalAction("hover", this.options, this); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,7 +59,7 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
_hideTooltip() { |
|
|
|
|
const tooltip = Tooltips.get(this.getName()); |
|
|
|
|
if (BI.isNotNull(tooltip)) { |
|
|
|
|
if (isNotNull(tooltip)) { |
|
|
|
|
tooltip.element.fadeOut(200, () => { |
|
|
|
|
Tooltips.remove(this.getName()); |
|
|
|
|
}); |
|
|
|
@ -68,7 +68,7 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
_init() { |
|
|
|
|
const { value } = this.options; |
|
|
|
|
this.options.value = BI.isFunction(value) ? this.__watch(value, (context, newValue) => { |
|
|
|
|
this.options.value = isFunction(value) ? this.__watch(value, (context, newValue) => { |
|
|
|
|
this.setValue(newValue); |
|
|
|
|
}) : value; |
|
|
|
|
super._init(arguments); |
|
|
|
@ -76,8 +76,8 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
_mounted() { |
|
|
|
|
const { enableHover, title, warningTitle, belowMouse, container } = this.options; |
|
|
|
|
if (enableHover || BI.isKey(title) || BI.isKey(warningTitle) |
|
|
|
|
|| BI.isFunction(title) || BI.isFunction(warningTitle)) { |
|
|
|
|
if (enableHover || isKey(title) || isKey(warningTitle) |
|
|
|
|
|| isFunction(title) || isFunction(warningTitle)) { |
|
|
|
|
this.enableHover({ |
|
|
|
|
belowMouse, |
|
|
|
|
container, |
|
|
|
@ -86,11 +86,11 @@ export class Single extends Widget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_clearTimeOut() { |
|
|
|
|
if (BI.isNotNull(this.showTimeout)) { |
|
|
|
|
if (isNotNull(this.showTimeout)) { |
|
|
|
|
clearTimeout(this.showTimeout); |
|
|
|
|
this.showTimeout = null; |
|
|
|
|
} |
|
|
|
|
if (BI.isNotNull(this.hideTimeout)) { |
|
|
|
|
if (isNotNull(this.hideTimeout)) { |
|
|
|
|
clearTimeout(this.hideTimeout); |
|
|
|
|
this.hideTimeout = null; |
|
|
|
|
} |
|
|
|
@ -99,12 +99,12 @@ export class Single extends Widget {
|
|
|
|
|
_getTooltipOptions(title) { |
|
|
|
|
const { tipType } = this.options; |
|
|
|
|
let tooltipOpt = {}; |
|
|
|
|
if (BI.isPlainObject(title)) { |
|
|
|
|
if (isPlainObject(title)) { |
|
|
|
|
tooltipOpt = title; |
|
|
|
|
} else { |
|
|
|
|
tooltipOpt.level = this.getTipType() || "success"; |
|
|
|
|
// 由于以前的用法,存在大量disabled:true搭配warningTitle的情况,所以这里做一个兼容,disabled:true的情况下,依然优先显示warningTitle,避免只设置了warningTitle而没有设置title的情况
|
|
|
|
|
if (BI.isNull(tipType) && !this.isEnabled()) { |
|
|
|
|
if (isNull(tipType) && !this.isEnabled()) { |
|
|
|
|
tooltipOpt.text = (this.getWarningTitle() || title); |
|
|
|
|
} else { |
|
|
|
|
tooltipOpt.text = tooltipOpt.level === "success" ? title : (this.getWarningTitle() || title); |
|
|
|
@ -120,17 +120,17 @@ export class Single extends Widget {
|
|
|
|
|
this.element.unbind("mouseenter.title").on("mouseenter.title", (e) => { |
|
|
|
|
this._e = e; |
|
|
|
|
this.mouseOver = true; |
|
|
|
|
if (this.getTipType() === "warning" || (BI.isKey(this.getWarningTitle()) && !this.isEnabled())) { |
|
|
|
|
if (this.getTipType() === "warning" || (isKey(this.getWarningTitle()) && !this.isEnabled())) { |
|
|
|
|
delayingTooltips = this.getName(); |
|
|
|
|
this.showTimeout = BI.delay(() => { |
|
|
|
|
if (BI.isNotNull(this.showTimeout) && delayingTooltips === this.getName()) { |
|
|
|
|
this.showTimeout = delay(() => { |
|
|
|
|
if (isNotNull(this.showTimeout) && delayingTooltips === this.getName()) { |
|
|
|
|
this._showToolTip(this._e || e, opt); |
|
|
|
|
} |
|
|
|
|
}, 200); |
|
|
|
|
} else if (this.getTipType() === "success" || this.isEnabled()) { |
|
|
|
|
delayingTooltips = this.getName(); |
|
|
|
|
this.showTimeout = BI.delay(() => { |
|
|
|
|
if (BI.isNotNull(this.showTimeout) && delayingTooltips === this.getName()) { |
|
|
|
|
this.showTimeout = delay(() => { |
|
|
|
|
if (isNotNull(this.showTimeout) && delayingTooltips === this.getName()) { |
|
|
|
|
this._showToolTip(this._e || e, opt); |
|
|
|
|
} |
|
|
|
|
}, 500); |
|
|
|
@ -138,22 +138,22 @@ export class Single extends Widget {
|
|
|
|
|
}); |
|
|
|
|
this.element.unbind("mousemove.title").on("mousemove.title", (e) => { |
|
|
|
|
this._e = e; |
|
|
|
|
if (BI.isNotNull(this.showTimeout)) { |
|
|
|
|
if (isNotNull(this.showTimeout)) { |
|
|
|
|
clearTimeout(this.showTimeout); |
|
|
|
|
this.showTimeout = null; |
|
|
|
|
} |
|
|
|
|
if (BI.isNull(this.hideTimeout)) { |
|
|
|
|
this.hideTimeout = BI.delay(() => { |
|
|
|
|
if (BI.isNotNull(this.hideTimeout)) { |
|
|
|
|
if (isNull(this.hideTimeout)) { |
|
|
|
|
this.hideTimeout = delay(() => { |
|
|
|
|
if (isNotNull(this.hideTimeout)) { |
|
|
|
|
this._hideTooltip(); |
|
|
|
|
} |
|
|
|
|
}, 500); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.showTimeout = BI.delay(() => { |
|
|
|
|
this.showTimeout = delay(() => { |
|
|
|
|
// DEC-5321 IE下如果回调已经进入事件队列,clearTimeout将不会起作用
|
|
|
|
|
if (BI.isNotNull(this.showTimeout)) { |
|
|
|
|
if (BI.isNotNull(this.hideTimeout)) { |
|
|
|
|
if (isNotNull(this.showTimeout)) { |
|
|
|
|
if (isNotNull(this.hideTimeout)) { |
|
|
|
|
clearTimeout(this.hideTimeout); |
|
|
|
|
this.hideTimeout = null; |
|
|
|
|
} |
|
|
|
@ -188,7 +188,7 @@ export class Single extends Widget {
|
|
|
|
|
// opt: {container: '', belowMouse: false}
|
|
|
|
|
setTitle(title, opt) { |
|
|
|
|
this.options.title = title; |
|
|
|
|
if (BI.isKey(title) || BI.isFunction(title)) { |
|
|
|
|
if (isKey(title) || isFunction(title)) { |
|
|
|
|
this.enableHover(opt); |
|
|
|
|
} else { |
|
|
|
|
this.disabledHover(); |
|
|
|
@ -197,7 +197,7 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
setWarningTitle(title, opt) { |
|
|
|
|
this.options.warningTitle = title; |
|
|
|
|
if (BI.isKey(title) || BI.isFunction(title)) { |
|
|
|
|
if (isKey(title) || isFunction(title)) { |
|
|
|
|
this.enableHover(opt); |
|
|
|
|
} else { |
|
|
|
|
this.disabledHover(); |
|
|
|
@ -218,7 +218,7 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
getTitle() { |
|
|
|
|
const title = this.options.title; |
|
|
|
|
if (BI.isFunction(title)) { |
|
|
|
|
if (isFunction(title)) { |
|
|
|
|
return title(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -227,7 +227,7 @@ export class Single extends Widget {
|
|
|
|
|
|
|
|
|
|
getWarningTitle() { |
|
|
|
|
const title = this.options.warningTitle; |
|
|
|
|
if (BI.isFunction(title)) { |
|
|
|
|
if (isFunction(title)) { |
|
|
|
|
return title(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -246,7 +246,7 @@ export class Single extends Widget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_destroyed() { |
|
|
|
|
if (BI.isNotNull(this.showTimeout)) { |
|
|
|
|
if (isNotNull(this.showTimeout)) { |
|
|
|
|
clearTimeout(this.showTimeout); |
|
|
|
|
this.showTimeout = null; |
|
|
|
|
} |
|
|
|
|