Skip to content

Commit

Permalink
feat support form submit
Browse files Browse the repository at this point in the history
  • Loading branch information
ganzw committed Apr 17, 2016
1 parent f291cf3 commit a93e6be
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ artEditor是一款基于jQuery的移动端富文本编辑器,支持插入图
图片上传成功回调
### uploadError
图片上传失败回调
### formInputId
表单隐藏域id,如果设置,则编辑器内容会储存到该元素value值


# Methods
Expand Down Expand Up @@ -78,3 +80,5 @@ $('#content').artEditor({
+ 插入图片自动换行
2016-03-28
+ 增加拍照上传图片
2016-04-17
+ 增加表单提交功能
16 changes: 13 additions & 3 deletions artEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ $.fn.extend({
} catch(e) {
console.log(e);
}
if(_this._opt.formInputId && $('#'+_this._opt.formInputId)[0]) {
$(_this).on('input', function() {
$('#'+_this._opt.formInputId).val(_this.getValue());
});
}
},
upload: function(data) {
var _this = this, filed = _this._opt.uploadField;
Expand Down Expand Up @@ -89,17 +94,22 @@ $.fn.extend({
selection.removeAllRanges();
selection.addRange(range);
}
if(this._opt.formInputId && $('#'+this._opt.formInputId)[0]) {
$('#'+this._opt.formInputId).val(this.getValue());
}
},
pasteHandler: function() {
var _this = this;
$(this).on("paste", function() {
/*var content = $(this).html();
$(this).on("paste", function(e) {
console.log(e.clipboardData.items);
var content = $(this).html();
console.log(content);
valiHTML = _this._opt.validHtml;
content = content.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(/<\/ ?tr[^>]*>/gi, "[br]").replace(/<\/ ?td[^>]*>/gi, "&nbsp;&nbsp;").replace(/<(ul|dl|ol)[^>]*>/gi, "[br]").replace(/<(li|dd)[^>]*>/gi, "[br]").replace(/<p [^>]*>/gi, "[br]").replace(new RegExp("<(/?(?:" + valiHTML.join("|") + ")[^>]*)>", "gi"), "[$1]").replace(new RegExp('<span([^>]*class="?at"?[^>]*)>', "gi"), "[span$1]").replace(/<[^>]*>/g, "").replace(/\[\[\-/g, "[").replace(/\-\]\]/g, "]").replace(new RegExp("\\[(/?(?:" + valiHTML.join("|") + "|img|span)[^\\]]*)\\]", "gi"), "<$1>");
if (!/firefox/.test(navigator.userAgent.toLowerCase())) {
content = content.replace(/\r?\n/gi, "<br>");
}
$(this).html(content);*/
$(this).html(content);
});
},
placeholderHandler: function() {
Expand Down
7 changes: 6 additions & 1 deletion artEditor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion example/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ $(function() {
data: {},
uploadField: 'image',
placeholader: '<p>请输入文章正文内容</p>',
validHtml: ["br"],
validHtml: ["<br/>"],
formInputId: 'target',
uploadSuccess: function(res) {
// return img url
return res.path;
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</div>
<div class="publish-article-content">
<div class="title-tips">正文</div>
<input type="hidden" id="target">
<div class="article-content" id="content">
</div>
<div class="footer-btn g-image-upload-box">
Expand Down

0 comments on commit a93e6be

Please sign in to comment.