1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
\r
3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
4 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
\r
6 * == BEGIN LICENSE ==
\r
8 * Licensed under the terms of any of the following licenses at your
\r
11 * - GNU General Public License Version 2 or later (the "GPL")
\r
12 * http://www.gnu.org/licenses/gpl.html
\r
14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
15 * http://www.gnu.org/licenses/lgpl.html
\r
17 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
18 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
22 * This dialog is shown when, for some reason (usually security settings),
\r
23 * the user is not able to paste data from the clipboard to the editor using
\r
24 * the toolbar buttons or the context menu.
\r
26 <html xmlns="http://www.w3.org/1999/xhtml">
\r
29 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
30 <meta name="robots" content="noindex, nofollow" />
\r
31 <script src="common/fck_dialog_common.js" type="text/javascript"></script>
\r
32 <script type="text/javascript">
\r
33 var dialog = window.parent ;
\r
34 var oEditor = dialog.InnerDialogLoaded() ;
\r
35 var FCK = oEditor.FCK;
\r
36 var FCKTools = oEditor.FCKTools ;
\r
37 var FCKConfig = oEditor.FCKConfig ;
\r
38 var FCKBrowserInfo = oEditor.FCKBrowserInfo ;
\r
40 window.onload = function ()
\r
42 // First of all, translate the dialog box texts
\r
43 oEditor.FCKLanguageManager.TranslatePage(document) ;
\r
45 var sPastingType = dialog.Args().CustomValue ;
\r
47 if ( sPastingType == 'Word' || sPastingType == 'Security' )
\r
49 if ( sPastingType == 'Security' )
\r
50 document.getElementById( 'xSecurityMsg' ).style.display = '' ;
\r
52 // For document.domain compatibility (#123) we must do all the magic in
\r
54 var sFrameUrl = !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE ?
\r
55 'javascript:void(0)' :
\r
56 'javascript:void( (function(){' +
\r
57 'document.open() ;' +
\r
58 'document.domain=\'' + document.domain + '\' ;' +
\r
59 'document.write(\'<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>\') ;' +
\r
60 'document.close() ;' +
\r
61 'document.body.contentEditable = true ;' +
\r
62 'window.focus() ;' +
\r
65 var eFrameSpace = document.getElementById( 'xFrameSpace' ) ;
\r
66 eFrameSpace.innerHTML = '<iframe id="frmData" src="' + sFrameUrl + '" ' +
\r
67 'height="98%" width="99%" frameborder="0" style="border: #000000 1px; background-color: #ffffff"><\/iframe>' ;
\r
69 var oFrame = eFrameSpace.firstChild ;
\r
71 if ( !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE )
\r
73 // Avoid errors if the pasted content has any script that fails: #389
\r
74 var oDoc = oFrame.contentWindow.document ;
\r
76 oDoc.write('<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>') ;
\r
79 if ( FCKBrowserInfo.IsIE )
\r
80 oDoc.body.contentEditable = true ;
\r
82 oDoc.designMode = 'on' ;
\r
84 oFrame.contentWindow.focus();
\r
89 document.getElementById('txtData').style.display = '' ;
\r
90 SelectField( 'txtData' ) ;
\r
93 if ( sPastingType != 'Word' )
\r
94 document.getElementById('oWordCommands').style.display = 'none' ;
\r
96 dialog.SetOkButton( true ) ;
\r
97 dialog.SetAutoSize( true ) ;
\r
102 // Before doing anything, save undo snapshot.
\r
103 oEditor.FCKUndo.SaveUndoStep() ;
\r
107 var sPastingType = dialog.Args().CustomValue ;
\r
109 if ( sPastingType == 'Word' || sPastingType == 'Security' )
\r
111 var oFrame = document.getElementById('frmData') ;
\r
114 if ( oFrame.contentDocument )
\r
115 oBody = oFrame.contentDocument.body ;
\r
117 oBody = oFrame.contentWindow.document.body ;
\r
119 if ( sPastingType == 'Word' )
\r
121 // If a plugin creates a FCK.CustomCleanWord function it will be called instead of the default one
\r
122 if ( typeof( FCK.CustomCleanWord ) == 'function' )
\r
123 sHtml = FCK.CustomCleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
\r
125 sHtml = CleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
\r
128 sHtml = oBody.innerHTML ;
\r
130 // Fix relative anchor URLs (IE automatically adds the current page URL).
\r
131 var re = new RegExp( window.location + "#", "g" ) ;
\r
132 sHtml = sHtml.replace( re, '#') ;
\r
136 sHtml = oEditor.FCKTools.HTMLEncode( document.getElementById('txtData').value ) ;
\r
137 sHtml = FCKTools.ProcessLineBreaks( oEditor, FCKConfig, sHtml ) ;
\r
139 // FCK.InsertHtml() does not work for us, since document fragments cannot contain node fragments. :(
\r
140 // Use the marker method instead. It's primitive, but it works.
\r
141 var range = new oEditor.FCKDomRange( oEditor.FCK.EditorWindow ) ;
\r
142 var oDoc = oEditor.FCK.EditorDocument ;
\r
143 dialog.Selection.EnsureSelection() ;
\r
144 range.MoveToSelection() ;
\r
145 range.DeleteContents() ;
\r
147 for ( var i = 0 ; i < 5 ; i++ )
\r
148 marker.push( parseInt(Math.random() * 100000, 10 ) ) ;
\r
149 marker = marker.join( "" ) ;
\r
150 range.InsertNode ( oDoc.createTextNode( marker ) ) ;
\r
151 var bookmark = range.CreateBookmark() ;
\r
153 // Now we've got a marker indicating the paste position in the editor document.
\r
154 // Find its position in the HTML code.
\r
155 var htmlString = oDoc.body.innerHTML ;
\r
156 var index = htmlString.indexOf( marker ) ;
\r
158 // Split it the HTML code up, add the code we generated, and put them back together.
\r
159 var htmlList = [] ;
\r
160 htmlList.push( htmlString.substr( 0, index ) ) ;
\r
161 htmlList.push( sHtml ) ;
\r
162 htmlList.push( htmlString.substr( index + marker.length ) ) ;
\r
163 htmlString = htmlList.join( "" ) ;
\r
165 if ( oEditor.FCKBrowserInfo.IsIE )
\r
166 oEditor.FCK.SetInnerHtml( htmlString ) ;
\r
168 oDoc.body.innerHTML = htmlString ;
\r
170 range.MoveToBookmark( bookmark ) ;
\r
171 range.Collapse( false ) ;
\r
177 oEditor.FCK.InsertHtml( sHtml ) ;
\r
182 // This function will be called from the PasteFromWord dialog (fck_paste.html)
\r
183 // Input: oNode a DOM node that contains the raw paste from the clipboard
\r
184 // bIgnoreFont, bRemoveStyles booleans according to the values set in the dialog
\r
185 // Output: the cleaned string
\r
186 function CleanWord( oNode, bIgnoreFont, bRemoveStyles )
\r
188 var html = oNode.innerHTML ;
\r
190 html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
\r
191 html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, ' ') ;
\r
193 // Remove mso-xxx styles.
\r
194 html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
\r
196 // Remove margin styles.
\r
197 html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;
\r
198 html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;
\r
200 html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*;/gi, '' ) ;
\r
201 html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*"/gi, "\"" ) ;
\r
203 html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
\r
205 html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
\r
207 html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
\r
209 html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
\r
210 html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;
\r
212 // Remove FONT face attributes.
\r
215 html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
\r
216 html = html.replace( /\s*face=[^ >]*/gi, '' ) ;
\r
218 html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
\r
221 // Remove Class attributes
\r
222 html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
225 if ( bRemoveStyles )
\r
226 html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
\r
228 // Remove style, meta and link tags
\r
229 html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;
\r
230 html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;
\r
232 // Remove empty styles.
\r
233 html = html.replace( /\s*style="\s*"/gi, '' ) ;
\r
235 html = html.replace( /<SPAN\s*[^>]*>\s* \s*<\/SPAN>/gi, ' ' ) ;
\r
237 html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
\r
239 // Remove Lang attributes
\r
240 html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
242 html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;
\r
244 html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;
\r
246 // Remove XML elements and declarations
\r
247 html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;
\r
249 // Remove w: tags with contents.
\r
250 html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;
\r
252 // Remove Tags with XML namespace declarations: <o:p><\/o:p>
\r
253 html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;
\r
255 // Remove comments [SF BUG-1481861].
\r
256 html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;
\r
258 html = html.replace( /<(U|I|STRIKE)> <\/\1>/g, ' ' ) ;
\r
260 html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
\r
262 // Remove "display:none" tags.
\r
263 html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;
\r
265 // Remove language tags
\r
266 html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;
\r
268 // Remove onmouseover and onmouseout events (from MS Word comments effect)
\r
269 html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
\r
270 html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
\r
272 if ( FCKConfig.CleanWordKeepsStructure )
\r
274 // The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
\r
275 html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;
\r
277 // Word likes to insert extra <font> tags, when using MSIE. (Wierd).
\r
278 html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
\r
279 html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
\r
283 html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
\r
284 html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
\r
285 html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
\r
286 html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
\r
287 html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
\r
288 html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
\r
290 html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
\r
292 // Transform <P> to <DIV>
\r
293 var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error
\r
294 html = html.replace( re, '<div$2<\/div>' ) ;
\r
296 // Remove empty tags (three times, just to be sure).
\r
297 // This also removes any empty anchor
\r
298 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
299 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
300 html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
\r
309 <body style="overflow: hidden">
\r
310 <table cellspacing="0" cellpadding="0" width="100%" border="0" style="height: 98%">
\r
313 <div id="xSecurityMsg" style="display: none">
\r
314 <span fcklang="DlgPasteSec">Because of your browser security settings,
\r
315 the editor is not able to access your clipboard data directly. You are required
\r
316 to paste it again in this window.</span><br />
\r
320 <span fcklang="DlgPasteMsg2">Please paste inside the following box using the keyboard
\r
321 (<strong>Ctrl+V</strong>) and hit <strong>OK</strong>.</span><br />
\r
327 <td id="xFrameSpace" valign="top" height="100%" style="border: #000000 1px solid">
\r
328 <textarea id="txtData" cols="80" rows="5" style="border: #000000 1px; display: none;
\r
329 width: 99%; height: 98%"></textarea>
\r
332 <tr id="oWordCommands">
\r
335 <input id="chkRemoveFont" type="checkbox" checked="checked" />
\r
336 <label for="chkRemoveFont" fcklang="DlgPasteIgnoreFont">
\r
337 Ignore Font Face definitions</label>
\r
339 <input id="chkRemoveStyles" type="checkbox" />
\r
340 <label for="chkRemoveStyles" fcklang="DlgPasteRemoveStyles">
\r
341 Remove Styles definitions</label>
\r