Permalink
Browse files

Now you can paste an image from clicpboard into the editor directly.

  • Loading branch information...
joyqi committed Oct 23, 2018
1 parent ad10000 commit 0b1096c588a68ac83eac283862fedb459afb3327
@@ -2,6 +2,7 @@
<?php $content = !empty($post) ? $post : $page; if ($options->markdown): ?>
<script src="<?php $options->adminStaticUrl('js', 'hyperdown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'pagedown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'paste.js?v=' . $suffixVersion); ?>"></script>
<script>
$(document).ready(function () {
var textarea = $('#text'),
@@ -203,6 +204,17 @@ function initMarkdown() {
return false;
});
// 剪贴板复制图片
textarea.pastableTextarea().on('pasteImage', function (e, data) {
name = data.name.replace(/[\(\)\[\]\*#!]/g, '');

This comment has been minimized.

@mmmwhy

mmmwhy Dec 16, 2018

name = Math.random().toString(10).substr(2, 10);

if (!name.match(/\.[a-z0-9]{2,}$/i)) {
var ext = data.blob.type.split('/').pop();
name += '.' + ext;
}
Typecho.uploadFile(new File([data.blob], name), name);
});
}
if (isMarkdown) {
@@ -120,8 +120,8 @@ function fileUploadComplete (id, url, data) {
}
}
$('#tab-files').bind('init', function () {
var uploader = new plupload.Uploader({
var uploader = null, tabFilesEl = $('#tab-files').bind('init', function () {
uploader = new plupload.Uploader({
browse_button : $('.upload-file').get(0),
url : '<?php $security->index('/action/upload'
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
@@ -176,6 +176,23 @@ function fileUploadComplete (id, url, data) {
uploader.init();
});
Typecho.uploadFile = function (file, name) {
if (!uploader) {
$('#tab-files-btn').parent().trigger('click');
}
var timer = setInterval(function () {
if (!uploader) {
return;
}
clearInterval(timer);
timer = null;
uploader.addFile(file, name);
}, 50);
};
function attachInsertEvent (el) {
$('.insert', el).click(function () {
var t = $(this), p = t.parents('li');
Oops, something went wrong.

0 comments on commit 0b1096c

Please sign in to comment.