source: trunk/phpgwapi/js/ckeditor/_source/core/editor_basic.js @ 2862

Revision 2862, 5.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #663 - Atualizando e centralizando o CKEditor (v. 3.2.1)

Line 
1/*
2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6if ( !CKEDITOR.editor )
7{
8        /**
9         * No element is linked to the editor instance.
10         * @constant
11         * @example
12         */
13        CKEDITOR.ELEMENT_MODE_NONE = 0;
14
15        /**
16         * The element is to be replaced by the editor instance.
17         * @constant
18         * @example
19         */
20        CKEDITOR.ELEMENT_MODE_REPLACE = 1;
21
22        /**
23         * The editor is to be created inside the element.
24         * @constant
25         * @example
26         */
27        CKEDITOR.ELEMENT_MODE_APPENDTO = 2;
28
29        /**
30         * Represents an editor instance. This constructor should be rarely used,
31         * being the {@link CKEDITOR} methods preferible.
32         * @constructor
33         * @param {Object} instanceConfig Configuration values for this specific
34         *              instance.
35         * @param {CKEDITOR.dom.element} [element] The element linked to this
36         *              instance.
37         * @param {Number} [mode] The mode in which the element is linked to this
38         *              instance.
39         * @param {String} [data] Since 3.3. Initial value for the instance.
40         * @augments CKEDITOR.event
41         * @example
42         */
43        CKEDITOR.editor = function( instanceConfig, element, mode, data )
44        {
45                this._ =
46                {
47                        // Save the config to be processed later by the full core code.
48                        instanceConfig : instanceConfig,
49                        element : element,
50                        data : data
51                };
52
53                /**
54                 * The mode in which the {@link #element} is linked to this editor
55                 * instance. It can be any of the following values:
56                 * <ul>
57                 * <li><b>CKEDITOR.ELEMENT_MODE_NONE</b>: No element is linked to the
58                 *              editor instance.</li>
59                 * <li><b>CKEDITOR.ELEMENT_MODE_REPLACE</b>: The element is to be
60                 *              replaced by the editor instance.</li>
61                 * <li><b>CKEDITOR.ELEMENT_MODE_APPENDTO</b>: The editor is to be
62                 *              created inside the element.</li>
63                 * </ul>
64                 * @name CKEDITOR.editor.prototype.elementMode
65                 * @type Number
66                 * @example
67                 * var editor = CKEDITOR.replace( 'editor1' );
68                 * alert( <b>editor.elementMode</b> );  "1"
69                 */
70                this.elementMode = mode || CKEDITOR.ELEMENT_MODE_NONE;
71
72                // Call the CKEDITOR.event constructor to initialize this instance.
73                CKEDITOR.event.call( this );
74
75                this._init();
76        };
77
78        /**
79         * Replaces a &lt;textarea&gt; or a DOM element (DIV) with a CKEditor
80         * instance. For textareas, the initial value in the editor will be the
81         * textarea value. For DOM elements, their innerHTML will be used
82         * instead. We recommend using TEXTAREA and DIV elements only. Do not use
83         * this function directly. Use {@link CKEDITOR.replace} instead.
84         * @param {Object|String} elementOrIdOrName The DOM element (textarea), its
85         *              ID or name.
86         * @param {Object} [config] The specific configurations to apply to this
87         *              editor instance. Configurations set here will override global CKEditor
88         *              settings.
89         * @returns {CKEDITOR.editor} The editor instance created.
90         * @example
91         */
92        CKEDITOR.editor.replace = function( elementOrIdOrName, config )
93        {
94                var element = elementOrIdOrName;
95
96                if ( typeof element != 'object' )
97                {
98                        // Look for the element by id. We accept any kind of element here.
99                        element = document.getElementById( elementOrIdOrName );
100
101                        // If not found, look for elements by name. In this case we accept only
102                        // textareas.
103                        if ( !element )
104                        {
105                                var i = 0,
106                                        textareasByName = document.getElementsByName( elementOrIdOrName );
107
108                                while ( ( element = textareasByName[ i++ ] ) && element.tagName.toLowerCase() != 'textarea' )
109                                { /*jsl:pass*/ }
110                        }
111
112                        if ( !element )
113                                throw '[CKEDITOR.editor.replace] The element with id or name "' + elementOrIdOrName + '" was not found.';
114                }
115
116                // Do not replace the textarea right now, just hide it. The effective
117                // replacement will be done by the _init function.
118                element.style.visibility = 'hidden';
119
120                // Create the editor instance.
121                return new CKEDITOR.editor( config, element, CKEDITOR.ELEMENT_MODE_REPLACE );
122        };
123
124        /**
125         * Creates a new editor instance inside a specific DOM element. Do not use
126         * this function directly. Use {@link CKEDITOR.appendTo} instead.
127         * @param {Object|String} elementOrId The DOM element or its ID.
128         * @param {Object} [config] The specific configurations to apply to this
129         *              editor instance. Configurations set here will override global CKEditor
130         *              settings.
131         * @param {String} [data] Since 3.3. Initial value for the instance.
132         * @returns {CKEDITOR.editor} The editor instance created.
133         * @example
134         */
135        CKEDITOR.editor.appendTo = function( elementOrId, config, data )
136        {
137                var element = elementOrId;
138                if ( typeof element != 'object' )
139                {
140                        element = document.getElementById( elementOrId );
141
142                        if ( !element )
143                                throw '[CKEDITOR.editor.appendTo] The element with id "' + elementOrId + '" was not found.';
144                }
145
146                // Create the editor instance.
147                return new CKEDITOR.editor( config, element, CKEDITOR.ELEMENT_MODE_APPENDTO, data );
148        };
149
150        CKEDITOR.editor.prototype =
151        {
152                /**
153                 * Initializes the editor instance. This function will be overriden by the
154                 * full CKEDITOR.editor implementation (editor.js).
155                 * @private
156                 */
157                _init : function()
158                {
159                        var pending = CKEDITOR.editor._pending || ( CKEDITOR.editor._pending = [] );
160                        pending.push( this );
161                },
162
163                // Both fire and fireOnce will always pass this editor instance as the
164                // "editor" param in CKEDITOR.event.fire. So, we override it to do that
165                // automaticaly.
166
167                /** @ignore */
168                fire : function( eventName, data )
169                {
170                        return CKEDITOR.event.prototype.fire.call( this, eventName, data, this );
171                },
172
173                /** @ignore */
174                fireOnce : function( eventName, data )
175                {
176                        return CKEDITOR.event.prototype.fireOnce.call( this, eventName, data, this );
177                }
178        };
179
180        // "Inherit" (copy actually) from CKEDITOR.event.
181        CKEDITOR.event.implementOn( CKEDITOR.editor.prototype, true );
182}
Note: See TracBrowser for help on using the repository browser.