[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 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.
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | if ( CKEDITOR.status == 'unloaded' )
|
---|
| 13 | {
|
---|
| 14 | (function()
|
---|
| 15 | {
|
---|
| 16 | CKEDITOR.event.implementOn( CKEDITOR );
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 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.
|
---|
| 22 | * @example
|
---|
| 23 | * // Check if the full core code has been loaded and load it.
|
---|
| 24 | * if ( CKEDITOR.loadFullCore )
|
---|
| 25 | * <b>CKEDITOR.loadFullCore()</b>;
|
---|
| 26 | */
|
---|
| 27 | CKEDITOR.loadFullCore = function()
|
---|
| 28 | {
|
---|
| 29 | // If not the basic code is not ready it, just mark it to be loaded.
|
---|
| 30 | if ( CKEDITOR.status != 'basic_ready' )
|
---|
| 31 | {
|
---|
| 32 | CKEDITOR.loadFullCore._load = true;
|
---|
| 33 | return;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | // Destroy this function.
|
---|
| 37 | delete CKEDITOR.loadFullCore;
|
---|
| 38 |
|
---|
| 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';
|
---|
| 43 |
|
---|
| 44 | document.getElementsByTagName( 'head' )[0].appendChild( script );
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 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.
|
---|
| 51 | *
|
---|
| 52 | * This value must be set on the page before the page load completion.
|
---|
| 53 | * @type Number
|
---|
| 54 | * @default 0 (zero)
|
---|
| 55 | * @example
|
---|
| 56 | * // Loads the full source after five seconds.
|
---|
| 57 | * CKEDITOR.loadFullCoreTimeout = 5;
|
---|
| 58 | */
|
---|
| 59 | CKEDITOR.loadFullCoreTimeout = 0;
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * The class name used to identify <textarea> elements to be replace
|
---|
| 63 | * by CKEditor instances.
|
---|
| 64 | * @type String
|
---|
| 65 | * @default 'ckeditor'
|
---|
| 66 | * @example
|
---|
| 67 | * <b>CKEDITOR.replaceClass</b> = 'rich_editor';
|
---|
| 68 | */
|
---|
| 69 | CKEDITOR.replaceClass = 'ckeditor';
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
| 72 | * Enables the replacement of all textareas with class name matching
|
---|
| 73 | * {@link CKEDITOR.replaceClass}.
|
---|
| 74 | * @type Boolean
|
---|
| 75 | * @default true
|
---|
| 76 | * @example
|
---|
| 77 | * // Disable the auto-replace feature.
|
---|
| 78 | * <b>CKEDITOR.replaceByClassEnabled</b> = false;
|
---|
| 79 | */
|
---|
| 80 | CKEDITOR.replaceByClassEnabled = true;
|
---|
| 81 |
|
---|
| 82 | var createInstance = function( elementOrIdOrName, config, creationFunction, data )
|
---|
| 83 | {
|
---|
| 84 | if ( CKEDITOR.env.isCompatible )
|
---|
| 85 | {
|
---|
| 86 | // Load the full core.
|
---|
| 87 | if ( CKEDITOR.loadFullCore )
|
---|
| 88 | CKEDITOR.loadFullCore();
|
---|
| 89 |
|
---|
| 90 | var editor = creationFunction( elementOrIdOrName, config, data );
|
---|
| 91 | CKEDITOR.add( editor );
|
---|
| 92 | return editor;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | return null;
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 | /**
|
---|
| 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
|
---|
| 104 | * ID or name.
|
---|
| 105 | * @param {Object} [config] The specific configurations to apply to this
|
---|
| 106 | * editor instance. Configurations set here will override global CKEditor
|
---|
| 107 | * settings.
|
---|
| 108 | * @returns {CKEDITOR.editor} The editor instance created.
|
---|
| 109 | * @example
|
---|
| 110 | * <textarea id="myfield" name="myfield"><:/textarea>
|
---|
| 111 | * ...
|
---|
| 112 | * <b>CKEDITOR.replace( 'myfield' )</b>;
|
---|
| 113 | * @example
|
---|
| 114 | * var textarea = document.body.appendChild( document.createElement( 'textarea' ) );
|
---|
| 115 | * <b>CKEDITOR.replace( textarea )</b>;
|
---|
| 116 | */
|
---|
| 117 | CKEDITOR.replace = function( elementOrIdOrName, config )
|
---|
| 118 | {
|
---|
| 119 | return createInstance( elementOrIdOrName, config, CKEDITOR.editor.replace );
|
---|
| 120 | };
|
---|
| 121 |
|
---|
| 122 | /**
|
---|
| 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
|
---|
| 127 | * settings.
|
---|
| 128 | * @param {String} [data] Since 3.3. Initial value for the instance.
|
---|
| 129 | * @returns {CKEDITOR.editor} The editor instance created.
|
---|
| 130 | * @example
|
---|
| 131 | * <div id="editorSpace"><:/div>
|
---|
| 132 | * ...
|
---|
| 133 | * <b>CKEDITOR.appendTo( 'editorSpace' )</b>;
|
---|
| 134 | */
|
---|
| 135 | CKEDITOR.appendTo = function( elementOrId, config, data )
|
---|
| 136 | {
|
---|
| 137 | return createInstance( elementOrId, config, CKEDITOR.editor.appendTo, data );
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * @ignore
|
---|
| 142 | * Documented at ckeditor.js.
|
---|
| 143 | */
|
---|
| 144 | CKEDITOR.add = function( editor )
|
---|
| 145 | {
|
---|
| 146 | // For now, just put the editor in the pending list. It will be
|
---|
| 147 | // processed as soon as the full code gets loaded.
|
---|
| 148 | var pending = this._.pending || ( this._.pending = [] );
|
---|
| 149 | pending.push( editor );
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 | /**
|
---|
| 153 | * Replace all <textarea> elements available in the document with
|
---|
| 154 | * editor instances.
|
---|
| 155 | * @example
|
---|
| 156 | * // Replace all <textarea> elements in the page.
|
---|
| 157 | * CKEDITOR.replaceAll();
|
---|
| 158 | * @example
|
---|
| 159 | * // Replace all <textarea class="myClassName"> elements in the page.
|
---|
| 160 | * CKEDITOR.replaceAll( 'myClassName' );
|
---|
| 161 | * @example
|
---|
| 162 | * // Selectively replace <textarea> elements, based on custom assertions.
|
---|
| 163 | * CKEDITOR.replaceAll( function( textarea, config )
|
---|
| 164 | * {
|
---|
| 165 | * // Custom code to evaluate the replace, returning false
|
---|
| 166 | * // if it must not be done.
|
---|
| 167 | * // It also passes the "config" parameter, so the
|
---|
| 168 | * // developer can customize the instance.
|
---|
| 169 | * } );
|
---|
| 170 | */
|
---|
| 171 | CKEDITOR.replaceAll = function()
|
---|
| 172 | {
|
---|
| 173 | var textareas = document.getElementsByTagName( 'textarea' );
|
---|
| 174 |
|
---|
| 175 | for ( var i = 0 ; i < textareas.length ; i++ )
|
---|
| 176 | {
|
---|
| 177 | var config = null;
|
---|
| 178 | var textarea = textareas[i];
|
---|
| 179 | var name = textarea.name;
|
---|
| 180 |
|
---|
| 181 | // The "name" and/or "id" attribute must exist.
|
---|
| 182 | if ( !textarea.name && !textarea.id )
|
---|
| 183 | continue;
|
---|
| 184 |
|
---|
| 185 | if ( typeof arguments[0] == 'string' )
|
---|
| 186 | {
|
---|
| 187 | // The textarea class name could be passed as the function
|
---|
| 188 | // parameter.
|
---|
| 189 |
|
---|
| 190 | var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' );
|
---|
| 191 |
|
---|
| 192 | if ( !classRegex.test( textarea.className ) )
|
---|
| 193 | continue;
|
---|
| 194 | }
|
---|
| 195 | else if ( typeof arguments[0] == 'function' )
|
---|
| 196 | {
|
---|
| 197 | // An assertion function could be passed as the function parameter.
|
---|
| 198 | // It must explicitly return "false" to ignore a specific <textarea>.
|
---|
| 199 | config = {};
|
---|
| 200 | if ( arguments[0]( textarea, config ) === false )
|
---|
| 201 | continue;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | this.replace( textarea, config );
|
---|
| 205 | }
|
---|
| 206 | };
|
---|
| 207 |
|
---|
| 208 | (function()
|
---|
| 209 | {
|
---|
| 210 | var onload = function()
|
---|
| 211 | {
|
---|
| 212 | var loadFullCore = CKEDITOR.loadFullCore,
|
---|
| 213 | loadFullCoreTimeout = CKEDITOR.loadFullCoreTimeout;
|
---|
| 214 |
|
---|
| 215 | // Replace all textareas with the default class name.
|
---|
| 216 | if ( CKEDITOR.replaceByClassEnabled )
|
---|
| 217 | CKEDITOR.replaceAll( CKEDITOR.replaceClass );
|
---|
| 218 |
|
---|
| 219 | CKEDITOR.status = 'basic_ready';
|
---|
| 220 |
|
---|
| 221 | if ( loadFullCore && loadFullCore._load )
|
---|
| 222 | loadFullCore();
|
---|
| 223 | else if ( loadFullCoreTimeout )
|
---|
| 224 | {
|
---|
| 225 | setTimeout( function()
|
---|
| 226 | {
|
---|
| 227 | if ( CKEDITOR.loadFullCore )
|
---|
| 228 | CKEDITOR.loadFullCore();
|
---|
| 229 | }
|
---|
| 230 | , loadFullCoreTimeout * 1000 );
|
---|
| 231 | }
|
---|
| 232 | };
|
---|
| 233 |
|
---|
| 234 | if ( window.addEventListener )
|
---|
| 235 | window.addEventListener( 'load', onload, false );
|
---|
| 236 | else if ( window.attachEvent )
|
---|
| 237 | window.attachEvent( 'onload', onload );
|
---|
| 238 | })();
|
---|
| 239 |
|
---|
| 240 | CKEDITOR.status = 'basic_loaded';
|
---|
| 241 | })();
|
---|
| 242 | }
|
---|