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