8d109c82de9524df7dca1dbbcabf4787ca792353
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 if ( !CKEDITOR
.editor
)
9 * No element is linked to the editor instance.
13 CKEDITOR
.ELEMENT_MODE_NONE
= 0;
16 * The element is to be replaced by the editor instance.
20 CKEDITOR
.ELEMENT_MODE_REPLACE
= 1;
23 * The editor is to be created inside the element.
27 CKEDITOR
.ELEMENT_MODE_APPENDTO
= 2;
30 * Creates an editor class instance. This constructor should be rarely
31 * used, in favor of the {@link CKEDITOR} editor creation functions.
32 * @ class Represents an editor instance.
33 * @param {Object} instanceConfig Configuration values for this specific
35 * @param {CKEDITOR.dom.element} [element] The element linked to this
37 * @param {Number} [mode] The mode in which the element is linked to this
38 * instance. See {@link #elementMode}.
39 * @param {String} [data] Since 3.3. Initial value for the instance.
40 * @augments CKEDITOR.event
43 CKEDITOR
.editor = function( instanceConfig
, element
, mode
, data
)
47 // Save the config to be processed later by the full core code.
48 instanceConfig
: instanceConfig
,
54 * The mode in which the {@link #element} is linked to this editor
55 * instance. It can be any of the following values:
57 * <li>{@link CKEDITOR.ELEMENT_MODE_NONE}: No element is linked to the
58 * editor instance.</li>
59 * <li>{@link CKEDITOR.ELEMENT_MODE_REPLACE}: The element is to be
60 * replaced by the editor instance.</li>
61 * <li>{@link CKEDITOR.ELEMENT_MODE_APPENDTO}: The editor is to be
62 * created inside the element.</li>
64 * @name CKEDITOR.editor.prototype.elementMode
67 * var editor = CKEDITOR.replace( 'editor1' );
68 * alert( <b>editor.elementMode</b> ); "1"
70 this.elementMode
= mode
|| CKEDITOR
.ELEMENT_MODE_NONE
;
72 // Call the CKEDITOR.event constructor to initialize this instance.
73 CKEDITOR
.event
.call( this );
79 * Replaces a <textarea> 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
86 * @param {Object} [config] The specific configurations to apply to this
87 * editor instance. Configurations set here will override global CKEditor
89 * @returns {CKEDITOR.editor} The editor instance created.
92 CKEDITOR
.editor
.replace = function( elementOrIdOrName
, config
)
94 var element
= elementOrIdOrName
;
96 if ( typeof element
!= 'object' )
98 // Look for the element by id. We accept any kind of element here.
99 element
= document
.getElementById( elementOrIdOrName
);
101 // Elements that should go into head are unacceptable (#6791).
102 if ( element
&& element
.tagName
.toLowerCase() in {style
:1,script
:1,base
:1,link
:1,meta
:1,title
:1} )
105 // If not found, look for elements by name. In this case we accept only
110 textareasByName
= document
.getElementsByName( elementOrIdOrName
);
112 while ( ( element
= textareasByName
[ i
++ ] ) && element
.tagName
.toLowerCase() != 'textarea' )
117 throw '[CKEDITOR.editor.replace] The element with id or name "' + elementOrIdOrName
+ '" was not found.';
120 // Do not replace the textarea right now, just hide it. The effective
121 // replacement will be done by the _init function.
122 element
.style
.visibility
= 'hidden';
124 // Create the editor instance.
125 return new CKEDITOR
.editor( config
, element
, CKEDITOR
.ELEMENT_MODE_REPLACE
);
129 * Creates a new editor instance inside a specific DOM element. Do not use
130 * this function directly. Use {@link CKEDITOR.appendTo} instead.
131 * @param {Object|String} elementOrId The DOM element or its ID.
132 * @param {Object} [config] The specific configurations to apply to this
133 * editor instance. Configurations set here will override global CKEditor
135 * @param {String} [data] Since 3.3. Initial value for the instance.
136 * @returns {CKEDITOR.editor} The editor instance created.
139 CKEDITOR
.editor
.appendTo = function( elementOrId
, config
, data
)
141 var element
= elementOrId
;
142 if ( typeof element
!= 'object' )
144 element
= document
.getElementById( elementOrId
);
147 throw '[CKEDITOR.editor.appendTo] The element with id "' + elementOrId
+ '" was not found.';
150 // Create the editor instance.
151 return new CKEDITOR
.editor( config
, element
, CKEDITOR
.ELEMENT_MODE_APPENDTO
, data
);
154 CKEDITOR
.editor
.prototype =
157 * Initializes the editor instance. This function will be overriden by the
158 * full CKEDITOR.editor implementation (editor.js).
163 var pending
= CKEDITOR
.editor
._pending
|| ( CKEDITOR
.editor
._pending
= [] );
164 pending
.push( this );
167 // Both fire and fireOnce will always pass this editor instance as the
168 // "editor" param in CKEDITOR.event.fire. So, we override it to do that
172 fire : function( eventName
, data
)
174 return CKEDITOR
.event
.prototype.fire
.call( this, eventName
, data
, this );
178 fireOnce : function( eventName
, data
)
180 return CKEDITOR
.event
.prototype.fireOnce
.call( this, eventName
, data
, this );
184 // "Inherit" (copy actually) from CKEDITOR.event.
185 CKEDITOR
.event
.implementOn( CKEDITOR
.editor
.prototype, true );