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