<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r
<!--\r
* FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2007 Frederico Caldeira Knabben\r
+ * Copyright (C) 2003-2010 Frederico Caldeira Knabben\r
*\r
* == BEGIN LICENSE ==\r
*\r
<title></title>\r
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
<meta name="robots" content="noindex, nofollow" />\r
-\r
+ <script src="common/fck_dialog_common.js" type="text/javascript"></script>\r
<script type="text/javascript">\r
-var oEditor = window.parent.InnerDialogLoaded() ;\r
+var dialog = window.parent ;\r
+var oEditor = dialog.InnerDialogLoaded() ;\r
var FCK = oEditor.FCK;\r
var FCKTools = oEditor.FCKTools ;\r
var FCKConfig = oEditor.FCKConfig ;\r
+var FCKBrowserInfo = oEditor.FCKBrowserInfo ;\r
\r
window.onload = function ()\r
{\r
// First of all, translate the dialog box texts\r
oEditor.FCKLanguageManager.TranslatePage(document) ;\r
- \r
- var sPastingType = window.parent.dialogArguments.CustomValue ;\r
+\r
+ var sPastingType = dialog.Args().CustomValue ;\r
\r
if ( sPastingType == 'Word' || sPastingType == 'Security' )\r
{\r
if ( sPastingType == 'Security' )\r
document.getElementById( 'xSecurityMsg' ).style.display = '' ;\r
\r
- var oFrame = document.getElementById('frmData') ;\r
- oFrame.style.display = '' ;\r
+ // For document.domain compatibility (#123) we must do all the magic in\r
+ // the URL for IE.\r
+ var sFrameUrl = !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE ?\r
+ 'javascript:void(0)' :\r
+ 'javascript:void( (function(){' +\r
+ 'document.open() ;' +\r
+ 'document.domain=\'' + document.domain + '\' ;' +\r
+ 'document.write(\'<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>\') ;' +\r
+ 'document.close() ;' +\r
+ 'document.body.contentEditable = true ;' +\r
+ 'window.focus() ;' +\r
+ '})() )' ;\r
+\r
+ var eFrameSpace = document.getElementById( 'xFrameSpace' ) ;\r
+ eFrameSpace.innerHTML = '<iframe id="frmData" src="' + sFrameUrl + '" ' +\r
+ 'height="98%" width="99%" frameborder="0" style="border: #000000 1px; background-color: #ffffff"><\/iframe>' ;\r
+\r
+ var oFrame = eFrameSpace.firstChild ;\r
+\r
+ if ( !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE )\r
+ {\r
+ // Avoid errors if the pasted content has any script that fails: #389\r
+ var oDoc = oFrame.contentWindow.document ;\r
+ oDoc.open() ;\r
+ oDoc.write('<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>') ;\r
+ oDoc.close() ;\r
+\r
+ if ( FCKBrowserInfo.IsIE )\r
+ oDoc.body.contentEditable = true ;\r
+ else\r
+ oDoc.designMode = 'on' ;\r
\r
- if ( oFrame.contentDocument )\r
- oFrame.contentDocument.designMode = 'on' ;\r
- else\r
- oFrame.contentWindow.document.body.contentEditable = true ;\r
+ oFrame.contentWindow.focus();\r
+ }\r
}\r
else\r
{\r
document.getElementById('txtData').style.display = '' ;\r
+ SelectField( 'txtData' ) ;\r
}\r
\r
if ( sPastingType != 'Word' )\r
document.getElementById('oWordCommands').style.display = 'none' ;\r
\r
- window.parent.SetOkButton( true ) ;\r
- window.parent.SetAutoSize( true ) ;\r
+ dialog.SetOkButton( true ) ;\r
+ dialog.SetAutoSize( true ) ;\r
}\r
\r
function Ok()\r
{\r
+ // Before doing anything, save undo snapshot.\r
+ oEditor.FCKUndo.SaveUndoStep() ;\r
+\r
var sHtml ;\r
\r
- var sPastingType = window.parent.dialogArguments.CustomValue ;\r
+ var sPastingType = dialog.Args().CustomValue ;\r
\r
if ( sPastingType == 'Word' || sPastingType == 'Security' )\r
{\r
else\r
{\r
sHtml = oEditor.FCKTools.HTMLEncode( document.getElementById('txtData').value ) ;\r
- sHtml = sHtml.replace( /\n/g, '<BR>' ) ;\r
+ sHtml = FCKTools.ProcessLineBreaks( oEditor, FCKConfig, sHtml ) ;\r
+\r
+ // FCK.InsertHtml() does not work for us, since document fragments cannot contain node fragments. :(\r
+ // Use the marker method instead. It's primitive, but it works.\r
+ var range = new oEditor.FCKDomRange( oEditor.FCK.EditorWindow ) ;\r
+ var oDoc = oEditor.FCK.EditorDocument ;\r
+ dialog.Selection.EnsureSelection() ;\r
+ range.MoveToSelection() ;\r
+ range.DeleteContents() ;\r
+ var marker = [] ;\r
+ for ( var i = 0 ; i < 5 ; i++ )\r
+ marker.push( parseInt(Math.random() * 100000, 10 ) ) ;\r
+ marker = marker.join( "" ) ;\r
+ range.InsertNode ( oDoc.createTextNode( marker ) ) ;\r
+ var bookmark = range.CreateBookmark() ;\r
+\r
+ // Now we've got a marker indicating the paste position in the editor document.\r
+ // Find its position in the HTML code.\r
+ var htmlString = oDoc.body.innerHTML ;\r
+ var index = htmlString.indexOf( marker ) ;\r
+\r
+ // Split it the HTML code up, add the code we generated, and put them back together.\r
+ var htmlList = [] ;\r
+ htmlList.push( htmlString.substr( 0, index ) ) ;\r
+ htmlList.push( sHtml ) ;\r
+ htmlList.push( htmlString.substr( index + marker.length ) ) ;\r
+ htmlString = htmlList.join( "" ) ;\r
+\r
+ if ( oEditor.FCKBrowserInfo.IsIE )\r
+ oEditor.FCK.SetInnerHtml( htmlString ) ;\r
+ else\r
+ oDoc.body.innerHTML = htmlString ;\r
+\r
+ range.MoveToBookmark( bookmark ) ;\r
+ range.Collapse( false ) ;\r
+ range.Select() ;\r
+ range.Release() ;\r
+ return true ;\r
}\r
\r
oEditor.FCK.InsertHtml( sHtml ) ;\r
return true ;\r
}\r
\r
-function CleanUpBox()\r
-{\r
- var oFrame = document.getElementById('frmData') ;\r
-\r
- if ( oFrame.contentDocument )\r
- oFrame.contentDocument.body.innerHTML = '' ;\r
- else\r
- oFrame.contentWindow.document.body.innerHTML = '' ;\r
-}\r
-\r
-\r
// This function will be called from the PasteFromWord dialog (fck_paste.html)\r
// Input: oNode a DOM node that contains the raw paste from the clipboard\r
// bIgnoreFont, bRemoveStyles booleans according to the values set in the dialog\r
var html = oNode.innerHTML ;\r
\r
html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;\r
- html = html.replace(/<o:p>.*?<\/o:p>/g, ' ') ;\r
+ html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, ' ') ;\r
\r
// Remove mso-xxx styles.\r
html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;\r
\r
// Remove margin styles.\r
- html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, '' ) ;\r
- html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;\r
+ html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;\r
+ html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;\r
\r
- html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;\r
- html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;\r
+ html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*;/gi, '' ) ;\r
+ html = html.replace( /\s*TEXT-INDENT: 0(?:cm|in)\s*"/gi, "\"" ) ;\r
\r
html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;\r
\r
if ( bRemoveStyles )\r
html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;\r
\r
+ // Remove style, meta and link tags\r
+ html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;\r
+ html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;\r
+\r
// Remove empty styles.\r
html = html.replace( /\s*style="\s*"/gi, '' ) ;\r
\r
// Remove Lang attributes\r
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;\r
\r
- html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;\r
+ html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;\r
\r
- html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;\r
+ html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;\r
\r
// Remove XML elements and declarations\r
html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;\r
\r
+ // Remove w: tags with contents.\r
+ html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;\r
+\r
// Remove Tags with XML namespace declarations: <o:p><\/o:p>\r
html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;\r
\r
// Remove comments [SF BUG-1481861].\r
- html = html.replace(/<\!--.*-->/g, '' ) ;\r
+ html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;\r
\r
html = html.replace( /<(U|I|STRIKE)> <\/\1>/g, ' ' ) ;\r
\r
html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;\r
\r
// Remove "display:none" tags.\r
- html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none(.*?)<\/\1>/ig, '' ) ;\r
+ html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;\r
+\r
+ // Remove language tags\r
+ html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;\r
+\r
+ // Remove onmouseover and onmouseout events (from MS Word comments effect)\r
+ html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;\r
+ html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;\r
\r
if ( FCKConfig.CleanWordKeepsStructure )\r
{\r
html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;\r
\r
// Word likes to insert extra <font> tags, when using MSIE. (Wierd).\r
- html = html.replace( /<(H\d)><FONT[^>]*>(.*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );\r
- html = html.replace( /<(H\d)><EM>(.*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );\r
+ html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );\r
+ html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );\r
}\r
else\r
{\r
html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;\r
\r
// Transform <P> to <DIV>\r
- var re = new RegExp( '(<P)([^>]*>.*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error\r
+ var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error\r
html = html.replace( re, '<div$2<\/div>' ) ;\r
\r
// Remove empty tags (three times, just to be sure).\r
</td>\r
</tr>\r
<tr>\r
- <td valign="top" height="100%" style="border-right: #000000 1px solid; border-top: #000000 1px solid;\r
- border-left: #000000 1px solid; border-bottom: #000000 1px solid">\r
+ <td id="xFrameSpace" valign="top" height="100%" style="border: #000000 1px solid">\r
<textarea id="txtData" cols="80" rows="5" style="border: #000000 1px; display: none;\r
width: 99%; height: 98%"></textarea>\r
- <iframe id="frmData" src="javascript:void(0)" height="98%" width="99%" frameborder="0"\r
- style="border-right: #000000 1px; border-top: #000000 1px; display: none; border-left: #000000 1px;\r
- border-bottom: #000000 1px; background-color: #ffffff"></iframe>\r
</td>\r
</tr>\r
<tr id="oWordCommands">\r
<td>\r
- <table border="0" cellpadding="0" cellspacing="0" width="100%">\r
- <tr>\r
- <td nowrap="nowrap">\r
- <input id="chkRemoveFont" type="checkbox" checked="checked" />\r
- <label for="chkRemoveFont" fcklang="DlgPasteIgnoreFont">\r
- Ignore Font Face definitions</label>\r
- <br />\r
- <input id="chkRemoveStyles" type="checkbox" />\r
- <label for="chkRemoveStyles" fcklang="DlgPasteRemoveStyles">\r
- Remove Styles definitions</label>\r
- </td>\r
- <td align="right" valign="top">\r
- <input type="button" fcklang="DlgPasteCleanBox" value="Clean Up Box" onclick="CleanUpBox()" />\r
- </td>\r
- </tr>\r
- </table>\r
+\r
+ <input id="chkRemoveFont" type="checkbox" checked="checked" />\r
+ <label for="chkRemoveFont" fcklang="DlgPasteIgnoreFont">\r
+ Ignore Font Face definitions</label>\r
+ <br />\r
+ <input id="chkRemoveStyles" type="checkbox" />\r
+ <label for="chkRemoveStyles" fcklang="DlgPasteRemoveStyles">\r
+ Remove Styles definitions</label>\r
+\r
</td>\r
</tr>\r
</table>\r