2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'pastefromword', function( editor )
\r
9 title : editor.lang.pastefromword.title,
\r
10 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,
\r
11 minHeight : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 270 : 260,
\r
12 htmlToLoad : '<!doctype html><script type="text/javascript">'
\r
13 + 'window.onload = function()'
\r
15 + 'if ( ' + CKEDITOR.env.ie + ' ) '
\r
16 + 'document.body.contentEditable = "true";'
\r
18 + 'document.designMode = "on";'
\r
19 + 'var iframe = new window.parent.CKEDITOR.dom.element( frameElement );'
\r
20 + 'var dialog = iframe.getCustomData( "dialog" );'
\r
22 + 'iframe.getFrameDocument().on( "keydown", function( e )\
\r
24 if ( e.data.getKeystroke() == 27 )\
\r
27 + 'dialog.fire( "iframeAdded", { iframe : iframe } );'
\r
29 + '</script><style>body { margin: 3px; height: 95%; } </style><body></body>',
\r
30 cleanWord : function( editor, html, ignoreFont, removeStyles )
\r
32 // Remove comments [SF BUG-1481861].
\r
33 html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;
\r
35 html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
\r
36 html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, ' ') ;
\r
38 // Remove mso-xxx styles.
\r
39 html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
\r
41 // Remove margin styles.
\r
42 html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;
\r
43 html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;
\r
45 html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
\r
46 html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
\r
48 html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
\r
50 html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
\r
52 html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
\r
54 html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
\r
55 html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;
\r
57 // Remove FONT face attributes.
\r
60 html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
\r
61 html = html.replace( /\s*face=[^ >]*/gi, '' ) ;
\r
63 html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
\r
66 // Remove Class attributes
\r
67 html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
71 html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
\r
73 // Remove style, meta and link tags
\r
74 html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;
\r
75 html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;
\r
77 // Remove empty styles.
\r
78 html = html.replace( /\s*style="\s*"/gi, '' ) ;
\r
80 html = html.replace( /<SPAN\s*[^>]*>\s* \s*<\/SPAN>/gi, ' ' ) ;
\r
82 html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
\r
84 // Remove Lang attributes
\r
85 html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
87 html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;
\r
89 html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;
\r
91 // Remove XML elements and declarations
\r
92 html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;
\r
94 // Remove w: tags with contents.
\r
95 html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;
\r
97 // Remove Tags with XML namespace declarations: <o:p><\/o:p>
\r
98 html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;
\r
100 html = html.replace( /<(U|I|STRIKE)> <\/\1>/g, ' ' ) ;
\r
102 html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
\r
104 // Remove "display:none" tags.
\r
105 html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;
\r
107 // Remove language tags
\r
108 html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
110 // Remove onmouseover and onmouseout events (from MS Word comments effect)
\r
111 html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
\r
112 html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
\r
114 if ( editor.config.pasteFromWordKeepsStructure )
\r
116 // The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
\r
117 html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;
\r
119 // Word likes to insert extra <font> tags, when using MSIE. (Wierd).
\r
120 html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
\r
121 html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
\r
125 html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
\r
126 html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
\r
127 html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
\r
128 html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
\r
129 html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
\r
130 html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
\r
132 html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
\r
134 // Transform <P> to <DIV>
\r
135 var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error
\r
136 html = html.replace( re, '<div$2<\/div>' ) ;
\r
138 // Remove empty tags (three times, just to be sure).
\r
139 // This also removes any empty anchor
\r
140 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
141 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
142 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
147 onShow : function()
\r
149 // To avoid JAWS putting virtual cursor back to the editor document,
\r
150 // disable main document 'contentEditable' during dialog opening.
\r
151 if ( CKEDITOR.env.ie )
\r
152 this.getParentEditor().document.getBody().$.contentEditable = 'false';
\r
154 // FIREFOX BUG: Force the browser to render the dialog to make the to-be-
\r
155 // inserted iframe editable. (#3366)
\r
156 this.parts.dialog.$.offsetHeight;
\r
158 var container = this.getContentElement( 'general', 'editing_area' ).getElement(),
\r
159 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe src="javascript:void(0)" frameborder="0" allowtransparency="1"></iframe>' );
\r
161 var lang = this.getParentEditor().lang;
\r
167 'background-color' : 'white',
\r
168 border : '1px solid black'
\r
170 iframe.setCustomData( 'dialog', this );
\r
172 var accTitle = lang.editorTitle.replace( '%1', lang.pastefromword.title );
\r
174 if ( CKEDITOR.env.ie )
\r
175 container.setHtml( '<legend style="position:absolute;top:-1000000px;left:-1000000px;">'
\r
176 + CKEDITOR.tools.htmlEncode( accTitle )
\r
180 container.setHtml( '' );
\r
181 container.setAttributes(
\r
186 iframe.setAttributes(
\r
192 container.append( iframe );
\r
193 if ( CKEDITOR.env.ie )
\r
194 container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' );
\r
196 if ( CKEDITOR.env.isCustomDomain() )
\r
198 CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad;
\r
199 iframe.setAttribute( 'src',
\r
200 'javascript:void( (function(){' +
\r
201 'document.open();' +
\r
202 'document.domain="' + document.domain + '";' +
\r
203 'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' +
\r
204 'delete window.parent.CKEDITOR._cke_htmlToLoad;' +
\r
205 'document.close();' +
\r
210 var doc = iframe.$.contentWindow.document;
\r
212 doc.write( this.definition.htmlToLoad );
\r
218 var container = this.getContentElement( 'general', 'editing_area' ).getElement(),
\r
219 iframe = container.getElementsByTag( 'iframe' ).getItem( 0 ),
\r
220 editor = this.getParentEditor(),
\r
221 html = this.definition.cleanWord( editor, iframe.$.contentWindow.document.body.innerHTML,
\r
222 this.getValueOf( 'general', 'ignoreFontFace' ),
\r
223 this.getValueOf( 'general', 'removeStyle' ) );
\r
225 // Insertion should happen after main document design mode turned on.
\r
226 setTimeout( function(){
\r
227 editor.insertHtml( html );
\r
230 onHide : function()
\r
232 if ( CKEDITOR.env.ie )
\r
233 this.getParentEditor().document.getBody().$.contentEditable = 'true';
\r
235 onLoad : function()
\r
237 if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' )
\r
238 this.parts.contents.setStyle( 'overflow', 'hidden' );
\r
244 label : editor.lang.pastefromword.title,
\r
249 style : 'white-space:normal;width:346px;display:block',
\r
250 onShow : function()
\r
253 * SAFARI BUG: The advice label would overflow if the table layout
\r
256 if ( CKEDITOR.env.webkit )
\r
257 this.getElement().getAscendant( 'table' ).setStyle( 'table-layout', 'fixed' );
\r
259 html : editor.lang.pastefromword.advice
\r
263 id : 'editing_area',
\r
264 style : 'width: 100%; height: 100%;',
\r
265 html : '<fieldset></fieldset>',
\r
268 var div = this.getElement();
\r
269 var iframe = div.getElementsByTag( 'iframe' );
\r
270 if ( iframe.count() < 1 )
\r
272 iframe = iframe.getItem( 0 );
\r
274 // #3291 : JAWS needs the 500ms delay to detect that the editor iframe
\r
275 // iframe is no longer editable. So that it will put the focus into the
\r
276 // Paste from Word dialog's editable area instead.
\r
277 setTimeout( function()
\r
279 iframe.$.contentWindow.focus();
\r
290 id : 'ignoreFontFace',
\r
291 label : editor.lang.pastefromword.ignoreFontFace,
\r
292 'default' : editor.config.pasteFromWordIgnoreFontFace
\r
296 id : 'removeStyle',
\r
297 label : editor.lang.pastefromword.removeStyle,
\r
298 'default' : editor.config.pasteFromWordRemoveStyle
\r