Files
leanote/public/tinymce/plugins/paste/plugin.min.js
2014-05-07 13:06:24 +08:00

1 line
8.9 KiB
JavaScript

!function(e,t){"use strict";function n(e,t){for(var n,i=[],r=0;r<e.length;++r){if(n=s[e[r]]||a(e[r]),!n)throw"module definition dependecy not found: "+e[r];i.push(n)}t.apply(null,i)}function i(e,i,r){if("string"!=typeof e)throw"invalid module definition, module id must be defined and be a string";if(i===t)throw"invalid module definition, dependencies must be specified";if(r===t)throw"invalid module definition, definition function must be specified";n(i,function(){s[e]=r.apply(null,arguments)})}function r(e){return!!s[e]}function a(t){for(var n=e,i=t.split(/[.\/]/),r=0;r<i.length;++r){if(!n[i[r]])return;n=n[i[r]]}return n}function o(n){for(var i=0;i<n.length;i++){for(var r=e,a=n[i],o=a.split(/[.\/]/),l=0;l<o.length-1;++l)r[o[l]]===t&&(r[o[l]]={}),r=r[o[l]];r[o[o.length-1]]=s[a]}}var s={},l="tinymce/pasteplugin/Utils",c="tinymce/util/Tools",p="tinymce/html/DomParser",u="tinymce/html/Schema",d="tinymce/pasteplugin/Clipboard",f="tinymce/Env",g="tinymce/util/VK",m="tinymce/pasteplugin/WordFilter",v="tinymce/html/Serializer",h="tinymce/html/Node",b="tinymce/pasteplugin/Quirks",y="tinymce/pasteplugin/Plugin",P="tinymce/PluginManager";i(l,[c,p,u],function(e,t,n){function i(t,n){return e.each(n,function(e){t=e.constructor==RegExp?t.replace(e,""):t.replace(e[0],e[1])}),t}function r(i){function r(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 r(e);while(e=e.next);p[t]&&n.next&&(s+="\n","p"==t&&(s+="\n"))}var a=new n,o=new t({},a),s="",l=a.getShortEndedElements(),c=e.makeMap("script noscript style textarea video audio iframe object"," "),p=a.getBlockElements();return r(o.parse(i)),s}return{filter:i,innerText:r}}),i(d,[f,g,l],function(e,t,n){return function(i){function r(e,t){var n,r=i.dom;if(i.settings.paste_data_images||(e=e.replace(/<img[^>]+src=\"data:image[^>]+>/g,"")),n=i.fire("BeforePastePreProcess",{content:e}),n=i.fire("PastePreProcess",n),e=n.content,!n.isDefaultPrevented()){if(i.hasEventListeners("PastePostProcess")&&!n.isDefaultPrevented()){var a=r.add(i.getBody(),"div",{style:"display:none"},e);n=i.fire("PastePostProcess",{node:a}),r.remove(a),e=n.node.innerHTML}if(!n.isDefaultPrevented()){var o=i.selection.getNode();if("PRE"==o.nodeName){if(!t)try{t=$(e).text()}catch(s){}t=t.replace(/</g,"&lt;"),t=t.replace(/>/g,"&gt;"),i.insertRawContent(t)}else i.insertContent(e)}}}function a(e){var t=e;e=i.dom.encode(e).replace(/\r\n/g,"\n");var a=i.dom.getParent(i.selection.getStart(),i.dom.isBlock),o=i.settings.forced_root_block,s;o&&(s=i.dom.createHTML(o,i.settings.forced_root_block_attrs),s=s.substr(0,s.length-3)+">"),a&&/^(PRE|DIV)$/.test(a.nodeName)||!o?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)),r(e,t)}function o(){var e=i.dom,t=i.getBody(),n=i.dom.getViewPort(i.getWin()),r=i.inline?t.scrollTop:n.y,a=i.inline?t.clientHeight:n.h;s(),u=e.add(i.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(r+20)+"px;width: 10px; height: "+(a-40)+"px; overflow: hidden; opacity: 0"},g),e.setStyle(u,"left","rtl"==e.getStyle(t,"direction",!0)?65535:-65535),e.bind(u,"beforedeactivate focusin focusout",function(e){e.stopPropagation()}),d=i.selection.getRng(),u.focus(),i.selection.select(u,!0)}function s(){u&&(i.dom.unbind(u),i.dom.remove(u),d&&i.selection.setRng(d)),m=!1,u=d=null}function l(){return u?u.innerHTML:g}function c(e){var t={},n=e.clipboardData||i.getDoc().dataTransfer;if(n&&n.types){t["text/plain"]=n.getData("Text");for(var r=0;r<n.types.length;r++){var a=n.types[r];t[a]=n.getData(a)}}return t}var p=this,u,d,f=0,g="%MCEPASTEBIN%",m;i.on("keydown",function(n){if(!n.isDefaultPrevented()&&(t.metaKeyPressed(n)&&86==n.keyCode||n.shiftKey&&45==n.keyCode)){if(m=n.shiftKey&&86==n.keyCode,n.stopImmediatePropagation(),f=(new Date).getTime(),e.ie&&m)return n.preventDefault(),void i.fire("paste",{ieFake:!0});o()}}),i.on("paste",function(t){var d=c(t),v=(new Date).getTime()-f<100,h="text"==p.pasteFormat||m;v||t.preventDefault(),!e.ie||v&&!t.ieFake||(o(),i.dom.bind(u,"paste",function(e){e.stopPropagation()}),i.getDoc().execCommand("Paste",!1,null),d["text/html"]=l(),s()),setTimeout(function(){var e=l();return u&&u.firstChild&&"mcepastebin"===u.firstChild.id&&(h=!0),s(),e!=g&&v||(e=d["text/html"]||d["text/plain"]||g,e!=g)?void(h?a(d["text/plain"]||n.innerText(e)):r(e,d["text/plain"])):void(v||i.windowManager.alert("Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents."))},0)}),p.pasteHtml=r,p.pasteText=a}}),i(m,[c,p,u,v,h,l],function(e,t,n,i,r,a){function o(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 p(e){function t(e,t,o,s){var l=e._listLevel||a;l!=a&&(a>l?n&&(n=n.parent.parent):(i=n,n=null)),n&&n.name==o?n.append(e):(i=i||n,n=new r(o,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>a&&i&&i.lastChild.append(n),a=l}for(var n,i,a=1,o=e.getAll("p"),s=0;s<o.length;s++)if(e=o[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 p=/([0-9])\./.exec(l),u=1;p&&(u=parseInt(p[1],10)),t(e,c,"ol",u);continue}n=null}}function u(t,n){if("p"===t.name){var i=/mso-list:\w+ \w+([0-9]+)/.exec(n);i&&(t._listLevel=parseInt(i[1],10))}if(s.getParam("paste_retain_style_properties","none")){var r="";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"==f||g&&g[t])&&(r+=t+":"+e+";")}),r)return r}return null}var d=c.content,f,g;if(f=l.paste_retain_style_properties,f&&(g=e.makeMap(f)),l.paste_enable_default_filters!==!1&&o(c.content)){c.wordContent=!0,d=a.filter(d,[/<!--[\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 m=l.paste_word_valid_elements;m||(m="@[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 v=new n({valid_elements:m}),h=new t({},v);h.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 b=h.parse(d);p(b),c.content=new i({},v).serialize(b)}})}return s.isWordContent=o,s}),i(b,[f,c,m,l],function(e,t,n,i){return function(r){function a(e){r.on("BeforePastePreProcess",function(t){t.content=e(t.content)})}function o(e){return e=i.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 a=[];t.each(r.schema.getBlockElements(),function(e,t){a.push(t)});var o=new RegExp("(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?("+a.join("|")+")[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*","g");return e=i.filter(e,[[o,"$1"]]),e=i.filter(e,[[/<br><br>/g,"<BR><BR>"],[/<br>/g," "],[/<BR><BR>/g,"<br>"]])}function l(e){return(r.settings.paste_remove_styles||r.settings.paste_remove_styles_if_webkit!==!1)&&(e=e.replace(/ style=\"[^\"]+\"/g,"")),e}e.webkit&&(a(l),a(o)),e.ie&&a(s)}}),i(y,[P,d,m,b],function(e,t,n,i){var r;e.add("paste",function(e){function a(){"text"==s.pasteFormat?(this.active(!1),s.pasteFormat="html"):(s.pasteFormat="text",this.active(!0),r||(e.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),r=!0))}var o=this,s,l=e.settings;o.clipboard=s=new t(e),o.quirks=new i(e),o.wordFilter=new n(e),e.settings.paste_as_text&&(o.clipboard.pasteFormat="text"),l.paste_preprocess&&e.on("PastePreProcess",function(e){l.paste_preprocess.call(o,o,e)}),l.paste_postprocess&&e.on("PastePostProcess",function(e){l.paste_postprocess.call(o,o,e)}),e.addCommand("mceInsertClipboardContent",function(e,t){t.content&&o.clipboard.pasteHtml(t.content),t.text&&o.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"==o.clipboard.pasteFormat}),e.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:s.pasteFormat,onclick:a})})}),o([l,d,m,b,y])}(this);