Skip to content

Commit

Permalink
Now you can paste an image from clicpboard into the editor directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Oct 23, 2018
1 parent ad10000 commit 0b1096c
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 20 deletions.
12 changes: 12 additions & 0 deletions admin/editor-js.php
Expand Up @@ -2,6 +2,7 @@
<?php $content = !empty($post) ? $post : $page; if ($options->markdown): ?> <?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', 'hyperdown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'pagedown.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> <script>
$(document).ready(function () { $(document).ready(function () {
var textarea = $('#text'), var textarea = $('#text'),
Expand Down Expand Up @@ -203,6 +204,17 @@ function initMarkdown() {


return false; return false;
}); });

// 剪贴板复制图片
textarea.pastableTextarea().on('pasteImage', function (e, data) {
name = data.name.replace(/[\(\)\[\]\*#!]/g, '');

This comment has been minimized.

Copy link
@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) { if (isMarkdown) {
Expand Down
21 changes: 19 additions & 2 deletions admin/file-upload-js.php
Expand Up @@ -120,8 +120,8 @@ function fileUploadComplete (id, url, data) {
} }
} }


$('#tab-files').bind('init', function () { var uploader = null, tabFilesEl = $('#tab-files').bind('init', function () {
var uploader = new plupload.Uploader({ uploader = new plupload.Uploader({
browse_button : $('.upload-file').get(0), browse_button : $('.upload-file').get(0),
url : '<?php $security->index('/action/upload' url : '<?php $security->index('/action/upload'
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>', . (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
Expand Down Expand Up @@ -176,6 +176,23 @@ function fileUploadComplete (id, url, data) {
uploader.init(); 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) { function attachInsertEvent (el) {
$('.insert', el).click(function () { $('.insert', el).click(function () {
var t = $(this), p = t.parents('li'); var t = $(this), p = t.parents('li');
Expand Down

0 comments on commit 0b1096c

Please sign in to comment.