forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.1 KiB
102 lines
3.1 KiB
import { SignEditor } from "../editor"; |
|
import { HorizontalFillLayout, shortcut, extend, emptyFn, createWidget, toPix, Controller } from "@/core"; |
|
import { TriggerIconButton } from "../button"; |
|
import { Trigger } from "@/base"; |
|
|
|
/** |
|
* 文本输入框trigger |
|
* |
|
* Created by GUY on 2015/9/15. |
|
* @class EditorTrigger |
|
* @extends Trigger |
|
*/ |
|
@shortcut() |
|
export class EditorTrigger extends Trigger { |
|
static xtype = "bi.editor_trigger"; |
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
static EVENT_FOCUS = "EVENT_FOCUS"; |
|
static EVENT_EMPTY = "EVENT_EMPTY"; |
|
static EVENT_VALID = "EVENT_VALID"; |
|
static EVENT_ERROR = "EVENT_ERROR"; |
|
|
|
_defaultConfig(config) { |
|
const conf = super._defaultConfig(...arguments); |
|
|
|
return extend(conf, { |
|
baseCls: `${conf.baseCls || ""} bi-editor-trigger bi-border-radius ${ |
|
config.simple ? "bi-border-bottom" : "bi-border" |
|
}`, |
|
height: 24, |
|
validationChecker: emptyFn, |
|
quitChecker: emptyFn, |
|
allowBlank: false, |
|
watermark: "", |
|
errorText: "", |
|
}); |
|
} |
|
|
|
_init() { |
|
super._init(...arguments); |
|
const o = this.options; |
|
this.editor = createWidget({ |
|
type: SignEditor.xtype, |
|
height: toPix(o.height, 2), |
|
value: o.value, |
|
validationChecker: o.validationChecker, |
|
quitChecker: o.quitChecker, |
|
allowBlank: o.allowBlank, |
|
watermark: o.watermark, |
|
errorText: o.errorText, |
|
title: () => this.getValue(), |
|
}); |
|
this.editor.on(Controller.EVENT_CHANGE, (...args) => { |
|
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
|
}); |
|
this.editor.on(SignEditor.EVENT_CHANGE, (...args) => { |
|
this.fireEvent(EditorTrigger.EVENT_CHANGE, ...args); |
|
}); |
|
this.editor.on(SignEditor.EVENT_FOCUS, (...args) => { |
|
this.fireEvent(EditorTrigger.EVENT_FOCUS, ...args); |
|
}); |
|
this.editor.on(SignEditor.EVENT_EMPTY, (...args) => { |
|
this.fireEvent(EditorTrigger.EVENT_EMPTY, ...args); |
|
}); |
|
this.editor.on(SignEditor.EVENT_VALID, (...args) => { |
|
this.fireEvent(EditorTrigger.EVENT_VALID, ...args); |
|
}); |
|
this.editor.on(SignEditor.EVENT_ERROR, (...args) => { |
|
this.fireEvent(EditorTrigger.EVENT_ERROR, ...args); |
|
}); |
|
|
|
createWidget({ |
|
element: this, |
|
type: HorizontalFillLayout.xtype, |
|
height: toPix(o.height, 2), |
|
items: [ |
|
{ |
|
el: this.editor, |
|
width: "fill", |
|
}, |
|
{ |
|
el: { |
|
type: TriggerIconButton.xtype, |
|
width: o.triggerWidth || toPix(o.height, 2), |
|
}, |
|
width: "", |
|
} |
|
], |
|
}); |
|
} |
|
|
|
getValue() { |
|
return this.editor.getValue(); |
|
} |
|
|
|
setValue(value) { |
|
this.editor.setValue(value); |
|
} |
|
|
|
setText(text) { |
|
this.editor.setState(text); |
|
} |
|
}
|
|
|