Browse Source

codeeditor的水印问题

es6
windy 7 years ago
parent
commit
7e66a82318
  1. 24
      bi/base.js
  2. 24
      docs/base.js
  3. 24
      src/base/single/editor/editor.code.js

24
bi/base.js

@ -17747,12 +17747,12 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}); });
this.editor.on("focus", function () { this.editor.on("focus", function () {
watermark.setVisible(false); self.watermark.setVisible(false);
self.fireEvent(BI.CodeEditor.EVENT_FOCUS); self.fireEvent(BI.CodeEditor.EVENT_FOCUS);
}); });
this.editor.on("blur", function () { this.editor.on("blur", function () {
watermark.setVisible(BI.isEmptyString(self.getValue())); self.watermark.setVisible(BI.isEmptyString(self.getValue()));
self.fireEvent(BI.CodeEditor.EVENT_BLUR); self.fireEvent(BI.CodeEditor.EVENT_BLUR);
}); });
@ -17761,21 +17761,21 @@ BI.CodeEditor = BI.inherit(BI.Single, {
// }); // });
//水印 //水印
var watermark = BI.createWidget({ this.watermark = BI.createWidget({
type: "bi.label", type: "bi.label",
text: o.watermark, text: o.watermark,
cls: "bi-water-mark", cls: "bi-water-mark",
whiteSpace: "nowrap", whiteSpace: "nowrap",
textAlign: "left" textAlign: "left"
}); });
watermark.element.bind( this.watermark.element.bind(
"mousedown", function (e) { "mousedown", function (e) {
self.insertString(""); self.insertString("");
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
} }
); );
watermark.element.bind("click", function (e) { this.watermark.element.bind("click", function (e) {
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
}); });
@ -17783,7 +17783,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: watermark, el: this.watermark,
top: 0, top: 0,
left: 5 left: 5
}] }]
@ -17801,6 +17801,15 @@ BI.CodeEditor = BI.inherit(BI.Single, {
this.editor.setOption("readOnly", b === true ? false : "nocursor") this.editor.setOption("readOnly", b === true ? false : "nocursor")
}, },
_checkWaterMark: function () {
var o = this.options;
if (BI.isEmptyString(this.editor.getValue()) && BI.isKey(o.watermark)) {
this.watermark && this.watermark.visible();
} else {
this.watermark && this.watermark.invisible();
}
},
insertParam: function (param) { insertParam: function (param) {
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
@ -17855,7 +17864,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
} else { } else {
self.insertString(item); self.insertString(item);
} }
}) });
this._checkWaterMark();
}, },
focus: function () { focus: function () {

24
docs/base.js

@ -17747,12 +17747,12 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}); });
this.editor.on("focus", function () { this.editor.on("focus", function () {
watermark.setVisible(false); self.watermark.setVisible(false);
self.fireEvent(BI.CodeEditor.EVENT_FOCUS); self.fireEvent(BI.CodeEditor.EVENT_FOCUS);
}); });
this.editor.on("blur", function () { this.editor.on("blur", function () {
watermark.setVisible(BI.isEmptyString(self.getValue())); self.watermark.setVisible(BI.isEmptyString(self.getValue()));
self.fireEvent(BI.CodeEditor.EVENT_BLUR); self.fireEvent(BI.CodeEditor.EVENT_BLUR);
}); });
@ -17761,21 +17761,21 @@ BI.CodeEditor = BI.inherit(BI.Single, {
// }); // });
//水印 //水印
var watermark = BI.createWidget({ this.watermark = BI.createWidget({
type: "bi.label", type: "bi.label",
text: o.watermark, text: o.watermark,
cls: "bi-water-mark", cls: "bi-water-mark",
whiteSpace: "nowrap", whiteSpace: "nowrap",
textAlign: "left" textAlign: "left"
}); });
watermark.element.bind( this.watermark.element.bind(
"mousedown", function (e) { "mousedown", function (e) {
self.insertString(""); self.insertString("");
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
} }
); );
watermark.element.bind("click", function (e) { this.watermark.element.bind("click", function (e) {
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
}); });
@ -17783,7 +17783,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: watermark, el: this.watermark,
top: 0, top: 0,
left: 5 left: 5
}] }]
@ -17801,6 +17801,15 @@ BI.CodeEditor = BI.inherit(BI.Single, {
this.editor.setOption("readOnly", b === true ? false : "nocursor") this.editor.setOption("readOnly", b === true ? false : "nocursor")
}, },
_checkWaterMark: function () {
var o = this.options;
if (BI.isEmptyString(this.editor.getValue()) && BI.isKey(o.watermark)) {
this.watermark && this.watermark.visible();
} else {
this.watermark && this.watermark.invisible();
}
},
insertParam: function (param) { insertParam: function (param) {
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
@ -17855,7 +17864,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
} else { } else {
self.insertString(item); self.insertString(item);
} }
}) });
this._checkWaterMark();
}, },
focus: function () { focus: function () {

24
src/base/single/editor/editor.code.js

@ -31,12 +31,12 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}); });
this.editor.on("focus", function () { this.editor.on("focus", function () {
watermark.setVisible(false); self.watermark.setVisible(false);
self.fireEvent(BI.CodeEditor.EVENT_FOCUS); self.fireEvent(BI.CodeEditor.EVENT_FOCUS);
}); });
this.editor.on("blur", function () { this.editor.on("blur", function () {
watermark.setVisible(BI.isEmptyString(self.getValue())); self.watermark.setVisible(BI.isEmptyString(self.getValue()));
self.fireEvent(BI.CodeEditor.EVENT_BLUR); self.fireEvent(BI.CodeEditor.EVENT_BLUR);
}); });
@ -45,21 +45,21 @@ BI.CodeEditor = BI.inherit(BI.Single, {
// }); // });
//水印 //水印
var watermark = BI.createWidget({ this.watermark = BI.createWidget({
type: "bi.label", type: "bi.label",
text: o.watermark, text: o.watermark,
cls: "bi-water-mark", cls: "bi-water-mark",
whiteSpace: "nowrap", whiteSpace: "nowrap",
textAlign: "left" textAlign: "left"
}); });
watermark.element.bind( this.watermark.element.bind(
"mousedown", function (e) { "mousedown", function (e) {
self.insertString(""); self.insertString("");
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
} }
); );
watermark.element.bind("click", function (e) { this.watermark.element.bind("click", function (e) {
self.editor.focus(); self.editor.focus();
e.stopEvent(); e.stopEvent();
}); });
@ -67,7 +67,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: watermark, el: this.watermark,
top: 0, top: 0,
left: 5 left: 5
}] }]
@ -85,6 +85,15 @@ BI.CodeEditor = BI.inherit(BI.Single, {
this.editor.setOption("readOnly", b === true ? false : "nocursor") this.editor.setOption("readOnly", b === true ? false : "nocursor")
}, },
_checkWaterMark: function () {
var o = this.options;
if (BI.isEmptyString(this.editor.getValue()) && BI.isKey(o.watermark)) {
this.watermark && this.watermark.visible();
} else {
this.watermark && this.watermark.invisible();
}
},
insertParam: function (param) { insertParam: function (param) {
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
@ -139,7 +148,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
} else { } else {
self.insertString(item); self.insertString(item);
} }
}) });
this._checkWaterMark();
}, },
focus: function () { focus: function () {

Loading…
Cancel
Save