* finish task #5074.

This commit is contained in:
Catouse
2018-11-16 11:00:26 +08:00
parent 05a48efe90
commit d8250402c4
3 changed files with 41 additions and 9 deletions
+2
View File
@@ -523,6 +523,8 @@ $lang->searchMore = "More results:";
$lang->chooseUsersToMail = "Choose users to be notified.";
$lang->browserNotice = 'Your current browser might not display the best effect. Use Chrome, Firefox, IE9+, Opera or Safari.';
$lang->noticePasteImg = "Paste images here";
$lang->pasteImgFail = "Paste image fail, try again later.";
$lang->pasteImgUploading = "Please wait image uploading...";
/* Time formats settings. */
if(!defined('DT_DATETIME1')) define('DT_DATETIME1', 'Y-m-d H:i:s');
+2
View File
@@ -520,6 +520,8 @@ $lang->searchMore = "搜索此关键字的更多结果:";
$lang->chooseUsersToMail = "选择要发信通知的用户...";
$lang->browserNotice = '你目前使用的浏览器可能无法得到最佳浏览效果,建议使用Chrome、火狐、IE9+、Opera、Safari浏览器。';
$lang->noticePasteImg = "可以在编辑器直接贴图。";
$lang->pasteImgFail = "贴图失败,请稍后重试。";
$lang->pasteImgUploading = "正在上传图片,请稍后...";
/* 时间格式设置。*/
if(!defined('DT_DATETIME1')) define('DT_DATETIME1', 'Y-m-d H:i:s');
+37 -9
View File
@@ -37,6 +37,7 @@ $uid = uniqid('');
'table', 'code', '|', 'pagebreak', 'anchor', '|',
'fullscreen', 'source', 'preview', 'about'];
var editorToolsMap = {fullTools: fullTools, simpleTools: simpleTools, bugTools: bugTools};
var imageLoadingEle = '<div class="image-loading-ele small" style="padding: 5px; background: #f1f1f1; width: 300px; border-radius: 2px;"><i class="icon icon-spin icon-spinner-indicator text-muted"></i> <?php echo $this->lang->pasteImgUploading?></div>';
// Kindeditor default options
var editorDefaults =
@@ -119,6 +120,29 @@ $uid = uniqid('');
placeholder += ' <?php echo $this->lang->noticePasteImg?>';
}
var pasteBegin = function()
{
$.enableForm(false);
$('body').one('click.ke' + kuid, function(){$.enableForm(true);});
cmd.inserthtml(imageLoadingEle);
keditor.readonly(true);
};
var pasteEnd = function(error)
{
if(error)
{
if(error === true) error = '<?php echo $this->lang->pasteImgFail;?>';
$.zui.messager.danger(error, {placement: 'center'});
}
$.enableForm(true);
$('body').off('.ke' + kuid);
$(doc.body).find('.image-loading-ele').remove();
keditor.readonly(false);
};
var pasteUrl = createLink('file', 'ajaxPasteImage', 'uid=' + kuid);
/* Paste in chrome.*/
/* Code reference from http://www.foliotek.com/devblog/copy-images-from-clipboard-in-javascript/. */
if(K.WEBKIT)
@@ -130,8 +154,7 @@ $uid = uniqid('');
var file = original.clipboardData.items[0].getAsFile();
if(file)
{
$('#submit').attr('disabled', 'disabled');
$("body").click(function(){$('#submit').removeAttr('disabled');});
pasteBegin();
var reader = new FileReader();
reader.onload = function(evt)
@@ -142,10 +165,13 @@ $uid = uniqid('');
var contentType = arr[0].split(";")[0].split(":")[1];
html = '<img src="' + result + '" alt="" />';
$.post(createLink('file', 'ajaxPasteImage', 'uid=' + kuid), {editor: html}, function(data)
$.post(pasteUrl, {editor: html}, function(data)
{
cmd.inserthtml(data);
$('#submit').removeAttr('disabled');
pasteEnd();
}).error(function()
{
pasteEnd(true);
});
};
reader.readAsDataURL(file);
@@ -162,13 +188,15 @@ $uid = uniqid('');
var html = K(doc.body).html();
if(html.search(/<img src="data:.+;base64,/) > -1)
{
$('#submit').attr('disabled', 'disabled');
$("body").click(function(){$('#submit').removeAttr('disabled');});
$.post(createLink('file', 'ajaxPasteImage', 'uid=' + kuid), {editor: html}, function(data)
pasteBegin();
$.post(pasteUrl, {editor: html}, function(data)
{
if(data.indexOf('<img') == 0) data = '<p>' + data + '</p>';
if(data.indexOf('<img') === 0) data = '<p>' + data + '</p>';
frame.html(data);
$('#submit').removeAttr('disabled');
pasteEnd();
}).error(function()
{
pasteEnd(true);
});
}
}, 80);