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. 83
      bi/base.js
  3. 83
      dist/base.js
  4. 83
      dist/bundle.js
  5. 56
      dist/bundle.min.js
  6. 83
      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
=============
## Demo
GithubPages: [https://fanruan.github.io/fineui](https://fanruan.github.io/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
============

83
bi/base.js

@ -16317,10 +16317,26 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
_init: function () {
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 instance = o.editor.selectedInstance;
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) {
sel = sel.parent();
}
var value = sel.attr("data-value");
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();
}
return sel;
},
addParam: function (param) {
var o = this.options;
var instance = o.editor.selectedInstance;
var sel = $(instance.selElm());
var sel = this._get$Sel();
var $param = $("<span>").attr({
"data-type": "param",
"data-value": param
@ -16369,44 +16364,32 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
var wrapper = o.editor.instance.getElm().element;
if (wrapper.find(sel).length <= 0) {
wrapper.append($param);
instance.setFocus($param[0]);
return;
}
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]);
sel.after($param);
}
this._addBlank($param);
},
keydown: function (e) {
var o = this.options;
var instance = o.editor.selectedInstance;
var wrapper = instance.getElm().element;
var sel = $(instance.selElm());
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
sel = sel.parent();
var sel = this._get$Sel();
if (e.keyCode === 229) {//中文输入法
if (this._isParam(sel)) {
this._addBlank(sel);
e.stopEvent();
return false;
}
if (BI.Key[e.keyCode]) {
if (sel.attr("data-type") === "param") {
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]);
}
if (BI.Key[e.keyCode] || e.keyCode === BI.KeyCode.TAB || e.keyCode === BI.KeyCode.ENTER || e.keyCode === BI.KeyCode.SPACE) {
if (this._isParam(sel)) {
e.stopEvent();
return false;
}
}
if (e.keyCode === BI.KeyCode.BACKSPACE) {
if (sel.attr("data-type") === "param") {//删除后鼠标停留在参数中间
if (this._isParam(sel)) {
sel.destroy();
e.stopEvent();
e.preventDefault();
return false;
}
}

83
dist/base.js vendored

@ -16317,10 +16317,26 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
_init: function () {
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 instance = o.editor.selectedInstance;
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) {
sel = sel.parent();
}
var value = sel.attr("data-value");
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();
}
return sel;
},
addParam: function (param) {
var o = this.options;
var instance = o.editor.selectedInstance;
var sel = $(instance.selElm());
var sel = this._get$Sel();
var $param = $("<span>").attr({
"data-type": "param",
"data-value": param
@ -16369,44 +16364,32 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
var wrapper = o.editor.instance.getElm().element;
if (wrapper.find(sel).length <= 0) {
wrapper.append($param);
instance.setFocus($param[0]);
return;
}
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]);
sel.after($param);
}
this._addBlank($param);
},
keydown: function (e) {
var o = this.options;
var instance = o.editor.selectedInstance;
var wrapper = instance.getElm().element;
var sel = $(instance.selElm());
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
sel = sel.parent();
var sel = this._get$Sel();
if (e.keyCode === 229) {//中文输入法
if (this._isParam(sel)) {
this._addBlank(sel);
e.stopEvent();
return false;
}
if (BI.Key[e.keyCode]) {
if (sel.attr("data-type") === "param") {
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]);
}
if (BI.Key[e.keyCode] || e.keyCode === BI.KeyCode.TAB || e.keyCode === BI.KeyCode.ENTER || e.keyCode === BI.KeyCode.SPACE) {
if (this._isParam(sel)) {
e.stopEvent();
return false;
}
}
if (e.keyCode === BI.KeyCode.BACKSPACE) {
if (sel.attr("data-type") === "param") {//删除后鼠标停留在参数中间
if (this._isParam(sel)) {
sel.destroy();
e.stopEvent();
e.preventDefault();
return false;
}
}

83
dist/bundle.js vendored

@ -45176,10 +45176,26 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
_init: function () {
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 instance = o.editor.selectedInstance;
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) {
sel = sel.parent();
}
var value = sel.attr("data-value");
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();
}
return sel;
},
addParam: function (param) {
var o = this.options;
var instance = o.editor.selectedInstance;
var sel = $(instance.selElm());
var sel = this._get$Sel();
var $param = $("<span>").attr({
"data-type": "param",
"data-value": param
@ -45228,44 +45223,32 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
var wrapper = o.editor.instance.getElm().element;
if (wrapper.find(sel).length <= 0) {
wrapper.append($param);
instance.setFocus($param[0]);
return;
}
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]);
sel.after($param);
}
this._addBlank($param);
},
keydown: function (e) {
var o = this.options;
var instance = o.editor.selectedInstance;
var wrapper = instance.getElm().element;
var sel = $(instance.selElm());
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
sel = sel.parent();
var sel = this._get$Sel();
if (e.keyCode === 229) {//中文输入法
if (this._isParam(sel)) {
this._addBlank(sel);
e.stopEvent();
return false;
}
if (BI.Key[e.keyCode]) {
if (sel.attr("data-type") === "param") {
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]);
}
if (BI.Key[e.keyCode] || e.keyCode === BI.KeyCode.TAB || e.keyCode === BI.KeyCode.ENTER || e.keyCode === BI.KeyCode.SPACE) {
if (this._isParam(sel)) {
e.stopEvent();
return false;
}
}
if (e.keyCode === BI.KeyCode.BACKSPACE) {
if (sel.attr("data-type") === "param") {//删除后鼠标停留在参数中间
if (this._isParam(sel)) {
sel.destroy();
e.stopEvent();
e.preventDefault();
return false;
}
}

56
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

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

@ -11,10 +11,26 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
_init: function () {
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 instance = o.editor.selectedInstance;
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) {
sel = sel.parent();
}
var value = sel.attr("data-value");
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();
}
return sel;
},
addParam: function (param) {
var o = this.options;
var instance = o.editor.selectedInstance;
var sel = $(instance.selElm());
var sel = this._get$Sel();
var $param = $("<span>").attr({
"data-type": "param",
"data-value": param
@ -63,44 +58,32 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
var wrapper = o.editor.instance.getElm().element;
if (wrapper.find(sel).length <= 0) {
wrapper.append($param);
instance.setFocus($param[0]);
return;
}
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]);
sel.after($param);
}
this._addBlank($param);
},
keydown: function (e) {
var o = this.options;
var instance = o.editor.selectedInstance;
var wrapper = instance.getElm().element;
var sel = $(instance.selElm());
if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
sel = sel.parent();
var sel = this._get$Sel();
if (e.keyCode === 229) {//中文输入法
if (this._isParam(sel)) {
this._addBlank(sel);
e.stopEvent();
return false;
}
}
if (BI.Key[e.keyCode]) {
if (sel.attr("data-type") === "param") {
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]);
if (BI.Key[e.keyCode] || e.keyCode === BI.KeyCode.TAB || e.keyCode === BI.KeyCode.ENTER || e.keyCode === BI.KeyCode.SPACE) {
if (this._isParam(sel)) {
e.stopEvent();
return false;
}
}
if (e.keyCode === BI.KeyCode.BACKSPACE) {
if (sel.attr("data-type") === "param") {//删除后鼠标停留在参数中间
if (this._isParam(sel)) {
sel.destroy();
e.stopEvent();
e.preventDefault();
return false;
}
}

Loading…
Cancel
Save