forked from fanruan/fineui
zsmj
3 years ago
3 changed files with 295 additions and 25 deletions
@ -0,0 +1,282 @@
|
||||
/** |
||||
* dailer |
||||
* 有默认提示文字的输入框 |
||||
* @class BI.DefaultTextEditor |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.DefaultTextEditor = BI.inherit(BI.Widget, { |
||||
props: function () { |
||||
return { |
||||
baseCls: "bi-default-text-editor", |
||||
hgap: 4, |
||||
vgap: 2, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
validationChecker: BI.emptyFn, |
||||
quitChecker: BI.emptyFn, |
||||
allowBlank: true, |
||||
watermark: "", |
||||
errorText: "", |
||||
height: 24, |
||||
defaultText: "", // 默认显示值,默认显示值与显示值的区别是默认显示值标记灰色
|
||||
text: "", // 显示值
|
||||
el: {} |
||||
}; |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
this.editor = BI.createWidget(o.el, { |
||||
type: "bi.editor", |
||||
simple: o.simple, |
||||
height: o.height, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
value: o.value, |
||||
validationChecker: o.validationChecker, |
||||
quitChecker: o.quitChecker, |
||||
allowBlank: o.allowBlank, |
||||
watermark: o.watermark, |
||||
errorText: o.errorText, |
||||
invisible: true, |
||||
}); |
||||
this.text = BI.createWidget({ |
||||
type: "bi.text_button", |
||||
cls: BI.isKey(o.text) ? "tip-text-style" : "bi-water-mark tip-text-style", |
||||
textAlign: "left", |
||||
height: o.height, |
||||
text: BI.isKey(o.text) ? o.text : o.defaultText, |
||||
hgap: o.hgap + 2, |
||||
handler: function () { |
||||
self._showInput(); |
||||
self.editor.focus(); |
||||
self.editor.setValue(""); |
||||
}, |
||||
title: o.title, |
||||
warningTitle: o.warningTitle, |
||||
tipType: o.tipType |
||||
}); |
||||
this.text.on(BI.TextButton.EVENT_CHANGE, function () { |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_CLICK_LABEL); |
||||
}); |
||||
}); |
||||
|
||||
this.editor.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_FOCUS, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_FOCUS, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_BLUR, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_BLUR, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_CLICK, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_CLICK, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_KEY_DOWN, arguments); |
||||
}); |
||||
|
||||
this.editor.on(BI.Editor.EVENT_VALID, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_VALID, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_CONFIRM, function () { |
||||
self._showHint(); |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_CONFIRM, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_CHANGE_CONFIRM, function () { |
||||
self._showHint(); |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_CHANGE_CONFIRM, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_START, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_START, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_PAUSE, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_PAUSE, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_STOP, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_STOP, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_SPACE, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_SPACE, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_ERROR, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_ERROR, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_ENTER, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_ENTER, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_RESTRICT, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_RESTRICT, arguments); |
||||
}); |
||||
this.editor.on(BI.Editor.EVENT_EMPTY, function () { |
||||
self.fireEvent(BI.DefaultTextEditor.EVENT_EMPTY, arguments); |
||||
}); |
||||
|
||||
return { |
||||
type: "bi.absolute", |
||||
items: [ |
||||
{ |
||||
el: this.editor, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}, { |
||||
el: this.text, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
} |
||||
] |
||||
}; |
||||
}, |
||||
|
||||
setWaterMark: function (v) { |
||||
this.options.watermark = v; |
||||
this.editor.setWaterMark(v); |
||||
}, |
||||
|
||||
setTitle: function (title) { |
||||
this.text.setTitle(title); |
||||
}, |
||||
|
||||
setWarningTitle: function (title) { |
||||
this.text.setWarningTitle(title); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { |
||||
return; |
||||
} |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { |
||||
return; |
||||
} |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
focus: function () { |
||||
if (this.options.disabled === false) { |
||||
this._showInput(); |
||||
this.editor.focus(); |
||||
} |
||||
}, |
||||
|
||||
blur: function () { |
||||
this.editor.blur(); |
||||
this._showHint(); |
||||
}, |
||||
|
||||
_showInput: function () { |
||||
this.editor.visible(); |
||||
this.text.invisible(); |
||||
}, |
||||
|
||||
_showHint: function () { |
||||
this.editor.invisible(); |
||||
this.text.visible(); |
||||
}, |
||||
|
||||
_setText: function (v) { |
||||
this.text.setText(v); |
||||
this.text.setTitle(v); |
||||
}, |
||||
|
||||
isValid: function () { |
||||
return this.editor.isValid(); |
||||
}, |
||||
|
||||
setErrorText: function (text) { |
||||
this.editor.setErrorText(text); |
||||
}, |
||||
|
||||
getErrorText: function () { |
||||
return this.editor.getErrorText(); |
||||
}, |
||||
|
||||
isEditing: function () { |
||||
return this.editor.isEditing(); |
||||
}, |
||||
|
||||
getLastValidValue: function () { |
||||
return this.editor.getLastValidValue(); |
||||
}, |
||||
|
||||
getLastChangedValue: function () { |
||||
return this.editor.getLastChangedValue(); |
||||
}, |
||||
|
||||
setValue: function (k) { |
||||
this.editor.setValue(k); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.editor.getValue(); |
||||
}, |
||||
|
||||
getState: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setState: function (v) { |
||||
var o = this.options; |
||||
if (BI.isKey(v)) { |
||||
this.text.setText(v); |
||||
this.text.element.removeClass("bi-water-mark"); |
||||
return; |
||||
} |
||||
this.text.setText(o.defaultText); |
||||
this.text.element.addClass("bi-water-mark"); |
||||
}, |
||||
|
||||
setTipType: function (v) { |
||||
this.text.options.tipType = v; |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.DefaultTextEditor.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.DefaultTextEditor.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.DefaultTextEditor.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.DefaultTextEditor.EVENT_CLICK = "EVENT_CLICK"; |
||||
BI.DefaultTextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; |
||||
BI.DefaultTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; |
||||
|
||||
BI.DefaultTextEditor.EVENT_START = "EVENT_START"; |
||||
BI.DefaultTextEditor.EVENT_PAUSE = "EVENT_PAUSE"; |
||||
BI.DefaultTextEditor.EVENT_STOP = "EVENT_STOP"; |
||||
BI.DefaultTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.DefaultTextEditor.EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM"; |
||||
BI.DefaultTextEditor.EVENT_VALID = "EVENT_VALID"; |
||||
BI.DefaultTextEditor.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.DefaultTextEditor.EVENT_ENTER = "EVENT_ENTER"; |
||||
BI.DefaultTextEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; |
||||
BI.DefaultTextEditor.EVENT_SPACE = "EVENT_SPACE"; |
||||
BI.DefaultTextEditor.EVENT_EMPTY = "EVENT_EMPTY"; |
||||
|
||||
BI.shortcut("bi.default_text_editor", BI.DefaultTextEditor); |
Loading…
Reference in new issue