又一动漫被下架,网友直呼丢失童年,是谁让“天性”成为了负担?
2018-03-05 11:03:21
KindEditor版本:4.1.10 (2013-11-23),具体可以去官网下载:http://kindeditor.net/down.php
基本的配置这里不说了,官网有文档,贴代码:
-
<textarea id="content" style="width:80%;height:100px;">textarea>
-
-
var editor;
-
-
-
$.getScript('../kindeditor/kindeditor-min.js', function () {
-
KindEditor.basePath = '../kindeditor/';
-
editor = KindEditor.create('textarea[id="content"]', {
-
id : 'editor_id',
-
uploadJson : '../kindeditor/asp.net/upload_json.ashx',
-
fileManagerJson : '../kindeditor/asp.net/file_manager_json.ashx',
-
allowFileManager : true,
-
resizeType : 1,
-
items : [
-
'undo', 'redo', '|',
-
'fontname', 'fontsize', '|',
-
'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|',
-
'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
-
'image', 'link', '|', 'preview'],
-
autoHeightMode : true,
-
afterCreate : function () {
-
this.loadPlugin('autoheight');
-
-
var __doc = this.edit.doc;
-
-
-
-
$(__doc).bind('paste', null, function () {
-
setTimeout(function () {
-
parent.uploadWebImg(editor);
-
}, 200);
-
});
-
},
-
afterChange : function () {
-
$('.word_count').html(this.count());
-
},
-
});
-
});
这里注意,要修改下kindeditor-min.js这个文件中的一个地方,不然粘贴的文本在事件响应之后(表现就是没有内容粘贴到编辑器中)
通过源代码可以在这里看到:https://github.com/kindsoft/kindeditor/blob/master/kindeditor-all.js
影响的具体方法就看自己这么写了,我的uploadWebImg代码贴到下面,用的layer弹窗组件,具体看它的官网api,这里不多说。
-
-
function uploadWebImg(editor) {
-
var relaceSrc = [];
-
var imgs = $(editor.html()).find('img');
-
-
imgs.map(function () {
-
var _src = $(this).attr('src');
-
-
if (_src.indexOf('http://') >= 0 || _src.indexOf('https://') >= 0) { //考虑可能有动态生成的图片
-
relaceSrc.push({ k: _src });
-
};
-
});
-
-
if (relaceSrc.length == 0) return;
-
-
var msg = '内容包含' + relaceSrc.length.toString() + '张远程图片,是否现在上传?';
-
-
confirmLayerNormal(msg, function (_index) {
-
var loading = layer.load(0);
-
var paramdata = {
-
action: "791c252eee12530f4f3af326674b7d97",
-
arg: { imgs: relaceSrc },
-
};
-
-
doAjaxPost(paramdata, function (result) {
-
layer.close(loading);
-
if (!result.success) {
-
SuperSite.MsgError(result.msg);
-
return;
-
}
-
-
-
var _content = editor.html();
-
$(relaceSrc).each(function (idx, dom) {
-
_content = _content.replace(dom.k, result.data[idx].value);
-
});
-
editor.html(_content);
-
-
SuperSite.MsgOK('远程图片上传成功');
-
});
-
layer.close(_index);
-
});
-
};
服务端的代码:
-
-
-
-
private void UploadWebImg()
-
{
-
var ajaxdata = base.GetActionParamData();
-
if (ajaxdata == null || ajaxdata.imgs == null || ajaxdata.imgs.Count == 0)
-
Outmsg(false, outmsg: "未获取到上传的图片地址");
-
-
var len = ajaxdata.imgs.Count;
-
var tempurl = new List();
-
var stkimg = new Stack(len);
-
-
for (int i = 0; i < len; i++)
-
{
-
var img = ajaxdata.imgs[i].k.Trim();
-
-
if (stkimg.Any(x => x.value == img))
-
{
-
var loadedpath = stkimg.First(x => x.value == img).value;
-
tempurl.Add(new KeyValueDesc
-
{
-
key = i.ToString(),
-
value = loadedpath,
-
desc = (int)EnumCenter.UploadImgStatus.Repeat
-
});
-
continue;
-
}
-
-
var tb = DownLoadWebImg(img);
-
stkimg.Push(new KeyValue { key = i.ToString(), value = tb.Item2 });
-
tempurl.Add(new KeyValueDesc
-
{
-
key = i.ToString(),
-
value = tb.Item2,
-
desc = tb.Item1 ?
-
(int)EnumCenter.UploadImgStatus.OK :
-
(int)EnumCenter.UploadImgStatus.Error
-
});
-
}
-
-
Outmsg(true, outdata: tempurl);
-
}
-
private Tuple<bool, string> DownLoadWebImg(string url)
-
{
-
try
-
{
-
var dt = DateTime.Now;
-
var folder = "/upload/image/" + dt.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo) + "/";
-
var newfile = dt.ToString("HHmmss_ffff", DateTimeFormatInfo.InvariantInfo)
-
+ url.Substring(url.LastIndexOf('.'));
-
var filepath = Server.MapPath(folder);
-
-
if (!Directory.Exists(filepath))
-
{
-
Directory.CreateDirectory(filepath);
-
}
-
-
using (WebClient mywebclient = new WebClient())
-
{
-
mywebclient.DownloadFile(url, filepath + newfile);
-
return new Tuple<bool, string>(true, folder + newfile);
-
}
-
}
-
catch (Exception ex)
-
{
-
Tools.LogHelp.WriteLog("下载远程图片失败", ex);
-
return new Tuple<bool, string>(false, url);
-
}
-
}
-