使用js实现一款简单的编辑器插件,可以实现文字的编辑,图片的上传操作。
/**
* 自定义编辑器
* @param {Object} id 编辑区
* @param {Object} control 操作区
*/
function insertImg(id, control, dataparams, fun){
this.bigBox = document.getElementById(id),
this.handles = document.getElementById(control),
this.handle = this.handles.children[0],
this.handleChildt = this.handle.children[1],
this.gethtml = this.handles.children[1],
param = dataparams,
funs = fun,
this.init()
}
insertImg.prototype = {
init:function(){
this.edit(); //编辑操作
this.getResult(); //编辑操作
},
pasteHandler:function() {
var that = this;
/**
* 监控粘贴(ctrl+v),粘贴过来的替换多余的html代码,只保留<br>
*/
setTimeout(function() {
var content = that.innerHTML;
valiHTML = ["br"];
content = content.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(/<\/ ?tr[^>]*>/gi, "[br]").replace(/<\/ ?td[^>]*>/gi, " ").replace(/<(ul|dl|ol)[^>]*>/gi, "[br]").replace(/<(li|dd)[^>]*>/gi, "[br]").replace(/<p [^>]*>/gi, "[br]").replace(new RegExp("<(/?(?:" + valiHTML.join("|") + ")[^>]*)>",