X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=inline;f=_source%2Fplugins%2Fpastefromword%2Fdialogs%2Fpastefromword.js;fp=_source%2Fplugins%2Fpastefromword%2Fdialogs%2Fpastefromword.js;h=a10f2979eb0432625be1d80c393506c986754fd4;hb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;hp=0000000000000000000000000000000000000000;hpb=b93873b6532ee7515fb0d6f8b73176c44fad28f7;p=ckeditor.git diff --git a/_source/plugins/pastefromword/dialogs/pastefromword.js b/_source/plugins/pastefromword/dialogs/pastefromword.js new file mode 100644 index 0000000..a10f297 --- /dev/null +++ b/_source/plugins/pastefromword/dialogs/pastefromword.js @@ -0,0 +1,307 @@ +/* +Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.dialog.add( 'pastefromword', function( editor ) +{ + return { + title : editor.lang.pastefromword.title, + minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350, + minHeight : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 270 : 260, + htmlToLoad : '', + cleanWord : function( editor, html, ignoreFont, removeStyles ) + { + // Remove comments [SF BUG-1481861]. + html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ; + + html = html.replace(/\s*<\/o:p>/g, '') ; + html = html.replace(/[\s\S]*?<\/o:p>/g, ' ') ; + + // Remove mso-xxx styles. + html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ; + + // Remove margin styles. + html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ; + html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ; + + html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ; + html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ; + + html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ; + + html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ; + + html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ; + + html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ; + html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ; + + // Remove FONT face attributes. + if ( ignoreFont ) + { + html = html.replace( /\s*face="[^"]*"/gi, '' ) ; + html = html.replace( /\s*face=[^ >]*/gi, '' ) ; + + html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ; + } + + // Remove Class attributes + html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ; + + // Remove styles. + if ( removeStyles ) + html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ; + + // Remove style, meta and link tags + html = html.replace( /]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ; + html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ; + + // Remove empty styles. + html = html.replace( /\s*style="\s*"/gi, '' ) ; + + html = html.replace( /]*>\s* \s*<\/SPAN>/gi, ' ' ) ; + + html = html.replace( /]*><\/SPAN>/gi, '' ) ; + + // Remove Lang attributes + html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ; + + html = html.replace( /([\s\S]*?)<\/SPAN>/gi, '$1' ) ; + + html = html.replace( /([\s\S]*?)<\/FONT>/gi, '$1' ) ; + + // Remove XML elements and declarations + html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ; + + // Remove w: tags with contents. + html = html.replace( /]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ; + + // Remove Tags with XML namespace declarations: <\/o:p> + html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ; + + html = html.replace( /<(U|I|STRIKE)> <\/\1>/g, ' ' ) ; + + html = html.replace( /\s*<\/H\d>/gi, '' ) ; + + // Remove "display:none" tags. + html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ; + + // Remove language tags + html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ; + + // Remove onmouseover and onmouseout events (from MS Word comments effect) + html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ; + html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ; + + if ( editor.config.pasteFromWordKeepsStructure ) + { + // The original tag send from Word is something like this: + html = html.replace( /]*)>/gi, '' ) ; + + // Word likes to insert extra tags, when using MSIE. (Wierd). + html = html.replace( /<(H\d)>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' ); + html = html.replace( /<(H\d)>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' ); + } + else + { + html = html.replace( /]*)>/gi, '' ) ; + html = html.replace( /]*)>/gi, '' ) ; + html = html.replace( /]*)>/gi, '' ) ; + html = html.replace( /]*)>/gi, '' ) ; + html = html.replace( /]*)>/gi, '' ) ; + html = html.replace( /]*)>/gi, '' ) ; + + html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ; + + // Transform

to

