source: trunk/expressoMail1_2/js/fckeditor/editor/_source/classes/fckeditingarea.js @ 389

Revision 389, 5.5 KB checked in by niltonneto, 16 years ago (diff)

Ver Tickets no Trac #286 e #287.
Inclusão de template de assinatura padrão.
Assinatura também disponível em formato de texto rico.
Inclusão da biblioteca FCKEditor.

  • Property svn:executable set to *
Line 
1/*
2 * FCKeditor - The text editor for internet
3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
4 *
5 * Licensed under the terms of the GNU Lesser General Public License:
6 *              http://www.opensource.org/licenses/lgpl-license.php
7 *
8 * For further information visit:
9 *              http://www.fckeditor.net/
10 *
11 * "Support Open Source software. What about a donation today?"
12 *
13 * File Name: fckeditingarea.js
14 *      FCKEditingArea Class: renders an editable area.
15 *
16 * File Authors:
17 *              Frederico Caldeira Knabben (fredck@fckeditor.net)
18 */
19
20/**
21 * @constructor
22 * @param {String} targetElement The element that will hold the editing area. Any child element present in the target will be deleted.
23 */
24var FCKEditingArea = function( targetElement )
25{
26        this.TargetElement = targetElement ;
27        this.Mode = FCK_EDITMODE_WYSIWYG ;
28
29        if ( FCK.IECleanup )
30                FCK.IECleanup.AddItem( this, FCKEditingArea_Cleanup ) ;
31}
32
33
34/**
35 * @param {String} html The complete HTML for the page, including DOCTYPE and the <html> tag.
36 */
37FCKEditingArea.prototype.Start = function( html, secondCall )
38{
39        var eTargetElement      = this.TargetElement ;
40        var oTargetDocument     = FCKTools.GetElementDocument( eTargetElement ) ;
41       
42        // Remove all child nodes from the target.
43        while( eTargetElement.childNodes.length > 0 )
44                eTargetElement.removeChild( eTargetElement.childNodes[0] ) ;
45
46        if ( this.Mode == FCK_EDITMODE_WYSIWYG )
47        {
48                if ( FCKBrowserInfo.IsGecko )
49                        html = html.replace( /(<body[^>]*>)\s*(<\/body>)/i, '$1' + GECKO_BOGUS + '$2' ) ;
50       
51                // Create the editing area IFRAME.
52                var oIFrame = this.IFrame = oTargetDocument.createElement( 'iframe' ) ;
53                oIFrame.src = 'javascript:void(0)' ;
54                oIFrame.frameBorder = 0 ;
55                oIFrame.width = oIFrame.height = '100%' ;
56               
57                // Append the new IFRAME to the target.
58                eTargetElement.appendChild( oIFrame ) ;
59               
60                // IE has a bug with the <base> tag... it must have a </base> closer,
61                // otherwise the all sucessive tags will be set as children nodes of the <base>.
62                if ( FCKBrowserInfo.IsIE )
63                        html = html.replace( /(<base[^>]*?)\s*\/?>(?!\s*<\/base>)/gi, '$1></base>' ) ;
64
65                // Get the window and document objects used to interact with the newly created IFRAME.
66                this.Window = oIFrame.contentWindow ;
67               
68                // IE: Avoid JavaScript errors thrown by the editing are source (like tags events).
69                // TODO: This error handler is not being fired.
70                // this.Window.onerror = function() { alert( 'Error!' ) ; return true ; }
71
72                var oDoc = this.Document = this.Window.document ;
73               
74                oDoc.open() ;
75                oDoc.write( html ) ;
76                oDoc.close() ;
77               
78                // Firefox 1.0.x is buggy... ohh yes... so let's do it two times and it
79                // will magicaly work.
80                if ( FCKBrowserInfo.IsGecko10 && !secondCall )
81                {
82                        this.Start( html, true ) ;
83                        return ;
84                }
85               
86                this.Window._FCKEditingArea = this ;
87               
88                // FF 1.0.x is buggy... we must wait a lot to enable editing because
89                // sometimes the content simply disappears, for example when pasting
90                // "bla1!<img src='some_url'>!bla2" in the source and then switching
91                // back to design.
92                if ( FCKBrowserInfo.IsGecko10 )
93                        this.Window.setTimeout( FCKEditingArea_CompleteStart, 500 ) ;
94                else
95                        FCKEditingArea_CompleteStart.call( this.Window ) ;
96        }
97        else
98        {
99                var eTextarea = this.Textarea = oTargetDocument.createElement( 'textarea' ) ;
100                eTextarea.className = 'SourceField' ;
101                eTextarea.dir = 'ltr' ;
102                eTextarea.style.width = eTextarea.style.height = '100%' ;
103                eTextarea.style.border = 'none' ;
104                eTargetElement.appendChild( eTextarea ) ;
105
106                eTextarea.value = html  ;
107
108                // Fire the "OnLoad" event.
109                FCKTools.RunFunction( this.OnLoad ) ;
110        }
111}
112
113// "this" here is FCKEditingArea.Window
114function FCKEditingArea_CompleteStart()
115{
116        // Of Firefox, the DOM takes a little to become available. So we must wait for it in a loop.
117        if ( !this.document.body )
118        {
119                this.setTimeout( FCKEditingArea_CompleteStart, 50 ) ;
120                return ;
121        }
122       
123        var oEditorArea = this._FCKEditingArea ;
124        oEditorArea.MakeEditable() ;
125       
126        // Fire the "OnLoad" event.
127        FCKTools.RunFunction( oEditorArea.OnLoad ) ;
128}
129
130FCKEditingArea.prototype.MakeEditable = function()
131{
132        var oDoc = this.Document ;
133
134        if ( FCKBrowserInfo.IsIE )
135                oDoc.body.contentEditable = true ;
136        else
137        {
138                try
139                {
140                        oDoc.designMode = 'on' ;
141
142                        // Tell Gecko to use or not the <SPAN> tag for the bold, italic and underline.
143                        oDoc.execCommand( 'useCSS', false, !FCKConfig.GeckoUseSPAN ) ;
144
145                        // Analysing Firefox 1.5 source code, it seams that there is support for a
146                        // "insertBrOnReturn" command. Applying it gives no error, but it doesn't
147                        // gives the same behavior that you have with IE. It works only if you are
148                        // already inside a paragraph and it doesn't render correctly in the first enter.
149                        // oDoc.execCommand( 'insertBrOnReturn', false, false ) ;
150
151                        // Tell Gecko (Firefox 1.5+) to enable or not live resizing of objects (by Alfonso Martinez)
152                        oDoc.execCommand( 'enableObjectResizing', false, !FCKConfig.DisableObjectResizing ) ;
153                       
154                        // Disable the standard table editing features of Firefox.
155                        oDoc.execCommand( 'enableInlineTableEditing', false, !FCKConfig.DisableFFTableHandles ) ;
156                }
157                catch (e) {}
158        }
159}
160
161FCKEditingArea.prototype.Focus = function()
162{
163        try
164        {
165                if ( this.Mode == FCK_EDITMODE_WYSIWYG )
166                {
167                        if ( FCKBrowserInfo.IsSafari )
168                                this.IFrame.focus() ;
169                        else
170                                this.Window.focus() ;
171                }
172                else
173                        this.Textarea.focus() ;
174        }
175        catch(e) {}
176}
177
178function FCKEditingArea_Cleanup()
179{
180        this.TargetElement = null ;
181        this.IFrame = null ;
182        this.Document = null ;
183        this.Textarea = null ;
184       
185        if ( this.Window )
186        {
187                this.Window._FCKEditingArea = null ;
188                this.Window = null ;
189        }
190}
Note: See TracBrowser for help on using the repository browser.