Files
leanote/public/tinymce/plugins/paste/plugin.min.js
2015-01-08 00:36:28 +08:00

1 line
11 KiB
JavaScript

!function(e,t){"use strict";function n(e,t){for(var n,r=[],i=0;i<e.length;++i){if(n=s[e[i]]||o(e[i]),!n)throw"module definition dependecy not found: "+e[i];r.push(n)}t.apply(null,r)}function r(e,r,i){if("string"!=typeof e)throw"invalid module definition, module id must be defined and be a string";if(r===t)throw"invalid module definition, dependencies must be specified";if(i===t)throw"invalid module definition, definition function must be specified";n(r,function(){s[e]=i.apply(null,arguments)})}function i(e){return!!s[e]}function o(t){for(var n=e,r=t.split(/[.\/]/),i=0;i<r.length;++i){if(!n[r[i]])return;n=n[r[i]]}return n}function a(n){for(var r=0;r<n.length;r++){for(var i=e,o=n[r],a=o.split(/[.\/]/),l=0;l<a.length-1;++l)i[a[l]]===t&&(i[a[l]]={}),i=i[a[l]];i[a[a.length-1]]=s[o]}}var s={},l="tinymce/pasteplugin/Utils",c="tinymce/util/Tools",d="tinymce/html/DomParser",u="tinymce/html/Schema",f="tinymce/pasteplugin/Clipboard",p="tinymce/Env",m="tinymce/util/VK",h="tinymce/pasteplugin/WordFilter",g="tinymce/html/Serializer",v="tinymce/html/Node",y="tinymce/pasteplugin/Quirks",b="tinymce/pasteplugin/Plugin",C="tinymce/PluginManager";r(l,[c,d,u],function(e,t,n){function r(t,n){return e.each(n,function(e){t=e.constructor==RegExp?t.replace(e,""):t.replace(e[0],e[1])}),t}function i(r){function i(e){var t=e.name,n=e;if("br"===t)return void(s+="\n");if(l[t]&&(s+=" "),c[t])return void(s+=" ");if(3==e.type&&(s+=e.value),!e.shortEnded&&(e=e.firstChild))do i(e);while(e=e.next);d[t]&&n.next&&(s+="\n","p"==t&&(s+="\n"))}var o=new n,a=new t({},o),s="",l=o.getShortEndedElements(),c=e.makeMap("script noscript style textarea video audio iframe object"," "),d=o.getBlockElements();return i(a.parse(r)),s}return{filter:r,innerText:i}}),r(f,[p,m,l],function(e,t,n){return function(r){function i(e,t){ajaxPost("/file/copyHttpImage",{src:e},function(e){if(reIsOk(e)){var n=urlPrefix+"/"+e.Item,i=r.dom;for(var o in t){var a=t[o],s=i.get(a);i.setAttrib(s,"src",n)}}})}function o(e,t){var n,o=r.dom;if(r.settings.paste_data_images||(e=e.replace(/<img[^>]+src=\"data:image[^>]+>/g,"")),n=r.fire("BeforePastePreProcess",{content:e}),n=r.fire("PastePreProcess",n),e=n.content,!n.isDefaultPrevented()){if(r.hasEventListeners("PastePostProcess")&&!n.isDefaultPrevented()){var a=o.add(r.getBody(),"div",{style:"display:none"},e);n=r.fire("PastePostProcess",{node:a}),o.remove(a),e=n.node.innerHTML}if(!n.isDefaultPrevented()){var s=r.selection.getNode();if("PRE"==s.nodeName){if(!t)try{t=$(e).text()}catch(l){}t=t.replace(/</g,"&lt;"),t=t.replace(/>/g,"&gt;"),r.insertRawContent(t)}else if(m.copyImage){var c=UrlPrefix,d={},u=(new Date).getTime();try{for(var f=$("<div>"+e+"</div"),p=f.find("img"),h=0;h<p.length;++h){var g=p.eq(h),v=g.attr("src");if(-1==v.indexOf(c)){u++;var y="__LEANOTE_IMAGE_"+u;g.attr("id",y),d[v]?d[v].push(y):d[v]=[y]}}r.insertContent(f.html());for(var v in d){var b=d[v];i(v,b)}}catch(l){r.insertContent(e)}}else r.insertContent(e)}}}function a(e){var t=e;e=r.dom.encode(e).replace(/\r\n/g,"\n");var i=r.dom.getParent(r.selection.getStart(),r.dom.isBlock),a=r.settings.forced_root_block,s;a&&(s=r.dom.createHTML(a,r.settings.forced_root_block_attrs),s=s.substr(0,s.length-3)+">"),i&&/^(PRE|DIV)$/.test(i.nodeName)||!a?e=n.filter(e,[[/\n/g,"<br>"]]):(e=n.filter(e,[[/\n\n/g,"</p>"+s],[/^(.*<\/p>)(<p>)$/,s+"$1"],[/\n/g,"<br />"]]),-1!=e.indexOf("<p>")&&(e=s+e)),o(e,t)}function s(){var e=r.dom,t=r.getBody(),n=r.dom.getViewPort(r.getWin()),i=r.inline?t.scrollTop:n.y,o=r.inline?t.clientHeight:n.h;l(),h=e.add(r.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(i+20)+"px;width: 10px; height: "+(o-40)+"px; overflow: hidden; opacity: 0"},y),e.setStyle(h,"left","rtl"==e.getStyle(t,"direction",!0)?65535:-65535),e.bind(h,"beforedeactivate focusin focusout",function(e){e.stopPropagation()}),g=r.selection.getRng(),h.focus(),r.selection.select(h,!0)}function l(){h&&(r.dom.unbind(h),r.dom.remove(h),g&&r.selection.setRng(g)),b=!1,h=g=null}function c(){return h?h.innerHTML:y}function d(e){var t={},n=e.clipboardData||r.getDoc().dataTransfer;if(n&&n.types){t["text/plain"]=n.getData("Text");for(var i=0;i<n.types.length;i++){var o=n.types[i];t[o]=n.getData(o)}}return t}function u(){var e=LeaAce.nowIsInAce();return e?(setTimeout(function(){e[0].focus()}),!0):!1}function f(e,t){function n(e,n){r.parentNode.removeChild(r),t({width:e,height:n})}var r=document.createElement("img");r.onload=function(){n(r.clientWidth,r.clientHeight)},r.onerror=function(){n()},r.src=e;var i=r.style;i.visibility="hidden",i.position="fixed",i.bottom=i.left=0,i.width=i.height="auto",document.body.appendChild(r)}function p(e){var t=(e.clipboardData||e.originalEvent.clipboardData).items;log(JSON.stringify(t));for(var n,r=0;r<t.length;r++)0===t[r].type.indexOf("image")&&(n=t[r].getAsFile());if(n){var i=new FileReader;return i.onload=function(e){var t=new FormData;t.append("from","pasteImage"),t.append("file",n),t.append("noteId",Note.curNoteId);var r=tinymce.EditorManager.activeEditor,i=r.dom,o={};o.id="__mcenew",o.src="http://leanote.com/images/loading-24.gif",r.insertContent(i.createHTML("img",o));var a=i.get("__mcenew");$.ajax({url:"/file/pasteImage",contentType:!1,processData:!1,data:t,type:"POST"}).done(function(e){if(!e||"object"!=typeof e||!e.Ok)return void i.remove(a);var t=UrlPrefix,n=t+"/file/outputImage?fileId="+e.Id;f(n,function(e){e&&e.width&&(e.width>600&&(e.width=600),o.width=e.width,i.setAttrib(a,"width",o.width)),i.setAttrib(a,"src",n)}),i.setAttrib(a,"id",null)})},i.readAsDataURL(n),!0}return!1}var m=this,h,g,v=0,y="%MCEPASTEBIN%",b;r.on("keydown",function(n){if(!n.isDefaultPrevented()&&(t.metaKeyPressed(n)&&86==n.keyCode||n.shiftKey&&45==n.keyCode)){if(u())return;if(b=n.shiftKey&&86==n.keyCode,n.stopImmediatePropagation(),v=(new Date).getTime(),e.ie&&b)return n.preventDefault(),void r.fire("paste",{ieFake:!0});s()}}),r.on("paste",function(t){if(!u()){var i=d(t),f=(new Date).getTime()-v<100,p="text"==m.pasteFormat||b;f||t.preventDefault(),!e.ie||f&&!t.ieFake||(s(),r.dom.bind(h,"paste",function(e){e.stopPropagation()}),r.getDoc().execCommand("Paste",!1,null),i["text/html"]=c(),l()),setTimeout(function(){var e=c();return h&&h.firstChild&&"mcepastebin"===h.firstChild.id&&(p=!0),l(),e!=y&&f||(e=i["text/html"]||i["text/plain"]||y,e!=y)?void(p?a(i["text/plain"]||n.innerText(e)):o(e,i["text/plain"])):void(f||r.windowManager.alert("Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents."))},0);try{}catch(t){}}}),m.pasteHtml=o,m.pasteText=a}}),r(h,[c,d,u,g,v,l],function(e,t,n,r,i,o){function a(e){return/class="?Mso|style="[^"]*\bmso-|style='[^'']*\bmso-|w:WordDocument/i.test(e)}function s(s){var l=s.settings;s.on("BeforePastePreProcess",function(c){function d(e){function t(e,t,a,s){var l=e._listLevel||o;l!=o&&(o>l?n&&(n=n.parent.parent):(r=n,n=null)),n&&n.name==a?n.append(e):(r=r||n,n=new i(a,1),s>1&&n.attr("start",""+s),e.wrap(n)),e.name="li",t.value="";var c=t.next;c&&3==c.type&&(c.value=c.value.replace(/^\u00a0+/,"")),l>o&&r&&r.lastChild.append(n),o=l}for(var n,r,o=1,a=e.getAll("p"),s=0;s<a.length;s++)if(e=a[s],"p"==e.name&&e.firstChild){for(var l="",c=e.firstChild;c&&!(l=c.value);)c=c.firstChild;if(/^\s*[\u2022\u00b7\u00a7\u00d8\u25CF]\s*$/.test(l)){t(e,c,"ul");continue}if(/^\s*\w+\.$/.test(l)){var d=/([0-9])\./.exec(l),u=1;d&&(u=parseInt(d[1],10)),t(e,c,"ol",u);continue}n=null}}function u(t,n){if("p"===t.name){var r=/mso-list:\w+ \w+([0-9]+)/.exec(n);r&&(t._listLevel=parseInt(r[1],10))}if(s.getParam("paste_retain_style_properties","none")){var i="";if(e.each(s.dom.parseStyle(n),function(e,t){switch(t){case"horiz-align":return void(t="text-align");case"vert-align":return void(t="vertical-align");case"font-color":case"mso-foreground":return void(t="color");case"mso-background":case"mso-highlight":t="background"}("all"==p||m&&m[t])&&(i+=t+":"+e+";")}),i)return i}return null}var f=c.content,p,m;if(p=l.paste_retain_style_properties,p&&(m=e.makeMap(p)),l.paste_enable_default_filters!==!1&&a(c.content)){c.wordContent=!0,f=o.filter(f,[/<!--[\s\S]+?-->/gi,/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,[/<(\/?)s>/gi,"<$1strike>"],[/&nbsp;/gi,"\xa0"],[/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,function(e,t){return t.length>0?t.replace(/./," ").slice(Math.floor(t.length/2)).split("").join("\xa0"):""}]]);var h=l.paste_word_valid_elements;h||(h="@[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 g=new n({valid_elements:h}),v=new t({},g);v.addAttributeFilter("style",function(e){for(var t=e.length,n;t--;)n=e[t],n.attr("style",u(n,n.attr("style"))),"span"!=n.name||n.attributes.length||n.unwrap()});var y=v.parse(f);d(y),c.content=new r({},g).serialize(y)}})}return s.isWordContent=a,s}),r(y,[p,c,h,l],function(e,t,n,r){return function(i){function o(e){i.on("BeforePastePreProcess",function(t){t.content=e(t.content)})}function a(e){return e=r.filter(e,[/^[\s\S]*<!--StartFragment-->|<!--EndFragment-->[\s\S]*$/g,[/<span class="Apple-converted-space">\u00a0<\/span>/g,"\xa0"],/<br>$/])}function s(e){if(!n.isWordContent(e))return e;var o=[];t.each(i.schema.getBlockElements(),function(e,t){o.push(t)});var a=new RegExp("(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?("+o.join("|")+")[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*","g");return e=r.filter(e,[[a,"$1"]]),e=r.filter(e,[[/<br><br>/g,"<BR><BR>"],[/<br>/g," "],[/<BR><BR>/g,"<br>"]])}function l(e){return(i.settings.paste_remove_styles||i.settings.paste_remove_styles_if_webkit!==!1)&&(e=e.replace(/ style=\"[^\"]+\"/g,"")),e}e.webkit&&(o(l),o(a)),e.ie&&o(s)}}),r(b,[C,f,h,y],function(e,t,n,r){var i,o;e.add("paste",function(e){function a(){"text"==c.pasteFormat?(this.active(!1),c.pasteFormat="html"):(c.pasteFormat="text",this.active(!0),i||(e.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),i=!0))}function s(){c.copyImage?(this.active(!1),c.copyImage=!1):(c.copyImage=!0,this.active(!0),o||(e.windowManager.alert("When copy other site's images (not in leanote) into editor, it will copy the image into your album."),o=!0))}var l=this,c,d=e.settings;l.clipboard=c=new t(e),l.quirks=new r(e),l.wordFilter=new n(e),e.settings.paste_as_text&&(l.clipboard.pasteFormat="text"),d.paste_preprocess&&e.on("PastePreProcess",function(e){d.paste_preprocess.call(l,l,e)}),d.paste_postprocess&&e.on("PastePostProcess",function(e){d.paste_postprocess.call(l,l,e)}),e.addCommand("mceInsertClipboardContent",function(e,t){t.content&&l.clipboard.pasteHtml(t.content),t.text&&l.clipboard.pasteText(t.text)}),e.paste_block_drop&&e.on("dragend dragover draggesture dragdrop drop drag",function(e){e.preventDefault(),e.stopPropagation()}),e.settings.paste_data_images||e.on("drop",function(e){var t=e.dataTransfer;t&&t.files&&t.files.length>0&&e.preventDefault()}),e.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:a,active:"text"==l.clipboard.pasteFormat}),e.addButton("pasteCopyImage",{icon:"copy",tooltip:"When Paste other site's image, copy it into my album as public image",onclick:s,active:l.clipboard.copyImage===!0}),e.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:c.pasteFormat,onclick:a})})}),a([l,f,h,y,b])}(this);