From 2000bc585be9e386263ba8d605ed1db27abe9486 Mon Sep 17 00:00:00 2001 From: lealife Date: Sun, 22 Nov 2015 23:01:30 +0800 Subject: [PATCH] markdown editor v2 paste images --- public/js/plugins/editor_drop_paste.js | 2 +- public/js/plugins/main.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/plugins/editor_drop_paste.js b/public/js/plugins/editor_drop_paste.js index 12514b2..aa7e5c5 100644 --- a/public/js/plugins/editor_drop_paste.js +++ b/public/js/plugins/editor_drop_paste.js @@ -290,7 +290,7 @@ define('editor_drop_paste', ['jquery.ui.widget', 'fileupload'], function() { // 2015/4/17 添加wmd-input markdown paste image $('#editorContent, #wmd-input .editor-content').fileupload({ dataType: 'json', - pasteZone: $('#editorContent, #wmd-input .editor-content'), + pasteZone: $('#editorContent, #wmd-input'), dropZone: '', // 只允许paste maxFileSize: 210000, url: "/file/pasteImage", diff --git a/public/js/plugins/main.min.js b/public/js/plugins/main.min.js index 4e3da15..697002d 100644 --- a/public/js/plugins/main.min.js +++ b/public/js/plugins/main.min.js @@ -2,5 +2,5 @@ define("note_info",[],function(){var t=["","
"+getMsg("Create Time define("tips",[],function(){var d=['"].join(""),a=$(d),i={init:function(){$("#tipsBtn").click(function(){a.modal({show:!0})})}};i.init()}); define("history",[],function(){var t=['"].join(""),i=$(t),s=i.find(".history-content"),e=i.find(".history-list"),o=i.find(".history-num"),n={note:null,list:[],curIndex:0,renderContent:function(t){var i=this.list[t].Content;this.curIndex=t;var o="
",n="
";this.note.IsMarkdown&&(o="
",n="
"),s.html(o+i+n);var a=e.find("a");a.removeClass("active"),a.eq(t).addClass("active")},render:function(t){var s="";if(this.list=t,t)for(var n=0;n#'+(n+1)+""+goNowToDatetime(a.UpdatedTime)+""}e.html(s),this.renderContent(0),o.html(t.length),i.modal({show:!0})},bind:function(){var t=this;$("#contentHistory").click(function(){t.getHistories()}),e.on("click","a",function(){var i=$(this).data("index");t.renderContent(i)}),i.find(".back").click(function(){confirm(getMsg("confirmBackup"))&&(Note.curChangedSaveIt(!0),note=Note.cache[Note.curNoteId],setEditorContent(t.list[t.curIndex].Content,note.IsMarkdown),i.modal("hide"),Note.curChangedSaveIt(!0))})},getHistories:function(){var t=this,i=Note.getCurNote();t.note=i,ajaxGet("/noteContentHistory/listHistories",{noteId:Note.curNoteId},function(i){return isArray(i)?void t.render(i):void alert(getMsg("noHistories"))})},init:function(){this.bind()}};n.init()}); var urlPrefix=UrlPrefix;define("attachment_upload",["jquery.ui.widget","fileupload"],function(){function e(e){return"number"!=typeof e?"":e>=1e9?(e/1e9).toFixed(2)+" GB":e>=1e6?(e/1e6).toFixed(2)+" MB":(e/1e3).toFixed(2)+" KB"}function t(e,t){var a=$(e);$(t).bind("dragover",function(e){e.preventDefault();var t=window.dropZoneTimeoutAttach;t&&clearTimeout(t);var o=!1,i=e.target;do{if(i===a[0]){o=!0;break}i=i.parentNode}while(null!=i);o?a.addClass("hover"):a.removeClass("hover"),window.dropZoneTimeoutAttach=setTimeout(function(){window.dropZoneTimeoutAttach=null,a.removeClass("in hover")},100)})}t("#dropAttach","#uploadAttach");var a=function(){$(".dropzone .btn-choose-file").click(function(){$(this).parent().find("input").click()});var t=$("#attachUploadMsg");$("#uploadAttach").fileupload({dataType:"json",pasteZone:"",dropZone:$("#dropAttach"),formData:function(e){return[{name:"noteId",value:Note.curNoteId}]},add:function(a,o){var i=Note.getCurNote();if(!i||i.IsNew)return void alert("This note hasn't saved, please save it firstly!");var r=$('');r.append(o.files[0].name+" ["+e(o.files[0].size)+"]"),t.html(r),o.context=t;var n=o.files[0].size,l=+GlobalConfigs.uploadAttachSize||100;if("number"==typeof n&&n>1048576*l)return r.find("img").remove(),r.removeClass("alert-info").addClass("alert-danger"),r.append(" Warning: File size is bigger than "+l+"M"),void setTimeout(function(e){return function(){e.remove()}}(r),3e3);var s;setTimeout(function(){s=o.submit()},10)},done:function(t,a){if(1==a.result.Ok)a.context.html(""),Attach.addAttach(a.result.Item);else{a.result;a.context.html("");var o=$('');o.append("Error: "+a.files[0].name+" ["+e(a.files[0].size)+"] "+a.result.Msg),a.context.html(o),setTimeout(function(e){return function(){e.remove()}}(o),3e3)}$("#uploadAttachMsg").scrollTop(1e3)},fail:function(t,a){a.context.html("");var o=$('');o.append("Error: "+a.files[0].name+" ["+e(a.files[0].size)+"] "+a.errorThrown),a.context.html(o),setTimeout(function(e){return function(){e.remove()}}(o),3e3),$("#uploadAttachMsg").scrollTop(1e3)}})};a()}); -var urlPrefix=UrlPrefix;define("editor_drop_paste",["jquery.ui.widget","fileupload"],function(){function e(){var e=$("#editorContent").children(),t=e&&e.length>0?e[e.length-1]:null;t&&"P"==t.tagName||$("#editorContent").append('


')}function t(t){var i="__mcenew"+(new Date).getTime(),o='
0%
';this.containerStr=o,t.insertContent(o),e();var a=$("#"+i);this.container=a,this.id=i,this.processBar=a.find(".progress-bar")}function i(e,t){function i(e,i){o.parentNode.removeChild(o),t({width:e,height:i})}var o=document.createElement("img");o.onload=function(){i(o.clientWidth,o.clientHeight)},o.onerror=function(){i()},o.src=e;var a=o.style;a.visibility="hidden",a.position="fixed",a.bottom=a.left=0,a.width=a.height="auto",document.body.appendChild(o)}function o(e){var t=tinymce.activeEditor,o=t.dom,r=function(t){function r(e){o.setAttrib(n,"src",t.src),t.title&&o.setAttrib(n,"title",t.title),o.setAttrib(n,"id",null)}var n,s={};s.id="__mcenew"+a++,s.src="/images/loading-24.gif",n=o.createHTML("img",s),tinymce.activeEditor.insertContent(n),n=o.get(s.id),i(e.src,r)},n="";if(fileIds=e.src.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(n=fileIds[1]),n){var s=Note.getCurNote();s&&s.UserId!=UserInfo.UserId?!function(e){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:n,toUserId:s.UserId},function(t){if(reIsOk(t)&&t.Id){var i=window.location.protocol+"//"+window.location.host;e.src=i+"/api/file/getImage?fileId="+t.Id}r(e)})}(e):r(e)}else r(e)}t.prototype.update=function(e){var t=this;e=Math.ceil(100*e),e>=100&&(e=99),e+="%",$("#"+t.id+" .progress-bar").html(e).css("width",e)},t.prototype.replace=function(e){var t=this;i(e,function(){$("#"+t.id).replaceWith('')})},t.prototype.remove=function(){var e=this;$("#"+e.id).remove()};var a=1,r=function(){function e(e){return"number"!=typeof e?"":e>=1e9?(e/1e9).toFixed(2)+" GB":e>=1e6?(e/1e6).toFixed(2)+" MB":(e/1e3).toFixed(2)+" KB"}function t(){$("#upload").css("z-index",12);var e=+$("#mceToolbar").css("height").slice(0,-2);$("#upload").css("top",e-8),$("#upload").show()}function i(){$("#upload").css("z-index",0).css("top","auto").hide()}var a=$("#upload ul");$("#drop a").click(function(){$(this).parent().find("input").click()}),$("#upload").fileupload({dataType:"json",pasteZone:"",acceptFileTypes:/(\.|\/)(gif|jpg|jpeg|png|jpe)$/i,maxFileSize:21e4,dropZone:$("#drop"),formData:function(e){return[{name:"albumId",value:""}]},add:function(t,i){var o=$('
  • ');o.find("div").append(i.files[0].name+" ["+e(i.files[0].size)+"]"),i.context=o.appendTo(a);i.submit()},done:function(t,i){if(1==i.result.Ok){i.context.remove();var a={src:urlPrefix+"/api/file/getImage?fileId="+i.result.Id};o(a)}else{i.context.empty();var r=$('
  • ');r.find("div").append(""+getMsg("Error")+": "+i.files[0].name+" ["+e(i.files[0].size)+"] "+i.result.Msg),i.context.append(r),setTimeout(function(e){return function(){e.remove()}}(r),2e3)}$("#uploadMsg").scrollTop(1e3)},fail:function(t,i){i.context.empty();var o=$('
  • ');o.find("div").append(""+getMsg("Error")+": "+i.files[0].name+" ["+e(i.files[0].size)+"] "+i.errorThrown),i.context.append(o),setTimeout(function(e){return function(){e.remove()}}(o),2e3),$("#uploadMsg").scrollTop(1e3)}}),$(document).on("drop dragover",function(e){e.preventDefault()}),$(document).bind("dragover",function(e){var o=$("#drop"),a=window.dropZoneTimeout;a?clearTimeout(a):(o.addClass("in"),t());var r=!1,n=e.target;do{if(n===o[0]){r=!0;break}n=n.parentNode}while(null!=n);r?(o.addClass("hover"),LEA.readOnly&&LEA.toggleWriteable()):o.removeClass("hover"),window.dropZoneTimeout=setTimeout(function(){window.dropZoneTimeout=null,o.removeClass("in hover"),i()},500)})},n=0,s=function(){var e,i;$("#editorContent, #wmd-input .editor-content").fileupload({dataType:"json",pasteZone:$("#editorContent, #wmd-input .editor-content"),dropZone:"",maxFileSize:21e4,url:"/file/pasteImage",paramName:"file",formData:function(e){return[{name:"from",value:"pasteImage"},{name:"noteId",value:Note.curNoteId}]},progress:function(t,i){e&&!e.IsMarkdown&&i.process.update(i.loaded/i.total)},add:function(o,a){var r=(new Date).getTime();if(!(500>r-n)){n=r;var s=Note.getCurNote();if(e=s,!s||s.IsNew)return void alert("This note hasn't saved, please save it firstly!");if(i=tinymce.EditorManager.activeEditor,!s.IsMarkdown)var l=new t(i);a.process=l;a.submit()}},done:function(t,i){if(1==i.result.Ok){var o=i.result,a=UrlPrefix,r=a+"/api/file/getImage?fileId="+o.Id;e&&!e.IsMarkdown?i.process.replace(r):MD&&MD.insertLink(r,"title",!0)}else i.process.remove()},fail:function(t,i){e&&!e.IsMarkdown&&i.process.remove()}})};r(),s()}); +var urlPrefix=UrlPrefix;define("editor_drop_paste",["jquery.ui.widget","fileupload"],function(){function e(){var e=$("#editorContent").children(),t=e&&e.length>0?e[e.length-1]:null;t&&"P"==t.tagName||$("#editorContent").append('


    ')}function t(t){var i="__mcenew"+(new Date).getTime(),o='
    0%
    ';this.containerStr=o,t.insertContent(o),e();var a=$("#"+i);this.container=a,this.id=i,this.processBar=a.find(".progress-bar")}function i(e,t){function i(e,i){o.parentNode.removeChild(o),t({width:e,height:i})}var o=document.createElement("img");o.onload=function(){i(o.clientWidth,o.clientHeight)},o.onerror=function(){i()},o.src=e;var a=o.style;a.visibility="hidden",a.position="fixed",a.bottom=a.left=0,a.width=a.height="auto",document.body.appendChild(o)}function o(e){var t=tinymce.activeEditor,o=t.dom,r=function(t){function r(e){o.setAttrib(n,"src",t.src),t.title&&o.setAttrib(n,"title",t.title),o.setAttrib(n,"id",null)}var n,s={};s.id="__mcenew"+a++,s.src="/images/loading-24.gif",n=o.createHTML("img",s),tinymce.activeEditor.insertContent(n),n=o.get(s.id),i(e.src,r)},n="";if(fileIds=e.src.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(n=fileIds[1]),n){var s=Note.getCurNote();s&&s.UserId!=UserInfo.UserId?!function(e){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:n,toUserId:s.UserId},function(t){if(reIsOk(t)&&t.Id){var i=window.location.protocol+"//"+window.location.host;e.src=i+"/api/file/getImage?fileId="+t.Id}r(e)})}(e):r(e)}else r(e)}t.prototype.update=function(e){var t=this;e=Math.ceil(100*e),e>=100&&(e=99),e+="%",$("#"+t.id+" .progress-bar").html(e).css("width",e)},t.prototype.replace=function(e){var t=this;i(e,function(){$("#"+t.id).replaceWith('')})},t.prototype.remove=function(){var e=this;$("#"+e.id).remove()};var a=1,r=function(){function e(e){return"number"!=typeof e?"":e>=1e9?(e/1e9).toFixed(2)+" GB":e>=1e6?(e/1e6).toFixed(2)+" MB":(e/1e3).toFixed(2)+" KB"}function t(){$("#upload").css("z-index",12);var e=+$("#mceToolbar").css("height").slice(0,-2);$("#upload").css("top",e-8),$("#upload").show()}function i(){$("#upload").css("z-index",0).css("top","auto").hide()}var a=$("#upload ul");$("#drop a").click(function(){$(this).parent().find("input").click()}),$("#upload").fileupload({dataType:"json",pasteZone:"",acceptFileTypes:/(\.|\/)(gif|jpg|jpeg|png|jpe)$/i,maxFileSize:21e4,dropZone:$("#drop"),formData:function(e){return[{name:"albumId",value:""}]},add:function(t,i){var o=$('
  • ');o.find("div").append(i.files[0].name+" ["+e(i.files[0].size)+"]"),i.context=o.appendTo(a);i.submit()},done:function(t,i){if(1==i.result.Ok){i.context.remove();var a={src:urlPrefix+"/api/file/getImage?fileId="+i.result.Id};o(a)}else{i.context.empty();var r=$('
  • ');r.find("div").append(""+getMsg("Error")+": "+i.files[0].name+" ["+e(i.files[0].size)+"] "+i.result.Msg),i.context.append(r),setTimeout(function(e){return function(){e.remove()}}(r),2e3)}$("#uploadMsg").scrollTop(1e3)},fail:function(t,i){i.context.empty();var o=$('
  • ');o.find("div").append(""+getMsg("Error")+": "+i.files[0].name+" ["+e(i.files[0].size)+"] "+i.errorThrown),i.context.append(o),setTimeout(function(e){return function(){e.remove()}}(o),2e3),$("#uploadMsg").scrollTop(1e3)}}),$(document).on("drop dragover",function(e){e.preventDefault()}),$(document).bind("dragover",function(e){var o=$("#drop"),a=window.dropZoneTimeout;a?clearTimeout(a):(o.addClass("in"),t());var r=!1,n=e.target;do{if(n===o[0]){r=!0;break}n=n.parentNode}while(null!=n);r?(o.addClass("hover"),LEA.readOnly&&LEA.toggleWriteable()):o.removeClass("hover"),window.dropZoneTimeout=setTimeout(function(){window.dropZoneTimeout=null,o.removeClass("in hover"),i()},500)})},n=0,s=function(){var e,i;$("#editorContent, #wmd-input .editor-content").fileupload({dataType:"json",pasteZone:$("#editorContent, #wmd-input"),dropZone:"",maxFileSize:21e4,url:"/file/pasteImage",paramName:"file",formData:function(e){return[{name:"from",value:"pasteImage"},{name:"noteId",value:Note.curNoteId}]},progress:function(t,i){e&&!e.IsMarkdown&&i.process.update(i.loaded/i.total)},add:function(o,a){var r=(new Date).getTime();if(!(500>r-n)){n=r;var s=Note.getCurNote();if(e=s,!s||s.IsNew)return void alert("This note hasn't saved, please save it firstly!");if(i=tinymce.EditorManager.activeEditor,!s.IsMarkdown)var l=new t(i);a.process=l;a.submit()}},done:function(t,i){if(1==i.result.Ok){var o=i.result,a=UrlPrefix,r=a+"/api/file/getImage?fileId="+o.Id;e&&!e.IsMarkdown?i.process.replace(r):MD&&MD.insertLink(r,"title",!0)}else i.process.remove()},fail:function(t,i){e&&!e.IsMarkdown&&i.process.remove()}})};r(),s()}); requirejs.config({paths:{editor_drop_paste:"js/plugins/editor_drop_paste",attachment_upload:"js/plugins/attachment_upload","jquery.ui.widget":"js/plugins/libs-min/jquery.ui.widget",fileupload:"js/plugins/libs-min/jquery.fileupload","iframe-transport":"js/plugins/libs-min/jquery.iframe-transport",note_info:"js/plugins/note_info",tips:"js/plugins/tips",history:"js/plugins/history"},shim:{fileupload:{deps:["jquery.ui.widget","iframe-transport"]}}}),setTimeout(function(){require(["editor_drop_paste","attachment_upload"]),require(["note_info"]),setTimeout(function(){require(["tips"]),require(["history"])},10)}); \ No newline at end of file