Browse Source

Merge pull request #116 in FUI/fineui from ~GUY/fineui:master to master

* commit 'b2b05ba6054172228c60ccf57a338ebf4cfbc497':
  富文本
  readme
es6
guy 7 years ago
parent
commit
9524424348
  1. 6
      README.md
  2. 85
      bi/base.js
  3. 85
      dist/base.js
  4. 85
      dist/bundle.js
  5. 56
      dist/bundle.min.js
  6. 85
      src/base/richeditor/bar/action.richeditor.param.js

6
README.md

@ -7,12 +7,16 @@ For more details, see the website [http://www.fanruan.com](http://www.fanruan.co
Documentation Documentation
============= =============
## Demo
GithubPages: [https://fanruan.github.io/fineui](https://fanruan.github.io/fineui) GithubPages: [https://fanruan.github.io/fineui](https://fanruan.github.io/fineui)
CodingPages: [http://fanruan.coding.me/fineui](http://fanruan.coding.me/fineui) CodingPages: [http://fanruan.coding.me/fineui](http://fanruan.coding.me/fineui)
Demo
=============
CodingPages: [http://fanruan.coding.me/fineui/dist/index.html](http://fanruan.coding.me/fineui/dist/index.html)
License License
============ ============

85
bi/base.js

@ -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("&nbsp;")[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;
} }
} }

85
dist/base.js vendored

@ -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("&nbsp;")[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;
} }
} }

85
dist/bundle.js vendored

@ -45176,10 +45176,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("&nbsp;")[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;
@ -45187,33 +45203,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
@ -45228,44 +45223,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;
} }
} }

56
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

85
src/base/richeditor/bar/action.richeditor.param.js

@ -11,10 +11,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("&nbsp;")[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;
@ -22,33 +38,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
@ -63,44 +58,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;
} }
} }

Loading…
Cancel
Save