source: sandbox/filemanager/tp/fckeditor/editor/_source/internals/fck_ie.js @ 1575

Revision 1575, 13.3 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

  • Property svn:executable set to *
Line 
1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 *  - GNU General Public License Version 2 or later (the "GPL")
11 *    http://www.gnu.org/licenses/gpl.html
12 *
13 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 *    http://www.gnu.org/licenses/lgpl.html
15 *
16 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17 *    http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * Creation and initialization of the "FCK" object. This is the main
22 * object that represents an editor instance.
23 * (IE specific implementations)
24 */
25
26FCK.Description = "FCKeditor for Internet Explorer 5.5+" ;
27
28FCK._GetBehaviorsStyle = function()
29{
30        if ( !FCK._BehaviorsStyle )
31        {
32                var sBasePath = FCKConfig.BasePath ;
33                var sTableBehavior = '' ;
34                var sStyle ;
35
36                // The behaviors should be pointed using the BasePath to avoid security
37                // errors when using a different BaseHref.
38                sStyle = '<style type="text/css" _fcktemp="true">' ;
39
40                if ( FCKConfig.ShowBorders )
41                        sTableBehavior = 'url(' + sBasePath + 'css/behaviors/showtableborders.htc)' ;
42
43                // Disable resize handlers.
44                sStyle += 'INPUT,TEXTAREA,SELECT,.FCK__Anchor,.FCK__PageBreak,.FCK__InputHidden' ;
45
46                if ( FCKConfig.DisableObjectResizing )
47                {
48                        sStyle += ',IMG' ;
49                        sTableBehavior += ' url(' + sBasePath + 'css/behaviors/disablehandles.htc)' ;
50                }
51
52                sStyle += ' { behavior: url(' + sBasePath + 'css/behaviors/disablehandles.htc) ; }' ;
53
54                if ( sTableBehavior.length > 0 )
55                        sStyle += 'TABLE { behavior: ' + sTableBehavior + ' ; }' ;
56
57                sStyle += '</style>' ;
58                FCK._BehaviorsStyle = sStyle ;
59        }
60
61        return FCK._BehaviorsStyle ;
62}
63
64function Doc_OnMouseUp()
65{
66        if ( FCK.EditorWindow.event.srcElement.tagName == 'HTML' )
67        {
68                FCK.Focus() ;
69                FCK.EditorWindow.event.cancelBubble     = true ;
70                FCK.EditorWindow.event.returnValue      = false ;
71        }
72}
73
74function Doc_OnPaste()
75{
76        var body = FCK.EditorDocument.body ;
77
78        body.detachEvent( 'onpaste', Doc_OnPaste ) ;
79
80        var ret = FCK.Paste( !FCKConfig.ForcePasteAsPlainText && !FCKConfig.AutoDetectPasteFromWord ) ;
81
82        body.attachEvent( 'onpaste', Doc_OnPaste ) ;
83
84        return ret ;
85}
86
87function Doc_OnDblClick()
88{
89        FCK.OnDoubleClick( FCK.EditorWindow.event.srcElement ) ;
90        FCK.EditorWindow.event.cancelBubble = true ;
91}
92
93function Doc_OnSelectionChange()
94{
95        // Don't fire the event if no document is loaded.
96        if ( !FCK.IsSelectionChangeLocked && FCK.EditorDocument )
97                FCK.Events.FireEvent( "OnSelectionChange" ) ;
98}
99
100function Doc_OnDrop()
101{
102        if ( FCK.MouseDownFlag )
103        {
104                FCK.MouseDownFlag = false ;
105                return ;
106        }
107
108        if ( FCKConfig.ForcePasteAsPlainText )
109        {
110                var evt = FCK.EditorWindow.event ;
111
112                if ( FCK._CheckIsPastingEnabled() || FCKConfig.ShowDropDialog )
113                        FCK.PasteAsPlainText( evt.dataTransfer.getData( 'Text' ) ) ;
114
115                evt.returnValue = false ;
116                evt.cancelBubble = true ;
117        }
118}
119
120FCK.InitializeBehaviors = function( dontReturn )
121{
122        // Set the focus to the editable area when clicking in the document area.
123        // TODO: The cursor must be positioned at the end.
124        this.EditorDocument.attachEvent( 'onmouseup', Doc_OnMouseUp ) ;
125
126        // Intercept pasting operations
127        this.EditorDocument.body.attachEvent( 'onpaste', Doc_OnPaste ) ;
128
129        // Intercept drop operations
130        this.EditorDocument.body.attachEvent( 'ondrop', Doc_OnDrop ) ;
131
132        // Reset the context menu.
133        FCK.ContextMenu._InnerContextMenu.AttachToElement( FCK.EditorDocument.body ) ;
134
135        this.EditorDocument.attachEvent("onkeydown", FCK._KeyDownListener ) ;
136
137        this.EditorDocument.attachEvent("ondblclick", Doc_OnDblClick ) ;
138
139        this.EditorDocument.attachEvent("onbeforedeactivate", function(){ FCKSelection.Save() ; } ) ;
140
141        // Catch cursor selection changes.
142        this.EditorDocument.attachEvent("onselectionchange", Doc_OnSelectionChange ) ;
143
144        FCKTools.AddEventListener( FCK.EditorDocument, 'mousedown', Doc_OnMouseDown ) ;
145}
146
147FCK.InsertHtml = function( html )
148{
149        html = FCKConfig.ProtectedSource.Protect( html ) ;
150        html = FCK.ProtectEvents( html ) ;
151        html = FCK.ProtectUrls( html ) ;
152        html = FCK.ProtectTags( html ) ;
153
154//      FCK.Focus() ;
155        FCKSelection.Restore() ;
156        FCK.EditorWindow.focus() ;
157
158        FCKUndo.SaveUndoStep() ;
159
160        // Gets the actual selection.
161        var oSel = FCKSelection.GetSelection() ;
162
163        // Deletes the actual selection contents.
164        if ( oSel.type.toLowerCase() == 'control' )
165                oSel.clear() ;
166
167        // Using the following trick, any comment in the beginning of the HTML will
168        // be preserved.
169        html = '<span id="__fakeFCKRemove__" style="display:none;">fakeFCKRemove</span>' + html ;
170
171        // Insert the HTML.
172        oSel.createRange().pasteHTML( html ) ;
173
174        // Remove the fake node
175        var fake = FCK.EditorDocument.getElementById('__fakeFCKRemove__') ;
176        // If the span is the only child of a node (so the inserted HTML is beyond that),
177        // remove also that parent that isn't needed. #1537
178        if (fake.parentNode.childNodes.length == 1)
179                fake = fake.parentNode ;
180        fake.removeNode( true ) ;
181
182        FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
183
184        // For some strange reason the SaveUndoStep() call doesn't activate the undo button at the first InsertHtml() call.
185        this.Events.FireEvent( "OnSelectionChange" ) ;
186}
187
188FCK.SetInnerHtml = function( html )             // IE Only
189{
190        var oDoc = FCK.EditorDocument ;
191        // Using the following trick, any comment in the beginning of the HTML will
192        // be preserved.
193        oDoc.body.innerHTML = '<div id="__fakeFCKRemove__">&nbsp;</div>' + html ;
194        oDoc.getElementById('__fakeFCKRemove__').removeNode( true ) ;
195}
196
197function FCK_PreloadImages()
198{
199        var oPreloader = new FCKImagePreloader() ;
200
201        // Add the configured images.
202        oPreloader.AddImages( FCKConfig.PreloadImages ) ;
203
204        // Add the skin icons strip.
205        oPreloader.AddImages( FCKConfig.SkinPath + 'fck_strip.gif' ) ;
206
207        oPreloader.OnComplete = LoadToolbarSetup ;
208        oPreloader.Start() ;
209}
210
211// Disable the context menu in the editor (outside the editing area).
212function Document_OnContextMenu()
213{
214        return ( event.srcElement._FCKShowContextMenu == true ) ;
215}
216document.oncontextmenu = Document_OnContextMenu ;
217
218function FCK_Cleanup()
219{
220        this.LinkedField = null ;
221        this.EditorWindow = null ;
222        this.EditorDocument = null ;
223}
224
225FCK._ExecPaste = function()
226{
227        // As we call ExecuteNamedCommand('Paste'), it would enter in a loop. So, let's use a semaphore.
228        if ( FCK._PasteIsRunning )
229                return true ;
230
231        if ( FCKConfig.ForcePasteAsPlainText )
232        {
233                FCK.PasteAsPlainText() ;
234                return false ;
235        }
236
237        var sHTML = FCK._CheckIsPastingEnabled( true ) ;
238
239        if ( sHTML === false )
240                FCKTools.RunFunction( FCKDialog.OpenDialog, FCKDialog, ['FCKDialog_Paste', FCKLang.Paste, 'dialog/fck_paste.html', 400, 330, 'Security'] ) ;
241        else
242        {
243                if ( FCKConfig.AutoDetectPasteFromWord && sHTML.length > 0 )
244                {
245                        var re = /<\w[^>]*(( class="?MsoNormal"?)|(="mso-))/gi ;
246                        if ( re.test( sHTML ) )
247                        {
248                                if ( confirm( FCKLang.PasteWordConfirm ) )
249                                {
250                                        FCK.PasteFromWord() ;
251                                        return false ;
252                                }
253                        }
254                }
255
256                // Instead of inserting the retrieved HTML, let's leave the OS work for us,
257                // by calling FCK.ExecuteNamedCommand( 'Paste' ). It could give better results.
258
259                // Enable the semaphore to avoid a loop.
260                FCK._PasteIsRunning = true ;
261
262                FCK.ExecuteNamedCommand( 'Paste' ) ;
263
264                // Removes the semaphore.
265                delete FCK._PasteIsRunning ;
266        }
267
268        // Let's always make a custom implementation (return false), otherwise
269        // the new Keyboard Handler may conflict with this code, and the CTRL+V code
270        // could result in a simple "V" being pasted.
271        return false ;
272}
273
274FCK.PasteAsPlainText = function( forceText )
275{
276        if ( !FCK._CheckIsPastingEnabled() )
277        {
278                FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ;
279                return ;
280        }
281
282        // Get the data available in the clipboard in text format.
283        var sText = null ;
284        if ( ! forceText )
285                sText = clipboardData.getData("Text") ;
286        else
287                sText = forceText ;
288
289        if ( sText && sText.length > 0 )
290        {
291                // Replace the carriage returns with <BR>
292                sText = FCKTools.HTMLEncode( sText ) ;
293                sText = FCKTools.ProcessLineBreaks( window, FCKConfig, sText ) ;
294
295                var closeTagIndex = sText.search( '</p>' ) ;
296                var startTagIndex = sText.search( '<p>' ) ;
297
298                if ( ( closeTagIndex != -1 && startTagIndex != -1 && closeTagIndex < startTagIndex )
299                                || ( closeTagIndex != -1 && startTagIndex == -1 ) )
300                {
301                        var prefix = sText.substr( 0, closeTagIndex ) ;
302                        sText = sText.substr( closeTagIndex + 4 ) ;
303                        this.InsertHtml( prefix ) ;
304                }
305
306                // Insert the resulting data in the editor.
307                FCKUndo.SaveLocked = true ;
308                this.InsertHtml( sText ) ;
309                FCKUndo.SaveLocked = false ;
310        }
311}
312
313FCK._CheckIsPastingEnabled = function( returnContents )
314{
315        // The following seams to be the only reliable way to check is script
316        // pasting operations are enabled in the security settings of IE6 and IE7.
317        // It adds a little bit of overhead to the check, but so far that's the
318        // only way, mainly because of IE7.
319
320        FCK._PasteIsEnabled = false ;
321
322        document.body.attachEvent( 'onpaste', FCK_CheckPasting_Listener ) ;
323
324        // The execCommand in GetClipboardHTML will fire the "onpaste", only if the
325        // security settings are enabled.
326        var oReturn = FCK.GetClipboardHTML() ;
327
328        document.body.detachEvent( 'onpaste', FCK_CheckPasting_Listener ) ;
329
330        if ( FCK._PasteIsEnabled )
331        {
332                if ( !returnContents )
333                        oReturn = true ;
334        }
335        else
336                oReturn = false ;
337
338        delete FCK._PasteIsEnabled ;
339
340        return oReturn ;
341}
342
343function FCK_CheckPasting_Listener()
344{
345        FCK._PasteIsEnabled = true ;
346}
347
348FCK.GetClipboardHTML = function()
349{
350        var oDiv = document.getElementById( '___FCKHiddenDiv' ) ;
351
352        if ( !oDiv )
353        {
354                oDiv = document.createElement( 'DIV' ) ;
355                oDiv.id = '___FCKHiddenDiv' ;
356
357                var oDivStyle = oDiv.style ;
358                oDivStyle.position              = 'absolute' ;
359                oDivStyle.visibility    = oDivStyle.overflow    = 'hidden' ;
360                oDivStyle.width                 = oDivStyle.height              = 1 ;
361
362                document.body.appendChild( oDiv ) ;
363        }
364
365        oDiv.innerHTML = '' ;
366
367        var oTextRange = document.body.createTextRange() ;
368        oTextRange.moveToElementText( oDiv ) ;
369        oTextRange.execCommand( 'Paste' ) ;
370
371        var sData = oDiv.innerHTML ;
372        oDiv.innerHTML = '' ;
373
374        return sData ;
375}
376
377FCK.CreateLink = function( url, noUndo )
378{
379        // Creates the array that will be returned. It contains one or more created links (see #220).
380        var aCreatedLinks = new Array() ;
381        var isControl = FCKSelection.GetType() == 'Control' ;
382        var selectedElement = isControl && FCKSelection.GetSelectedElement() ;
383
384        // Remove any existing link in the selection.
385        // IE BUG: Unlinking a floating control selection that is not inside a link
386        // will collapse the selection. (#3677)
387        if ( !( isControl && !FCKTools.GetElementAscensor( selectedElement, 'a' ) ) )
388                FCK.ExecuteNamedCommand( 'Unlink', null, false, !!noUndo ) ;
389
390        if ( url.length > 0 )
391        {
392                // If there are several images, and you try to link each one, all the images get inside the link:
393                // <img><img> -> <a><img></a><img> -> <a><img><img></a> due to the call to 'CreateLink' (bug in IE)
394                if ( isControl )
395                {
396                        // Create a link
397                        var oLink = this.EditorDocument.createElement( 'A' ) ;
398                        oLink.href = url ;
399
400                        // Get the selected object
401                        var oControl = selectedElement ;
402                        // Put the link just before the object
403                        oControl.parentNode.insertBefore(oLink, oControl) ;
404                        // Move the object inside the link
405                        oControl.parentNode.removeChild( oControl ) ;
406                        oLink.appendChild( oControl ) ;
407
408                        return [ oLink ] ;
409                }
410
411                // Generate a temporary name for the link.
412                var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ;
413
414                // Use the internal "CreateLink" command to create the link.
415                FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl, false, !!noUndo ) ;
416
417                // Look for the just create link.
418                var oLinks = this.EditorDocument.links ;
419
420                for ( i = 0 ; i < oLinks.length ; i++ )
421                {
422                        var oLink = oLinks[i] ;
423
424                        // Check it this a newly created link.
425                        // getAttribute must be used. oLink.url may cause problems with IE7 (#555).
426                        if ( oLink.getAttribute( 'href', 2 ) == sTempUrl )
427                        {
428                                var sInnerHtml = oLink.innerHTML ;      // Save the innerHTML (IE changes it if it is like an URL).
429                                oLink.href = url ;
430                                oLink.innerHTML = sInnerHtml ;          // Restore the innerHTML.
431
432                                // If the last child is a <br> move it outside the link or it
433                                // will be too easy to select this link again #388.
434                                var oLastChild = oLink.lastChild ;
435                                if ( oLastChild && oLastChild.nodeName == 'BR' )
436                                {
437                                        // Move the BR after the link.
438                                        FCKDomTools.InsertAfterNode( oLink, oLink.removeChild( oLastChild ) ) ;
439                                }
440
441                                aCreatedLinks.push( oLink ) ;
442                        }
443                }
444        }
445
446        return aCreatedLinks ;
447}
448
449function _FCK_RemoveDisabledAtt()
450{
451        this.removeAttribute( 'disabled' ) ;
452}
453
454function Doc_OnMouseDown( evt )
455{
456        var e = evt.srcElement ;
457
458        // Radio buttons and checkboxes should not be allowed to be triggered in IE
459        // in editable mode. Otherwise the whole browser window may be locked by
460        // the buttons. (#1782)
461        if ( e.nodeName && e.nodeName.IEquals( 'input' ) && e.type.IEquals( ['radio', 'checkbox'] ) && !e.disabled )
462        {
463                e.disabled = true ;
464                FCKTools.SetTimeout( _FCK_RemoveDisabledAtt, 1, e ) ;
465        }
466}
Note: See TracBrowser for help on using the repository browser.