1 /* 2 * CKEditor - The text editor for Internet - http://ckeditor.com 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 */ 21 22 /** 23 * @fileOverview Contains the second part of the {@link CKEDITOR} object 24 * definition, which defines the basic editor features to be available in 25 * the root ckeditor_basic.js file. 26 */ 27 28 if ( CKEDITOR.status == 'unloaded' ) 29 { 30 CKEDITOR.event.implementOn( CKEDITOR ); 31 32 /** 33 * Forces the full CKEditor core code, in the case only the basic code has been 34 * loaded (ckeditor_basic.js). This method self-destroys (becomes undefined) in 35 * the first call or as soon as the full code is available. 36 * @type undefined 37 * @example 38 * // Check if the full core code has been loaded and load it. 39 * if ( CKEDITOR.loadFullCore ) 40 * <b>CKEDITOR.loadFullCore()</b>; 41 */ 42 CKEDITOR.loadFullCore = function() 43 { 44 delete CKEDITOR.loadFullCore; 45 46 var script = document.createElement( 'script' ); 47 script.type = 'text/javascript'; 48 script.src = CKEDITOR.basePath + 'ckeditor.js'; 49 script.src = CKEDITOR.basePath + 'ckeditor_source.js'; // @Packager.RemoveLine 50 51 document.getElementsByTagName( 'head' )[0].appendChild( script ); 52 }; 53 54 /** 55 * The class name used to identify <textarea> elements to be replace 56 * by CKEditor instances. 57 * @type string 58 * @default 'ckeditor' 59 * @example 60 * <b>CKEDITOR.replaceClass</b> = 'rich_editor'; 61 */ 62 CKEDITOR.replaceClass = 'ckeditor'; 63 64 /** 65 * Enables the replacement of all textareas with class name matching 66 * {@link CKEDITOR.replaceClass}. 67 * @type Boolean 68 * @default true 69 * @example 70 * // Disable the auto-replace feature. 71 * <b>CKEDITOR.replaceByClassEnabled</b> = false; 72 */ 73 CKEDITOR.replaceByClassEnabled = true; 74 75 /** 76 * Replaces a specific <textarea> with a CKEditor instance. 77 * @param {object|string} elementOrIdOrName The DOM element (textarea), its 78 * ID or name. 79 * @param {Object} [config] The specific configurations to apply to this 80 * editor instance. Configurations set here will override global CKEditor 81 * settings. 82 * @type undefined 83 * @example 84 * <textarea id="myfield" name="myfield"><:/textarea> 85 * ... 86 * <b>CKEDITOR.replace( 'myfield' )</b>; 87 * @example 88 * var textarea = document.body.appendChild( document.createElement( 'textarea' ) ); 89 * <b>CKEDITOR.replace( textarea )</b>; 90 */ 91 CKEDITOR.replace = function( elementOrIdOrName, config ) 92 { 93 if ( CKEDITOR.env.isCompatible ) 94 { 95 var textarea = elementOrIdOrName; 96 97 if ( typeof textarea != 'object' ) 98 { 99 // First look for the element id, then the name. 100 var i = 0; 101 var textareasByName = document.getElementsByName( elementOrIdOrName ); 102 textarea = document.getElementById( elementOrIdOrName ) || textareasByName[ i++ ]; 103 104 while ( textarea ) 105 { 106 if ( textarea.tagName.toLowerCase() == 'textarea' ) 107 break; 108 textarea = textareasByName[ i++ ]; 109 } 110 111 if ( !textarea ) 112 throw '[CKEDITOR.replace] The <textarea> with id or name "' + elementOrIdOrName + '" was not found.'; 113 } 114 115 CKEDITOR.replace._replaceElement( textarea, config ); 116 } 117 }; 118 119 // This function will be overwritten by the full core code implementation. 120 CKEDITOR.replace._replaceElement = function( textarea, config ) 121 { 122 // Do not replace the textarea right now, just hide it. the 123 // effective replacement will be done by the full core code. 124 textarea.style.visibility = 'hidden'; 125 126 // Push the textarea in the array of pending replacements. 127 var pending = CKEDITOR.replace._pending || ( CKEDITOR.replace._pending = [] ); 128 pending.push( [ textarea, config ] ); 129 130 // Check if it is time to load the full core code. 131 if ( CKEDITOR.loadFullCore && CKEDITOR.status == 'basic_ready' ) 132 CKEDITOR.loadFullCore(); 133 }; 134 135 /** 136 * Replace all <textarea> elements available in the document with 137 * editor instances. 138 * @type undefined 139 * @example 140 * // Replace all <textarea> elements in the page. 141 * CKEDITOR.replaceAll(); 142 * @example 143 * // Replace all <textarea class="myClassName"> elements in the page. 144 * CKEDITOR.replaceAll( 'myClassName' ); 145 * @example 146 * // Selectively replace <textarea> elements, based on custom assertions. 147 * CKEDITOR.replaceAll( function( textarea, config ) 148 * { 149 * // Custom code to evaluate the replace, returning false 150 * // if it must not be done. 151 * // It also passes the "config" parameter, so the 152 * // developer can customize the instance. 153 * } ); 154 */ 155 CKEDITOR.replaceAll = function() 156 { 157 var textareas = document.getElementsByTagName( 'textarea' ); 158 159 for ( var i = 0 ; i < textareas.length ; i++ ) 160 { 161 var config = null; 162 var textarea = textareas[i]; 163 var name = textarea.name; 164 165 // The "name" and/or "id" attribute must exist. 166 if ( !textarea.name && !textarea.id ) 167 continue; 168 169 if ( typeof arguments[0] == 'string' ) 170 { 171 // The textarea class name could be passed as the function 172 // parameter. 173 174 var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ); 175 176 if ( !classRegex.test( textarea.className ) ) 177 continue; 178 } 179 else if ( typeof arguments[0] == 'function' ) 180 { 181 // An assertion function could be passed as the function parameter. 182 // It must explicitly return "false" to ignore a specific <textarea>. 183 config = {}; 184 if ( arguments[0]( textarea, config ) === false ) 185 continue; 186 } 187 188 this.replace( textarea, config ); 189 } 190 }; 191 192 (function() 193 { 194 var onload = function() 195 { 196 // Replace all textareas with the default class name. 197 if ( CKEDITOR.replaceByClassEnabled ) 198 CKEDITOR.replaceAll( CKEDITOR.replaceClass ); 199 200 if ( CKEDITOR.status == 'basic_loaded' ) 201 { 202 if ( CKEDITOR.replace._pending && CKEDITOR.loadFullCore ) 203 CKEDITOR.loadFullCore(); 204 205 CKEDITOR.status = 'basic_ready'; 206 } 207 }; 208 209 if ( window.addEventListener ) 210 window.addEventListener( 'load', onload, false ); 211 else if ( window.attachEvent ) 212 window.attachEvent( 'onload', onload ); 213 })(); 214 215 CKEDITOR.status = 'basic_loaded'; 216 } 217