be06db87dfb9a87ea07f1d0f2e174d34316c5eb7
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview Contains the second part of the {@link CKEDITOR} object
8 * definition, which defines the basic editor features to be available in
9 * the root ckeditor_basic.js file.
12 if ( CKEDITOR
.status
== 'unloaded' )
16 CKEDITOR
.event
.implementOn( CKEDITOR
);
19 * Forces the full CKEditor core code, in the case only the basic code has been
20 * loaded (ckeditor_basic.js). This method self-destroys (becomes undefined) in
21 * the first call or as soon as the full code is available.
23 * // Check if the full core code has been loaded and load it.
24 * if ( CKEDITOR.loadFullCore )
25 * <b>CKEDITOR.loadFullCore()</b>;
27 CKEDITOR
.loadFullCore = function()
29 // If not the basic code is not ready it, just mark it to be loaded.
30 if ( CKEDITOR
.status
!= 'basic_ready' )
32 CKEDITOR
.loadFullCore
._load
= 1;
36 // Destroy this function.
37 delete CKEDITOR
.loadFullCore
;
39 // Append the script to the head.
40 var script
= document
.createElement( 'script' );
41 script
.type
= 'text/javascript';
42 script
.src
= CKEDITOR
.basePath
+ 'ckeditor.js';
44 document
.getElementsByTagName( 'head' )[0].appendChild( script
);
48 * The time to wait (in seconds) to load the full editor code after the
49 * page load, if the "ckeditor_basic" file is used. If set to zero, the
50 * editor is loaded on demand, as soon as an instance is created.
52 * This value must be set on the page before the page load completion.
56 * // Loads the full source after five seconds.
57 * CKEDITOR.loadFullCoreTimeout = 5;
59 CKEDITOR
.loadFullCoreTimeout
= 0;
62 * The class name used to identify <textarea> elements to be replace
63 * by CKEditor instances.
67 * <b>CKEDITOR.replaceClass</b> = 'rich_editor';
69 CKEDITOR
.replaceClass
= 'ckeditor';
72 * Enables the replacement of all textareas with class name matching
73 * {@link CKEDITOR.replaceClass}.
77 * // Disable the auto-replace feature.
78 * <b>CKEDITOR.replaceByClassEnabled</b> = false;
80 CKEDITOR
.replaceByClassEnabled
= 1;
82 var createInstance = function( elementOrIdOrName
, config
, creationFunction
, data
)
84 if ( CKEDITOR
.env
.isCompatible
)
86 // Load the full core.
87 if ( CKEDITOR
.loadFullCore
)
88 CKEDITOR
.loadFullCore();
90 var editor
= creationFunction( elementOrIdOrName
, config
, data
);
91 CKEDITOR
.add( editor
);
99 * Replaces a <textarea> or a DOM element (DIV) with a CKEditor
100 * instance. For textareas, the initial value in the editor will be the
101 * textarea value. For DOM elements, their innerHTML will be used
102 * instead. We recommend using TEXTAREA and DIV elements only.
103 * @param {Object|String} elementOrIdOrName The DOM element (textarea), its
105 * @param {Object} [config] The specific configurations to apply to this
106 * editor instance. Configurations set here will override global CKEditor
108 * @returns {CKEDITOR.editor} The editor instance created.
110 * <textarea id="myfield" name="myfield"><:/textarea>
112 * <b>CKEDITOR.replace( 'myfield' )</b>;
114 * var textarea = document.body.appendChild( document.createElement( 'textarea' ) );
115 * <b>CKEDITOR.replace( textarea )</b>;
117 CKEDITOR
.replace = function( elementOrIdOrName
, config
)
119 return createInstance( elementOrIdOrName
, config
, CKEDITOR
.editor
.replace
);
123 * Creates a new editor instance inside a specific DOM element.
124 * @param {Object|String} elementOrId The DOM element or its ID.
125 * @param {Object} [config] The specific configurations to apply to this
126 * editor instance. Configurations set here will override global CKEditor
128 * @param {String} [data] Since 3.3. Initial value for the instance.
129 * @returns {CKEDITOR.editor} The editor instance created.
131 * <div id="editorSpace"><:/div>
133 * <b>CKEDITOR.appendTo( 'editorSpace' )</b>;
135 CKEDITOR
.appendTo = function( elementOrId
, config
, data
)
137 return createInstance( elementOrId
, config
, CKEDITOR
.editor
.appendTo
, data
);
140 // Documented at ckeditor.js.
141 CKEDITOR
.add = function( editor
)
143 // For now, just put the editor in the pending list. It will be
144 // processed as soon as the full code gets loaded.
145 var pending
= this._
.pending
|| ( this._
.pending
= [] );
146 pending
.push( editor
);
150 * Replace all <textarea> elements available in the document with
153 * // Replace all <textarea> elements in the page.
154 * CKEDITOR.replaceAll();
156 * // Replace all <textarea class="myClassName"> elements in the page.
157 * CKEDITOR.replaceAll( 'myClassName' );
159 * // Selectively replace <textarea> elements, based on custom assertions.
160 * CKEDITOR.replaceAll( function( textarea, config )
162 * // Custom code to evaluate the replace, returning false
163 * // if it must not be done.
164 * // It also passes the "config" parameter, so the
165 * // developer can customize the instance.
168 CKEDITOR
.replaceAll = function()
170 var textareas
= document
.getElementsByTagName( 'textarea' );
172 for ( var i
= 0 ; i
< textareas
.length
; i
++ )
175 textarea
= textareas
[i
];
177 // The "name" and/or "id" attribute must exist.
178 if ( !textarea
.name
&& !textarea
.id
)
181 if ( typeof arguments
[0] == 'string' )
183 // The textarea class name could be passed as the function
186 var classRegex
= new RegExp( '(?:^|\\s)' + arguments
[0] + '(?:$|\\s)' );
188 if ( !classRegex
.test( textarea
.className
) )
191 else if ( typeof arguments
[0] == 'function' )
193 // An assertion function could be passed as the function parameter.
194 // It must explicitly return "false" to ignore a specific <textarea>.
196 if ( arguments
[0]( textarea
, config
) === false )
200 this.replace( textarea
, config
);
206 var onload = function()
208 var loadFullCore
= CKEDITOR
.loadFullCore
,
209 loadFullCoreTimeout
= CKEDITOR
.loadFullCoreTimeout
;
211 // Replace all textareas with the default class name.
212 if ( CKEDITOR
.replaceByClassEnabled
)
213 CKEDITOR
.replaceAll( CKEDITOR
.replaceClass
);
215 CKEDITOR
.status
= 'basic_ready';
217 if ( loadFullCore
&& loadFullCore
._load
)
219 else if ( loadFullCoreTimeout
)
221 setTimeout( function()
223 if ( CKEDITOR
.loadFullCore
)
224 CKEDITOR
.loadFullCore();
226 , loadFullCoreTimeout
* 1000 );
230 if ( window
.addEventListener
)
231 window
.addEventListener( 'load', onload
, false );
232 else if ( window
.attachEvent
)
233 window
.attachEvent( 'onload', onload
);
236 CKEDITOR
.status
= 'basic_loaded';