Browse Source

KERNEL-14020 refactor: base/single中的iframe,image,instruction,link,trigger ES6化

es6
impact 2 years ago
parent
commit
1530f78a1e
  1. 66
      src/base/single/0.single.js
  2. 3
      src/base/single/button/node/texticonnode.js
  3. 4
      src/base/single/editor/editor.js
  4. 62
      src/base/single/iframe/iframe.js
  5. 42
      src/base/single/img/img.js
  6. 5
      src/base/single/index.js
  7. 89
      src/base/single/instruction/instruction.js
  8. 2
      src/base/single/label/html.label.js
  9. 2
      src/base/single/label/label.js
  10. 44
      src/base/single/link/link.js
  11. 2
      src/base/single/text.pure.js
  12. 23
      src/base/single/trigger/trigger.js

66
src/base/single/0.single.js

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

3
src/base/single/button/node/texticonnode.js

@ -7,7 +7,8 @@ import { extend, shortcut } from "../../../../core";
* @extends NodeButton * @extends NodeButton
*/ */
@shortcut() @shortcut()
export default class TextIconNode extends NodeButton { export class TextIconNode extends NodeButton {
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
static xtype = "bi.text_icon_node"; static xtype = "bi.text_icon_node";

4
src/base/single/editor/editor.js

@ -206,7 +206,7 @@ export class Editor extends Single {
_checkToolTip() { _checkToolTip() {
const { errorText } = this.options; const { errorText } = this.options;
if (isFunction(errorText)) { if (isFunction(errorText)) {
errorText = errorText(this.editor.getValue()); this.options.errorText = errorText(this.editor.getValue());
} }
if (isKey(errorText)) { if (isKey(errorText)) {
if (!this.isEnabled() || this.isValid() || Bubbles.has(this.getName())) { if (!this.isEnabled() || this.isValid() || Bubbles.has(this.getName())) {
@ -298,7 +298,7 @@ export class Editor extends Single {
_setErrorVisible(b) { _setErrorVisible(b) {
const { errorText, autoTrim, simple } = this.options; const { errorText, autoTrim, simple } = this.options;
if (isFunction(errorText)) { if (isFunction(errorText)) {
errorText = errorText(autoTrim ? trim(this.editor.getValue()) : this.editor.getValue()); this.options.errorText = errorText(autoTrim ? trim(this.editor.getValue()) : this.editor.getValue());
} }
if (!this.disabledError && isKey(errorText)) { if (!this.disabledError && isKey(errorText)) {
Bubbles[b ? "show" : "hide"](this.getName(), errorText, this, { Bubbles[b ? "show" : "hide"](this.getName(), errorText, this, {

62
src/base/single/iframe/iframe.js

@ -1,14 +1,19 @@
/** /**
* @class BI.Iframe * @class Iframe
* @extends BI.Single * @extends Single
* @abstract * @abstract
* Created by GameJian on 2016/3/2. * Created by GameJian on 2016/3/2.
*/ */
BI.Iframe = BI.inherit(BI.Single, { import { shortcut, extend } from "../../../core";
_defaultConfig: function (config) { import { Single } from "../0.single";
var conf = BI.Iframe.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { @shortcut()
export class Iframe extends Single {
static xtype = "bi.iframe";
_defaultConfig(config) {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
tagName: "iframe", tagName: "iframe",
baseCls: (conf.baseCls || "") + " bi-iframe", baseCls: (conf.baseCls || "") + " bi-iframe",
src: "", src: "",
@ -17,42 +22,39 @@ BI.Iframe = BI.inherit(BI.Single, {
width: "100%", width: "100%",
height: "100%", height: "100%",
}); });
}, }
render: function () { render() {
var self = this; this.element.on("load", () => {
this.element.on("load", function () { this.fireEvent("EVENT_LOADED");
self.fireEvent("EVENT_LOADED");
}); });
}, }
_initProps: function () { _initProps() {
BI.Iframe.superclass._initProps.apply(this, arguments); super._initProps(...arguments)
var o = this.options; const { src, name } = this.options;
this.options.attributes = BI.extend({ this.options.attributes = extend({
frameborder: 0, frameborder: 0,
src: o.src, src,
name: o.name, name,
}, this.options.attributes); }, this.options.attributes);
}, }
setSrc: function (src) { setSrc(src) {
this.options.src = src; this.options.src = src;
this.element.attr("src", src); this.element.attr("src", src);
}, }
getSrc: function () { getSrc() {
return this.options.src; return this.options.src;
}, }
setName: function (name) { setName(name) {
this.options.name = name; this.options.name = name;
this.element.attr("name", name); this.element.attr("name", name);
}, }
getName: function () { getName() {
return this.options.name; return this.options.name;
}, }
}); }
BI.shortcut("bi.iframe", BI.Iframe);

42
src/base/single/img/img.js

@ -6,11 +6,17 @@
* @extends BI.Single * @extends BI.Single
* @abstract * @abstract
*/ */
BI.Img = BI.inherit(BI.Single, { import { shortcut, extend } from "../../../core";
_defaultConfig: function (config) { import { Single } from "../0.single";
var conf = BI.Img.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { @shortcut()
export class Img extends Single {
static xtype = "bi.img";
_defaultConfig(config) {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
tagName: "img", tagName: "img",
baseCls: (conf.baseCls || "") + " bi-img display-block", baseCls: (conf.baseCls || "") + " bi-img display-block",
src: "", src: "",
@ -18,24 +24,22 @@ BI.Img = BI.inherit(BI.Single, {
width: "100%", width: "100%",
height: "100%", height: "100%",
}); });
}, }
_initProps: function () { _initProps() {
BI.Img.superclass._initProps.apply(this, arguments); super._initProps(...arguments)
var o = this.options; const { src } = this.options;
this.options.attributes = BI.extend({ this.options.attributes = extend({
src: o.src, src,
}, this.options.attributes); }, this.options.attributes);
}, }
setSrc: function (src) { setSrc(src) {
this.options.src = src; this.options.src = src;
this.element.attr("src", src); this.element.attr("src", src);
}, }
getSrc: function () { getSrc() {
return this.options.src; return this.options.src;
}, }
}); }
BI.shortcut("bi.img", BI.Img);

5
src/base/single/index.js

@ -4,6 +4,11 @@ export { PureText } from "./text.pure";
export { Icon } from "./icon/icon"; export { Icon } from "./icon/icon";
export { Html } from "./html/html"; export { Html } from "./html/html";
export { A } from "./a/a"; export { A } from "./a/a";
export { Iframe } from "./iframe/iframe";
export { Link } from "./link/link";
export { Instruction } from "./instruction/instruction";
export { Img } from "./img/img";
export { Trigger } from "./trigger/trigger";
export * from "./tip"; export * from "./tip";
export * from "./label"; export * from "./label";
export * from "./input"; export * from "./input";

89
src/base/single/instruction/instruction.js

@ -1,7 +1,12 @@
BI.Instruction = BI.inherit(BI.Widget, { import { shortcut, Widget, extend } from "../../../core";
_defaultConfig: function () {
var conf = BI.Link.superclass._defaultConfig.apply(this, arguments); @shortcut()
return BI.extend(conf, { export class Instruction extends Widget {
static xtype = "bi.instruction";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: (conf.baseCls || "") + " bi-instruction", baseCls: (conf.baseCls || "") + " bi-instruction",
height: 20, height: 20,
level: "error", level: "error",
@ -9,68 +14,66 @@ BI.Instruction = BI.inherit(BI.Widget, {
whiteSpace: "nowrap", whiteSpace: "nowrap",
hgap: 5 hgap: 5
}); });
}, }
render: function () { render() {
var self = this, o = this.options; const { level, textAlign, whiteSpace, height, hgap, rgap, lgap, vgap, text, keyword, value, py } = this.options;
return { return {
type: "bi.label", type: "bi.label",
ref: function (_ref) { ref: (_ref) => {
self.text = _ref; this.text = _ref;
}, },
cls: "instruction-" + o.level, cls: "instruction-" + level,
textAlign: o.textAlign, textAlign,
whiteSpace: o.whiteSpace, whiteSpace,
textHeight: o.height, textHeight: height,
height: o.height, height,
hgap: o.hgap, hgap,
rgap: o.rgap, rgap,
lgap: o.lgap, lgap,
vgap: o.vgap, vgap,
text: o.text, text,
keyword: o.keyword, keyword,
value: o.value, value,
py: o.py py
}; };
}, }
doRedMark: function () { doRedMark() {
this.text.doRedMark.apply(this.text, arguments); this.text.doRedMark.apply(this.text, arguments);
}, }
unRedMark: function () { unRedMark() {
this.text.unRedMark.apply(this.text, arguments); this.text.unRedMark.apply(this.text, arguments);
}, }
doHighLight: function () { doHighLight() {
this.text.doHighLight.apply(this.text, arguments); this.text.doHighLight.apply(this.text, arguments);
}, }
unHighLight: function () { unHighLight() {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
}, }
setText: function (v) { setText(v) {
this.options.text = v; this.options.text = v;
this.text.setText(v); this.text.setText(v);
}, }
getText: function () { getText() {
return this.options.text; return this.options.text;
}, }
setStyle: function (css) { setStyle(css) {
this.text.setStyle(css); this.text.setStyle(css);
}, }
setValue: function (v) { setValue(v) {
this.text.setValue(v); this.text.setValue(v);
}, }
getValue: function () { getValue() {
this.text.getValue(); this.text.getValue();
} }
}); }
BI.shortcut("bi.instruction", BI.Instruction);

2
src/base/single/label/html.label.js

@ -2,7 +2,7 @@
* Created by GUY on 2015/6/26. * Created by GUY on 2015/6/26.
*/ */
import { shortcut } from "../../../core"; import { shortcut } from "../../../core";
import { AbstractLabel } from "./abstract.label" import { AbstractLabel } from "./abstract.label";
@shortcut() @shortcut()
export class HtmlLabel extends AbstractLabel { export class HtmlLabel extends AbstractLabel {

2
src/base/single/label/label.js

@ -2,7 +2,7 @@
* Created by GUY on 2015/6/26. * Created by GUY on 2015/6/26.
*/ */
import { shortcut, isFunction, isNotNull } from "../../../core"; import { shortcut, isFunction, isNotNull } from "../../../core";
import { AbstractLabel } from "./abstract.label" import { AbstractLabel } from "./abstract.label";
@shortcut() @shortcut()
export class Label extends AbstractLabel { export class Label extends AbstractLabel {

44
src/base/single/link/link.js

@ -3,34 +3,38 @@
* @class BI.Link * @class BI.Link
* @extends BI.Text * @extends BI.Text
*/ */
BI.Link = BI.inherit(BI.Label, { import { shortcut, extend } from "../../../core";
_defaultConfig: function () { import { Label } from "../label/label";
var conf = BI.Link.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { @shortcut()
export class Link extends Label {
static xtype = "bi.link";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: (conf.baseCls || "") + " bi-link display-block", baseCls: (conf.baseCls || "") + " bi-link display-block",
tagName: "a", tagName: "a",
href: "", href: "",
target: "_blank", target: "_blank",
}); });
}, }
_createJson: function () { _createJson() {
var o = this.options; const { textAlign, whiteSpace, textHeight, text, keyword, value, py, href, target } = this.options;
return { return {
type: "bi.a", type: "bi.a",
textAlign: o.textAlign, textAlign,
whiteSpace: o.whiteSpace, whiteSpace,
lineHeight: o.textHeight, lineHeight: textHeight,
text: o.text, text,
keyword: o.keyword, keyword,
value: o.value, value,
py: o.py, py,
href: o.href, href,
target: o.target, target,
}; };
}, }
}); }
BI.shortcut("bi.link", BI.Link);

2
src/base/single/text.pure.js

@ -26,7 +26,7 @@ export class PureText extends Widget {
_getShowText() { _getShowText() {
const { text: optionsText, value } = this.options; const { text: optionsText, value } = this.options;
const text = isFunction(optionsText) ? optionsText() : optionsText; let text = isFunction(optionsText) ? optionsText() : optionsText;
text = isKey(text) ? text : value; text = isKey(text) ? text : value;
if (!isKey(text)) { if (!isKey(text)) {
return ""; return "";

23
src/base/single/trigger/trigger.js

@ -4,21 +4,24 @@
* @extends BI.Single * @extends BI.Single
* @abstract * @abstract
*/ */
BI.Trigger = BI.inherit(BI.Single, { import { extend } from "../../../core";
_defaultConfig: function () { import { Single } from "../0.single";
var conf = BI.Trigger.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { export class Trigger extends Single {
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
_baseCls: (conf._baseCls || "") + " bi-trigger cursor-pointer", _baseCls: (conf._baseCls || "") + " bi-trigger cursor-pointer",
height: 24, height: 24,
}); });
}, }
setKey: function () { setKey() {
}, }
getKey: function () { getKey() {
}, }
}); }

Loading…
Cancel
Save