|
|
@ -16317,10 +16317,26 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, { |
|
|
|
|
|
|
|
|
|
|
|
_init: function () { |
|
|
|
_init: function () { |
|
|
|
BI.RichEditorParamAction.superclass._init.apply(this, arguments); |
|
|
|
BI.RichEditorParamAction.superclass._init.apply(this, arguments); |
|
|
|
this.options.editor.instance.getElm().element.on("textchange", BI.bind(this._checkParam, this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_checkParam: function (e) { |
|
|
|
_isParam: function (sel) { |
|
|
|
|
|
|
|
return sel.attr("data-type") === "param"; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_addBlank: function ($param) { |
|
|
|
|
|
|
|
var o = this.options; |
|
|
|
|
|
|
|
var instance = o.editor.selectedInstance; |
|
|
|
|
|
|
|
var next = $param.next(); |
|
|
|
|
|
|
|
if (next.length === 0 || this._isParam(next)) { |
|
|
|
|
|
|
|
var node = $("<span>").html(" ")[0]; |
|
|
|
|
|
|
|
$param.after(node); |
|
|
|
|
|
|
|
instance.setFocus(node); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
instance.setFocus(next[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get$Sel: function () { |
|
|
|
var o = this.options; |
|
|
|
var o = this.options; |
|
|
|
var instance = o.editor.selectedInstance; |
|
|
|
var instance = o.editor.selectedInstance; |
|
|
|
var wrapper = instance.getElm().element; |
|
|
|
var wrapper = instance.getElm().element; |
|
|
@ -16328,33 +16344,12 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, { |
|
|
|
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { |
|
|
|
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { |
|
|
|
sel = sel.parent(); |
|
|
|
sel = sel.parent(); |
|
|
|
} |
|
|
|
} |
|
|
|
var value = sel.attr("data-value"); |
|
|
|
return sel; |
|
|
|
var text = sel.text(); |
|
|
|
|
|
|
|
text = BI.trim(text.replaceAll(" ", "")); |
|
|
|
|
|
|
|
//检查光标前一个元素
|
|
|
|
|
|
|
|
if (sel.attr("data-type") === "param" && text !== value) { |
|
|
|
|
|
|
|
if (text.indexOf(value) === 0) { |
|
|
|
|
|
|
|
var extra = sel.text().slice(value.length); |
|
|
|
|
|
|
|
if (extra.length > 0) { |
|
|
|
|
|
|
|
var span = $("<span>").text(extra); |
|
|
|
|
|
|
|
sel.after(span); |
|
|
|
|
|
|
|
sel.text(sel.attr("data-value")); |
|
|
|
|
|
|
|
instance.setFocus(span[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sel.text(sel.attr("data-value")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//检查光标后一个元素
|
|
|
|
|
|
|
|
if (sel.next().attr("data-type") === "param" && sel.next().text() !== sel.next().attr("data-value")) { |
|
|
|
|
|
|
|
sel.next().destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addParam: function (param) { |
|
|
|
addParam: function (param) { |
|
|
|
var o = this.options; |
|
|
|
var o = this.options; |
|
|
|
var instance = o.editor.selectedInstance; |
|
|
|
var sel = this._get$Sel(); |
|
|
|
var sel = $(instance.selElm()); |
|
|
|
|
|
|
|
var $param = $("<span>").attr({ |
|
|
|
var $param = $("<span>").attr({ |
|
|
|
"data-type": "param", |
|
|
|
"data-type": "param", |
|
|
|
"data-value": param |
|
|
|
"data-value": param |
|
|
@ -16369,44 +16364,32 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, { |
|
|
|
var wrapper = o.editor.instance.getElm().element; |
|
|
|
var wrapper = o.editor.instance.getElm().element; |
|
|
|
if (wrapper.find(sel).length <= 0) { |
|
|
|
if (wrapper.find(sel).length <= 0) { |
|
|
|
wrapper.append($param); |
|
|
|
wrapper.append($param); |
|
|
|
instance.setFocus($param[0]); |
|
|
|
} else { |
|
|
|
return; |
|
|
|
sel.after($param); |
|
|
|
} |
|
|
|
|
|
|
|
var ln = sel.closest("a"); |
|
|
|
|
|
|
|
if (ln.length === 0) { |
|
|
|
|
|
|
|
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { |
|
|
|
|
|
|
|
sel.parent().after($param); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sel.after($param) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
instance.setFocus($param[0]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this._addBlank($param); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
keydown: function (e) { |
|
|
|
keydown: function (e) { |
|
|
|
var o = this.options; |
|
|
|
var o = this.options; |
|
|
|
var instance = o.editor.selectedInstance; |
|
|
|
var sel = this._get$Sel(); |
|
|
|
var wrapper = instance.getElm().element; |
|
|
|
if (e.keyCode === 229) {//中文输入法
|
|
|
|
var sel = $(instance.selElm()); |
|
|
|
if (this._isParam(sel)) { |
|
|
|
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { |
|
|
|
this._addBlank(sel); |
|
|
|
sel = sel.parent(); |
|
|
|
e.stopEvent(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.Key[e.keyCode]) { |
|
|
|
if (BI.Key[e.keyCode] || e.keyCode === BI.KeyCode.TAB || e.keyCode === BI.KeyCode.ENTER || e.keyCode === BI.KeyCode.SPACE) { |
|
|
|
if (sel.attr("data-type") === "param") { |
|
|
|
if (this._isParam(sel)) { |
|
|
|
var key = BI.Key[e.keyCode]; |
|
|
|
|
|
|
|
key = e.shiftKey ? key.toUpperCase() : key; |
|
|
|
|
|
|
|
var span = $("<span>").text(key); |
|
|
|
|
|
|
|
sel.after(span); |
|
|
|
|
|
|
|
sel.text(sel.attr("data-value")); |
|
|
|
|
|
|
|
instance.setFocus(span[0]); |
|
|
|
|
|
|
|
e.stopEvent(); |
|
|
|
e.stopEvent(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (e.keyCode === BI.KeyCode.BACKSPACE) { |
|
|
|
if (e.keyCode === BI.KeyCode.BACKSPACE) { |
|
|
|
if (sel.attr("data-type") === "param") {//删除后鼠标停留在参数中间
|
|
|
|
if (this._isParam(sel)) { |
|
|
|
sel.destroy(); |
|
|
|
sel.destroy(); |
|
|
|
e.stopEvent(); |
|
|
|
e.preventDefault(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|