+ var re = new RegExp( '(]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error + html = html.replace( re, '' ) ; + + // Remove empty tags (three times, just to be sure). + // This also removes any empty anchor + html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ; + html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ; + html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ; + } + + return html ; + }, + onShow : function() + { + // To avoid JAWS putting virtual cursor back to the editor document, + // disable main document 'contentEditable' during dialog opening. + if ( CKEDITOR.env.ie ) + this.getParentEditor().document.getBody().$.contentEditable = 'false'; + + // FIREFOX BUG: Force the browser to render the dialog to make the to-be- + // inserted iframe editable. (#3366) + this.parts.dialog.$.offsetHeight; + + var container = this.getContentElement( 'general', 'editing_area' ).getElement(), + iframe = CKEDITOR.dom.element.createFromHtml( '' ); + + var lang = this.getParentEditor().lang; + + iframe.setStyles( + { + width : '346px', + height : '152px', + 'background-color' : 'white', + border : '1px solid black' + } ); + iframe.setCustomData( 'dialog', this ); + + var accTitle = lang.editorTitle.replace( '%1', lang.pastefromword.title ); + + if ( CKEDITOR.env.ie ) + container.setHtml( '' + + CKEDITOR.tools.htmlEncode( accTitle ) + + '' ); + else + { + container.setHtml( '' ); + container.setAttributes( + { + role : 'region', + title : accTitle + } ); + iframe.setAttributes( + { + role : 'region', + title : ' ' + } ); + } + container.append( iframe ); + if ( CKEDITOR.env.ie ) + container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' ); + + var isCustomDomain = CKEDITOR.env.ie && document.domain != window.location.hostname; + if ( isCustomDomain ) + { + CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad; + iframe.setAttribute( 'src', + 'javascript:void( (function(){' + + 'document.open();' + + 'document.domain="' + document.domain + '";' + + 'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' + + 'delete window.parent.CKEDITOR._cke_htmlToLoad;' + + 'document.close();' + + '})() )' ); + } + else + { + var doc = iframe.$.contentWindow.document; + doc.open(); + doc.write( this.definition.htmlToLoad ); + doc.close(); + } + }, + onOk : function() + { + var container = this.getContentElement( 'general', 'editing_area' ).getElement(), + iframe = container.getElementsByTag( 'iframe' ).getItem( 0 ), + editor = this.getParentEditor(), + html = this.definition.cleanWord( editor, iframe.$.contentWindow.document.body.innerHTML, + this.getValueOf( 'general', 'ignoreFontFace' ), + this.getValueOf( 'general', 'removeStyle' ) ); + + // Insertion should happen after main document design mode turned on. + setTimeout( function(){ + editor.insertHtml( html ); + }, 0 ); + }, + onHide : function() + { + if ( CKEDITOR.env.ie ) + this.getParentEditor().document.getBody().$.contentEditable = 'true'; + }, + onLoad : function() + { + if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' ) + this.parts.contents.setStyle( 'overflow', 'hidden' ); + }, + contents : + [ + { + id : 'general', + label : editor.lang.pastefromword.title, + elements : + [ + { + type : 'html', + style : 'white-space:normal;width:346px;display:block', + onShow : function() + { + /* + * SAFARI BUG: The advice label would overflow if the table layout + * isn't fixed. + */ + if ( CKEDITOR.env.webkit ) + this.getElement().getAscendant( 'table' ).setStyle( 'table-layout', 'fixed' ); + }, + html : editor.lang.pastefromword.advice + }, + { + type : 'html', + id : 'editing_area', + style : 'width: 100%; height: 100%;', + html : '
', + focus : function() + { + var div = this.getElement(); + var iframe = div.getElementsByTag( 'iframe' ); + if ( iframe.count() < 1 ) + return; + iframe = iframe.getItem( 0 ); + + // #3291 : JAWS needs the 500ms delay to detect that the editor iframe + // iframe is no longer editable. So that it will put the focus into the + // Paste from Word dialog's editable area instead. + setTimeout( function() + { + iframe.$.contentWindow.focus(); + }, 500 ); + } + }, + { + type : 'vbox', + padding : 0, + children : + [ + { + type : 'checkbox', + id : 'ignoreFontFace', + label : editor.lang.pastefromword.ignoreFontFace, + 'default' : editor.config.pasteFromWordIgnoreFontFace + }, + { + type : 'checkbox', + id : 'removeStyle', + label : editor.lang.pastefromword.removeStyle, + 'default' : editor.config.pasteFromWordRemoveStyle + } + ] + } + ] + } + ] + }; +} );