From b0be7a14d21e1ba51b6a6341bdbb55e99764e887 Mon Sep 17 00:00:00 2001 From: lealife Date: Fri, 30 Oct 2015 13:48:54 +0800 Subject: [PATCH] =?UTF-8?q?ctrl+v=20=E5=A4=8D=E5=88=B6=E5=9B=BE=E7=89=87,?= =?UTF-8?q?=20=E6=9C=89=E6=97=B6=E4=B8=8D=E6=98=BE=E7=A4=BA,=20=E4=BD=86?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/leanote/leanote/issues/227 --- public/js/plugins/attachment_upload.js | 4 +- public/js/plugins/editor_drop_paste.js | 27 +++++++++--- .../plugins/paste/classes/Clipboard.js | 43 +++++++++++++------ public/tinymce/plugins/paste/plugin.js | 43 +++++++++++++------ public/tinymce/plugins/paste/plugin.min.js | 2 +- 5 files changed, 84 insertions(+), 35 deletions(-) diff --git a/public/js/plugins/attachment_upload.js b/public/js/plugins/attachment_upload.js index a628a4a..ec8efaf 100644 --- a/public/js/plugins/attachment_upload.js +++ b/public/js/plugins/attachment_upload.js @@ -72,7 +72,7 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){ return; } - var tpl = $('
×
'); + var tpl = $('
×
'); // Append the file name and file size tpl.append(data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ']'); @@ -141,4 +141,4 @@ define('attachment_upload', ['jquery.ui.widget', 'fileupload'], function(){ }; initUploader(); -}); \ No newline at end of file +}); diff --git a/public/js/plugins/editor_drop_paste.js b/public/js/plugins/editor_drop_paste.js index ca0bae6..12514b2 100644 --- a/public/js/plugins/editor_drop_paste.js +++ b/public/js/plugins/editor_drop_paste.js @@ -1,7 +1,19 @@ // for editor. // drag image to editor var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; -define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ +define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function() { + + // 在toggle成pre或ace时 + // 最后没有元素, 或者元素不是p, 则在最后插入之 + function insertPIfNotExists() { + var children = $('#editorContent').children(); + var lastChild = children && children.length > 0 ? children[children.length - 1] : null; + if (!lastChild || lastChild.tagName != 'P') { + $('#editorContent').append('


