fck_paste.html 12 KB

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