|
|
|
/**
|
|
|
|
* title提示
|
|
|
|
*
|
|
|
|
* Created by GUY on 2015/9/7.
|
|
|
|
* @class BI.Tooltip
|
|
|
|
* @extends BI.Tip
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { shortcut, extend, createWidget, map } from "../../../core";
|
|
|
|
import { Tip } from "./0.tip";
|
|
|
|
@shortcut()
|
|
|
|
export class Tooltip extends Tip {
|
|
|
|
_const = {
|
|
|
|
hgap: 8,
|
|
|
|
vgap: 4,
|
|
|
|
}
|
|
|
|
static xtype = "bi.tooltip";
|
|
|
|
|
|
|
|
_defaultConfig() {
|
|
|
|
return extend(super._defaultConfig(arguments), {
|
|
|
|
extraCls: "bi-tooltip",
|
|
|
|
text: "",
|
|
|
|
level: "success", // success或warning
|
|
|
|
stopEvent: false,
|
|
|
|
stopPropagation: false,
|
|
|
|
textAlign: "left",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { level, stopPropagation, stopEvent, text, textAlign } = this.options;
|
|
|
|
this.element.addClass(`tooltip-${level}`);
|
|
|
|
function fn(e) {
|
|
|
|
stopPropagation && e.stopPropagation();
|
|
|
|
stopEvent && e.stopEvent();
|
|
|
|
}
|
|
|
|
this.element.bind({
|
|
|
|
click: fn,
|
|
|
|
mousedown: fn,
|
|
|
|
mouseup: fn,
|
|
|
|
mouseover: fn,
|
|
|
|
mouseenter: fn,
|
|
|
|
mouseleave: fn,
|
|
|
|
mousemove: fn,
|
|
|
|
});
|
|
|
|
|
|
|
|
const texts = (`${text}`).split("\n");
|
|
|
|
if (texts.length > 1) {
|
|
|
|
createWidget({
|
|
|
|
type: "bi.vertical",
|
|
|
|
element: this,
|
|
|
|
hgap: this._const.hgap,
|
|
|
|
innerVgap: this._const.vgap,
|
|
|
|
items: map(texts, (i, text) => {
|
|
|
|
return {
|
|
|
|
type: "bi.label",
|
|
|
|
textAlign,
|
|
|
|
whiteSpace: "normal",
|
|
|
|
text,
|
|
|
|
textHeight: 18,
|
|
|
|
title: null,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.text = createWidget({
|
|
|
|
type: "bi.label",
|
|
|
|
element: this,
|
|
|
|
textAlign,
|
|
|
|
whiteSpace: "normal",
|
|
|
|
text,
|
|
|
|
title: null,
|
|
|
|
textHeight: 18,
|
|
|
|
hgap: this._const.hgap,
|
|
|
|
vgap: this._const.vgap,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setWidth(width) {
|
|
|
|
this.element.width(BI.pixFormat(width - 2 * this._const.hgap));
|
|
|
|
}
|
|
|
|
|
|
|
|
setText(text) {
|
|
|
|
this.text && this.text.setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLevel(level) {
|
|
|
|
this.element.removeClass("tooltip-success").removeClass("tooltip-warning");
|
|
|
|
this.element.addClass(`tooltip-${level}`);
|
|
|
|
}
|
|
|
|
}
|