'); + } + } + + // 粘贴图片的进度控制 function Process(editor) { var id = '__mcenew' + (new Date()).getTime(); var str = '
' + @@ -13,7 +25,10 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ '
' + ''; this.containerStr = str; + editor.insertContent(str); + insertPIfNotExists(); + var container = $('#' + id); this.container = container; this.id = id; @@ -111,7 +126,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) { if(reIsOk(re) && re.Id) { var urlPrefix = window.location.protocol + "//" + window.location.host; - data.src = urlPrefix + "/file/outputImage?fileId=" + re.Id; + data.src = urlPrefix + "/api/file/getImage?fileId=" + re.Id; } renderImage(data); }); @@ -147,7 +162,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ // This function is called when a file is added to the queue; // either via the browse button, or via drag/drop: add: function(e, data) { - var tpl = $('
  • '); + var tpl = $('
  • '); // Append the file name and file size tpl.find('div').append(data.files[0].name + ' [' + formatFileSize(data.files[0].size) + ']'); @@ -165,7 +180,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ if (data.result.Ok == true) { data.context.remove(); // life - var data2 = {src: urlPrefix + "/file/outputImage?fileId=" + data.result.Id} + var data2 = {src: urlPrefix + "/api/file/getImage?fileId=" + data.result.Id} insertImage(data2); } else { data.context.empty(); @@ -355,7 +370,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ } // 这里, 如果图片宽度过大, 这里设置成500px var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; - var src = urlPrefix + "/file/outputImage?fileId=" + re.Id; + var src = urlPrefix + "/api/file/getImage?fileId=" + re.Id; getImageSize(src, function(wh) { // life 4/25 if(wh && wh.width) { @@ -379,7 +394,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function(){ // 这里, 如果图片宽度过大, 这里设置成500px var re = data.result; var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host; - var src = urlPrefix + "/file/outputImage?fileId=" + re.Id; + var src = urlPrefix + "/api/file/getImage?fileId=" + re.Id; if(curNote && !curNote.IsMarkdown) { data.process.replace(src); diff --git a/public/tinymce/plugins/paste/classes/Clipboard.js b/public/tinymce/plugins/paste/classes/Clipboard.js index 6106b35..f344dfc 100644 --- a/public/tinymce/plugins/paste/classes/Clipboard.js +++ b/public/tinymce/plugins/paste/classes/Clipboard.js @@ -341,7 +341,31 @@ define("tinymce/pasteplugin/Clipboard", [ document.body.appendChild(img); } + // 是否有图片的粘贴, 有则删除paste bin + // 因为paste bin隐藏不见了, 如果不删除, 则editor_drop_paste的图片就会在这个bin下 + // 而且, paste bin最后会删除, 导致图片不能显示 + function hasImage(event) { + var items; + if (event.clipboardData) { + items = event.clipboardData.items; + } + else if(event.originalEvent && event.originalEvent.clipboardData) { + items = event.originalEvent.clipboardData; + } + if (!items) { + return false; + } + // find pasted image among pasted items + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + return true; + } + } + return false; + } + // 上传图片 + // 已过时, 不用, pasteImage在editor_drop_paste.js中用 function pasteImage(event) { // use event.originalEvent.clipboard for newer chrome versions var items = (event.clipboardData || event.originalEvent.clipboardData).items; // 可能有多个file, 找到属于图片的file @@ -406,6 +430,12 @@ define("tinymce/pasteplugin/Clipboard", [ editor.on('paste', function(e) { if(inAcePrevent()) { + removePasteBin(); + return; + } + + if (hasImage(e)) { + removePasteBin(); return; } @@ -459,20 +489,7 @@ define("tinymce/pasteplugin/Clipboard", [ pasteHtml(html, clipboardContent['text/plain']); } }, 0); - - //----------- - // paste image - try { - /* - if(pasteImage(e)) { - return; - } - */ - } catch(e) {}; - }); - - self.pasteHtml = pasteHtml; self.pasteText = pasteText; diff --git a/public/tinymce/plugins/paste/plugin.js b/public/tinymce/plugins/paste/plugin.js index 6f99776..7426962 100644 --- a/public/tinymce/plugins/paste/plugin.js +++ b/public/tinymce/plugins/paste/plugin.js @@ -526,7 +526,31 @@ define("tinymce/pasteplugin/Clipboard", [ document.body.appendChild(img); } + // 是否有图片的粘贴, 有则删除paste bin + // 因为paste bin隐藏不见了, 如果不删除, 则editor_drop_paste的图片就会在这个bin下 + // 而且, paste bin最后会删除, 导致图片不能显示 + function hasImage(event) { + var items; + if (event.clipboardData) { + items = event.clipboardData.items; + } + else if(event.originalEvent && event.originalEvent.clipboardData) { + items = event.originalEvent.clipboardData; + } + if (!items) { + return false; + } + // find pasted image among pasted items + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + return true; + } + } + return false; + } + // 上传图片 + // 已过时, 不用, pasteImage在editor_drop_paste.js中用 function pasteImage(event) { // use event.originalEvent.clipboard for newer chrome versions var items = (event.clipboardData || event.originalEvent.clipboardData).items; // 可能有多个file, 找到属于图片的file @@ -591,6 +615,12 @@ define("tinymce/pasteplugin/Clipboard", [ editor.on('paste', function(e) { if(inAcePrevent()) { + removePasteBin(); + return; + } + + if (hasImage(e)) { + removePasteBin(); return; } @@ -644,20 +674,7 @@ define("tinymce/pasteplugin/Clipboard", [ pasteHtml(html, clipboardContent['text/plain']); } }, 0); - - //----------- - // paste image - try { - /* - if(pasteImage(e)) { - return; - } - */ - } catch(e) {}; - }); - - self.pasteHtml = pasteHtml; self.pasteText = pasteText; diff --git a/public/tinymce/plugins/paste/plugin.min.js b/public/tinymce/plugins/paste/plugin.min.js index 0a6a904..8768d40 100644 --- a/public/tinymce/plugins/paste/plugin.min.js +++ b/public/tinymce/plugins/paste/plugin.min.js @@ -1 +1 @@ -!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(//g,">"),d.insertRawContent(b)}else if(p.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$("
    "+a+"
    "),n=m.find("img"),o=0;o"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"
    "]]):(a=c.filter(a,[[/\n\n/g,"

    "+e],[/^(.*<\/p>)(

    )$/,e+"$1"],[/\n/g,"
    "]]),-1!=a.indexOf("

    ")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),m=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},r),a.setStyle(m,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(m,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),n=d.selection.getRng(),m.focus(),d.selection.select(m,!0)}function i(){m&&(d.dom.unbind(m),d.dom.remove(m),n&&d.selection.setRng(n)),o=!1,m=n=null}function j(){return m?m.innerHTML:r}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;ei?c&&(c=c.parent.parent):(d=c,c=null)),c&&c.name==g?c.append(a):(d=d||c,c=new e(g,1),h>1&&c.attr("start",""+h),a.wrap(c)),a.name="li",b.value="";var j=b.next;j&&3==j.type&&(j.value=j.value.replace(/^\u00a0+/,"")),i>f&&d&&d.lastChild.append(c),f=i}for(var c,d,f=1,g=a.getAll("p"),h=0;h/gi,/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,[/<(\/?)s>/gi,"<$1strike>"],[/ /gi,"\xa0"],[/([\s\u00a0]*)<\/span>/gi,function(a,b){return b.length>0?b.replace(/./," ").slice(Math.floor(b.length/2)).split("").join("\xa0"):""}]]);var p=i.paste_word_valid_elements;p||(p="@[style],-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[!href],sub,sup,strike,br");var q=new c({valid_elements:p}),r=new b({},q);r.addAttributeFilter("style",function(a){for(var b,c=a.length;c--;)b=a[c],b.attr("style",l(b,b.attr("style"))),"span"!=b.name||b.attributes.length||b.unwrap()});var s=r.parse(o);k(s),j.content=new d({},q).serialize(s)}})}return h.isWordContent=g,h}),d("tinymce/pasteplugin/Quirks",["tinymce/Env","tinymce/util/Tools","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Utils"],function(a,b,c,d){return function(e){function f(a){e.on("BeforePastePreProcess",function(b){b.content=a(b.content)})}function g(a){return a=d.filter(a,[/^[\s\S]*|[\s\S]*$/g,[/\u00a0<\/span>/g,"\xa0"],/
    $/])}function h(a){if(!c.isWordContent(a))return a;var f=[];b.each(e.schema.getBlockElements(),function(a,b){f.push(b)});var g=new RegExp("(?:
     [\\s\\r\\n]+|
    )*(<\\/?("+f.join("|")+")[^>]*>)(?:
     [\\s\\r\\n]+|
    )*","g");return a=d.filter(a,[[g,"$1"]]),a=d.filter(a,[[/

    /g,"

    "],[/
    /g," "],[/

    /g,"
    "]])}function i(a){return(e.settings.paste_remove_styles||e.settings.paste_remove_styles_if_webkit!==!1)&&(a=a.replace(/ style=\"[^\"]+\"/g,"")),a}a.webkit&&(f(i),f(g)),a.ie&&f(h)}}),d("tinymce/pasteplugin/Plugin",["tinymce/PluginManager","tinymce/pasteplugin/Clipboard","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Quirks"],function(a,b,c,d){var e;a.add("paste",function(a){function f(){"text"==g.pasteFormat?(this.active(!1),g.pasteFormat="html"):(g.pasteFormat="text",this.active(!0),e||(a.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),e=!0))}var g,h=this,i=a.settings;h.clipboard=g=new b(a),h.quirks=new d(a),h.wordFilter=new c(a),g.copyImage=!0,a.settings.paste_as_text&&(h.clipboard.pasteFormat="text"),i.paste_preprocess&&a.on("PastePreProcess",function(a){i.paste_preprocess.call(h,h,a)}),i.paste_postprocess&&a.on("PastePostProcess",function(a){i.paste_postprocess.call(h,h,a)}),a.addCommand("mceInsertClipboardContent",function(a,b){b.content&&h.clipboard.pasteHtml(b.content),b.text&&h.clipboard.pasteText(b.text)}),a.paste_block_drop&&a.on("dragend dragover draggesture dragdrop drop drag",function(a){a.preventDefault(),a.stopPropagation()}),a.settings.paste_data_images||a.on("drop",function(a){var b=a.dataTransfer;b&&b.files&&b.files.length>0&&a.preventDefault()}),a.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:f,active:"text"==h.clipboard.pasteFormat}),a.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:g.pasteFormat,onclick:f})})}),f(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"])}(this); \ No newline at end of file +!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(//g,">"),d.insertRawContent(b)}else if(q.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$("

    "+a+"
    "),n=m.find("img"),o=0;o"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"
    "]]):(a=c.filter(a,[[/\n\n/g,"

    "+e],[/^(.*<\/p>)(

    )$/,e+"$1"],[/\n/g,"
    "]]),-1!=a.indexOf("

    ")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),n=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},s),a.setStyle(n,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(n,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),o=d.selection.getRng(),n.focus(),d.selection.select(n,!0)}function i(){n&&(d.dom.unbind(n),d.dom.remove(n),o&&d.selection.setRng(o)),p=!1,n=o=null}function j(){return n?n.innerHTML:s}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;ei?c&&(c=c.parent.parent):(d=c,c=null)),c&&c.name==g?c.append(a):(d=d||c,c=new e(g,1),h>1&&c.attr("start",""+h),a.wrap(c)),a.name="li",b.value="";var j=b.next;j&&3==j.type&&(j.value=j.value.replace(/^\u00a0+/,"")),i>f&&d&&d.lastChild.append(c),f=i}for(var c,d,f=1,g=a.getAll("p"),h=0;h/gi,/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,[/<(\/?)s>/gi,"<$1strike>"],[/ /gi,"\xa0"],[/([\s\u00a0]*)<\/span>/gi,function(a,b){return b.length>0?b.replace(/./," ").slice(Math.floor(b.length/2)).split("").join("\xa0"):""}]]);var p=i.paste_word_valid_elements;p||(p="@[style],-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[!href],sub,sup,strike,br");var q=new c({valid_elements:p}),r=new b({},q);r.addAttributeFilter("style",function(a){for(var b,c=a.length;c--;)b=a[c],b.attr("style",l(b,b.attr("style"))),"span"!=b.name||b.attributes.length||b.unwrap()});var s=r.parse(o);k(s),j.content=new d({},q).serialize(s)}})}return h.isWordContent=g,h}),d("tinymce/pasteplugin/Quirks",["tinymce/Env","tinymce/util/Tools","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Utils"],function(a,b,c,d){return function(e){function f(a){e.on("BeforePastePreProcess",function(b){b.content=a(b.content)})}function g(a){return a=d.filter(a,[/^[\s\S]*|[\s\S]*$/g,[/\u00a0<\/span>/g,"\xa0"],/
    $/])}function h(a){if(!c.isWordContent(a))return a;var f=[];b.each(e.schema.getBlockElements(),function(a,b){f.push(b)});var g=new RegExp("(?:
     [\\s\\r\\n]+|
    )*(<\\/?("+f.join("|")+")[^>]*>)(?:
     [\\s\\r\\n]+|
    )*","g");return a=d.filter(a,[[g,"$1"]]),a=d.filter(a,[[/

    /g,"

    "],[/
    /g," "],[/

    /g,"
    "]])}function i(a){return(e.settings.paste_remove_styles||e.settings.paste_remove_styles_if_webkit!==!1)&&(a=a.replace(/ style=\"[^\"]+\"/g,"")),a}a.webkit&&(f(i),f(g)),a.ie&&f(h)}}),d("tinymce/pasteplugin/Plugin",["tinymce/PluginManager","tinymce/pasteplugin/Clipboard","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Quirks"],function(a,b,c,d){var e;a.add("paste",function(a){function f(){"text"==g.pasteFormat?(this.active(!1),g.pasteFormat="html"):(g.pasteFormat="text",this.active(!0),e||(a.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),e=!0))}var g,h=this,i=a.settings;h.clipboard=g=new b(a),h.quirks=new d(a),h.wordFilter=new c(a),g.copyImage=!0,a.settings.paste_as_text&&(h.clipboard.pasteFormat="text"),i.paste_preprocess&&a.on("PastePreProcess",function(a){i.paste_preprocess.call(h,h,a)}),i.paste_postprocess&&a.on("PastePostProcess",function(a){i.paste_postprocess.call(h,h,a)}),a.addCommand("mceInsertClipboardContent",function(a,b){b.content&&h.clipboard.pasteHtml(b.content),b.text&&h.clipboard.pasteText(b.text)}),a.paste_block_drop&&a.on("dragend dragover draggesture dragdrop drop drag",function(a){a.preventDefault(),a.stopPropagation()}),a.settings.paste_data_images||a.on("drop",function(a){var b=a.dataTransfer;b&&b.files&&b.files.length>0&&a.preventDefault()}),a.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:f,active:"text"==h.clipboard.pasteFormat}),a.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:g.pasteFormat,onclick:f})})}),f(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"])}(this); \ No newline at end of file