import torrus 1.0.9
[freeside.git] / httemplate / elements / fckeditor / editor / dialog / fck_paste.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r
2 <!--\r
3  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
4  * Copyright (C) 2003-2010 Frederico Caldeira Knabben\r
5  *\r
6  * == BEGIN LICENSE ==\r
7  *\r
8  * Licensed under the terms of any of the following licenses at your\r
9  * choice:\r
10  *\r
11  *  - GNU General Public License Version 2 or later (the "GPL")\r
12  *    http://www.gnu.org/licenses/gpl.html\r
13  *\r
14  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
15  *    http://www.gnu.org/licenses/lgpl.html\r
16  *\r
17  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
18  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
19  *\r
20  * == END LICENSE ==\r
21  *\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
25 -->\r
26 <html xmlns="http://www.w3.org/1999/xhtml">\r
27 <head>\r
28         <title></title>\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
39 \r
40 window.onload = function ()\r
41 {\r
42         // First of all, translate the dialog box texts\r
43         oEditor.FCKLanguageManager.TranslatePage(document) ;\r
44 \r
45         var sPastingType = dialog.Args().CustomValue ;\r
46 \r
47         if ( sPastingType == 'Word' || sPastingType == 'Security' )\r
48         {\r
49                 if ( sPastingType == 'Security' )\r
50                         document.getElementById( 'xSecurityMsg' ).style.display = '' ;\r
51 \r
52                 // For document.domain compatibility (#123) we must do all the magic in\r
53                 // the URL for IE.\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
63                                 '})() )' ;\r
64 \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
68 \r
69                 var oFrame = eFrameSpace.firstChild ;\r
70 \r
71                 if ( !oEditor.FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE )\r
72                 {\r
73                         // Avoid errors if the pasted content has any script that fails: #389\r
74                         var oDoc = oFrame.contentWindow.document ;\r
75                         oDoc.open() ;\r
76                         oDoc.write('<html><head><scr' + 'ipt>window.onerror = function() { return true ; };<\/script><\/head><body><\/body><\/html>') ;\r
77                         oDoc.close() ;\r
78 \r
79                         if ( FCKBrowserInfo.IsIE )\r
80                                 oDoc.body.contentEditable = true ;\r
81                         else\r
82                                 oDoc.designMode = 'on' ;\r
83 \r
84                         oFrame.contentWindow.focus();\r
85                 }\r
86         }\r
87         else\r
88         {\r
89                 document.getElementById('txtData').style.display = '' ;\r
90                 SelectField( 'txtData' ) ;\r
91         }\r
92 \r
93         if ( sPastingType != 'Word' )\r
94                 document.getElementById('oWordCommands').style.display = 'none' ;\r
95 \r
96         dialog.SetOkButton( true ) ;\r
97         dialog.SetAutoSize( true ) ;\r
98 }\r
99 \r
100 function Ok()\r
101 {\r
102         // Before doing anything, save undo snapshot.\r
103         oEditor.FCKUndo.SaveUndoStep() ;\r
104 \r
105         var sHtml ;\r
106 \r
107         var sPastingType = dialog.Args().CustomValue ;\r
108 \r
109         if ( sPastingType == 'Word' || sPastingType == 'Security' )\r
110         {\r
111                 var oFrame = document.getElementById('frmData') ;\r
112                 var oBody ;\r
113 \r
114                 if ( oFrame.contentDocument )\r
115                         oBody = oFrame.contentDocument.body ;\r
116                 else\r
117                         oBody = oFrame.contentWindow.document.body ;\r
118 \r
119                 if ( sPastingType == 'Word' )\r
120                 {\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
124                         else\r
125                                 sHtml = CleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;\r
126                 }\r
127                 else\r
128                         sHtml = oBody.innerHTML ;\r
129 \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
133         }\r
134         else\r
135         {\r
136                 sHtml = oEditor.FCKTools.HTMLEncode( document.getElementById('txtData').value )  ;\r
137                 sHtml = FCKTools.ProcessLineBreaks( oEditor, FCKConfig, sHtml ) ;\r
138 \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
146                 var marker = [] ;\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
152 \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
157 \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
164 \r
165                 if ( oEditor.FCKBrowserInfo.IsIE )\r
166                         oEditor.FCK.SetInnerHtml( htmlString ) ;\r
167                 else\r
168                         oDoc.body.innerHTML = htmlString ;\r
169 \r
170                 range.MoveToBookmark( bookmark ) ;\r
171                 range.Collapse( false ) ;\r
172                 range.Select() ;\r
173                 range.Release() ;\r
174                 return true ;\r
175         }\r
176 \r
177         oEditor.FCK.InsertHtml( sHtml ) ;\r
178 \r
179         return true ;\r
180 }\r
181 \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
187 {\r
188         var html = oNode.innerHTML ;\r
189 \r
190         html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;\r
191         html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, '&nbsp;') ;\r
192 \r
193         // Remove mso-xxx styles.\r
194         html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;\r
195 \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
199 \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
202 \r
203         html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;\r
204 \r
205         html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;\r
206 \r
207         html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;\r
208 \r
209         html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;\r
210         html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;\r
211 \r
212         // Remove FONT face attributes.\r
213         if ( bIgnoreFont )\r
214         {\r
215                 html = html.replace( /\s*face="[^"]*"/gi, '' ) ;\r
216                 html = html.replace( /\s*face=[^ >]*/gi, '' ) ;\r
217 \r
218                 html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;\r
219         }\r
220 \r
221         // Remove Class attributes\r
222         html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;\r
223 \r
224         // Remove styles.\r
225         if ( bRemoveStyles )\r
226                 html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;\r
227 \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
231 \r
232         // Remove empty styles.\r
233         html =  html.replace( /\s*style="\s*"/gi, '' ) ;\r
234 \r
235         html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;\r
236 \r
237         html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;\r
238 \r
239         // Remove Lang attributes\r
240         html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;\r
241 \r
242         html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;\r
243 \r
244         html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;\r
245 \r
246         // Remove XML elements and declarations\r
247         html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;\r
248 \r
249         // Remove w: tags with contents.\r
250         html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;\r
251 \r
252         // Remove Tags with XML namespace declarations: <o:p><\/o:p>\r
253         html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;\r
254 \r
255         // Remove comments [SF BUG-1481861].\r
256         html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;\r
257 \r
258         html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;\r
259 \r
260         html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;\r
261 \r
262         // Remove "display:none" tags.\r
263         html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;\r
264 \r
265         // Remove language tags\r
266         html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;\r
267 \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
271 \r
272         if ( FCKConfig.CleanWordKeepsStructure )\r
273         {\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
276 \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
280         }\r
281         else\r
282         {\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
289 \r
290                 html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;\r
291 \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
295 \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
301         }\r
302 \r
303         return html ;\r
304 }\r
305 \r
306         </script>\r
307 \r
308 </head>\r
309 <body style="overflow: hidden">\r
310         <table cellspacing="0" cellpadding="0" width="100%" border="0" style="height: 98%">\r
311                 <tr>\r
312                         <td>\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
317                                         &nbsp;\r
318                                 </div>\r
319                                 <div>\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
322                                         &nbsp;\r
323                                 </div>\r
324                         </td>\r
325                 </tr>\r
326                 <tr>\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
330                         </td>\r
331                 </tr>\r
332                 <tr id="oWordCommands">\r
333                         <td>\r
334 \r
335                                         <input id="chkRemoveFont" type="checkbox" checked="checked" />\r
336                                         <label for="chkRemoveFont" fcklang="DlgPasteIgnoreFont">\r
337                                                 Ignore Font Face definitions</label>\r
338                                         <br />\r
339                                         <input id="chkRemoveStyles" type="checkbox" />\r
340                                         <label for="chkRemoveStyles" fcklang="DlgPasteRemoveStyles">\r
341                                                 Remove Styles definitions</label>\r
342 \r
343                         </td>\r
344                 </tr>\r
345         </table>\r
346 </body>\r
347 </html>\r