ckeditor_basic.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. /**
  6. * @fileOverview Contains the second part of the {@link CKEDITOR} object
  7. * definition, which defines the basic editor features to be available in
  8. * the root ckeditor_basic.js file.
  9. */
  10. if ( CKEDITOR.status == 'unloaded' )
  11. {
  12. (function()
  13. {
  14. CKEDITOR.event.implementOn( CKEDITOR );
  15. /**
  16. * Forces the full CKEditor core code, in the case only the basic code has been
  17. * loaded (ckeditor_basic.js). This method self-destroys (becomes undefined) in
  18. * the first call or as soon as the full code is available.
  19. * @example
  20. * // Check if the full core code has been loaded and load it.
  21. * if ( CKEDITOR.loadFullCore )
  22. * <b>CKEDITOR.loadFullCore()</b>;
  23. */
  24. CKEDITOR.loadFullCore = function()
  25. {
  26. // If not the basic code is not ready it, just mark it to be loaded.
  27. if ( CKEDITOR.status != 'basic_ready' )
  28. {
  29. CKEDITOR.loadFullCore._load = 1;
  30. return;
  31. }
  32. // Destroy this function.
  33. delete CKEDITOR.loadFullCore;
  34. // Append the script to the head.
  35. var script = document.createElement( 'script' );
  36. script.type = 'text/javascript';
  37. script.src = CKEDITOR.basePath + 'ckeditor.js';
  38. document.getElementsByTagName( 'head' )[0].appendChild( script );
  39. };
  40. /**
  41. * The time to wait (in seconds) to load the full editor code after the
  42. * page load, if the "ckeditor_basic" file is used. If set to zero, the
  43. * editor is loaded on demand, as soon as an instance is created.
  44. *
  45. * This value must be set on the page before the page load completion.
  46. * @type Number
  47. * @default 0 (zero)
  48. * @example
  49. * // Loads the full source after five seconds.
  50. * CKEDITOR.loadFullCoreTimeout = 5;
  51. */
  52. CKEDITOR.loadFullCoreTimeout = 0;
  53. /**
  54. * The class name used to identify &lt;textarea&gt; elements to be replace
  55. * by CKEditor instances.
  56. * @type String
  57. * @default 'ckeditor'
  58. * @example
  59. * <b>CKEDITOR.replaceClass</b> = 'rich_editor';
  60. */
  61. CKEDITOR.replaceClass = 'ckeditor';
  62. /**
  63. * Enables the replacement of all textareas with class name matching
  64. * {@link CKEDITOR.replaceClass}.
  65. * @type Boolean
  66. * @default true
  67. * @example
  68. * // Disable the auto-replace feature.
  69. * <b>CKEDITOR.replaceByClassEnabled</b> = false;
  70. */
  71. CKEDITOR.replaceByClassEnabled = 1;
  72. var createInstance = function( elementOrIdOrName, config, creationFunction, data )
  73. {
  74. if ( CKEDITOR.env.isCompatible )
  75. {
  76. // Load the full core.
  77. if ( CKEDITOR.loadFullCore )
  78. CKEDITOR.loadFullCore();
  79. var editor = creationFunction( elementOrIdOrName, config, data );
  80. CKEDITOR.add( editor );
  81. return editor;
  82. }
  83. return null;
  84. };
  85. /**
  86. * Replaces a &lt;textarea&gt; or a DOM element (DIV) with a CKEditor
  87. * instance. For textareas, the initial value in the editor will be the
  88. * textarea value. For DOM elements, their innerHTML will be used
  89. * instead. We recommend using TEXTAREA and DIV elements only.
  90. * @param {Object|String} elementOrIdOrName The DOM element (textarea), its
  91. * ID or name.
  92. * @param {Object} [config] The specific configurations to apply to this
  93. * editor instance. Configurations set here will override global CKEditor
  94. * settings.
  95. * @returns {CKEDITOR.editor} The editor instance created.
  96. * @example
  97. * &lt;textarea id="myfield" name="myfield"&gt;&lt:/textarea&gt;
  98. * ...
  99. * <b>CKEDITOR.replace( 'myfield' )</b>;
  100. * @example
  101. * var textarea = document.body.appendChild( document.createElement( 'textarea' ) );
  102. * <b>CKEDITOR.replace( textarea )</b>;
  103. */
  104. CKEDITOR.replace = function( elementOrIdOrName, config )
  105. {
  106. return createInstance( elementOrIdOrName, config, CKEDITOR.editor.replace );
  107. };
  108. /**
  109. * Creates a new editor instance inside a specific DOM element.
  110. * @param {Object|String} elementOrId The DOM element or its ID.
  111. * @param {Object} [config] The specific configurations to apply to this
  112. * editor instance. Configurations set here will override global CKEditor
  113. * settings.
  114. * @param {String} [data] Since 3.3. Initial value for the instance.
  115. * @returns {CKEDITOR.editor} The editor instance created.
  116. * @example
  117. * &lt;div id="editorSpace"&gt;&lt:/div&gt;
  118. * ...
  119. * <b>CKEDITOR.appendTo( 'editorSpace' )</b>;
  120. */
  121. CKEDITOR.appendTo = function( elementOrId, config, data )
  122. {
  123. return createInstance( elementOrId, config, CKEDITOR.editor.appendTo, data );
  124. };
  125. // Documented at ckeditor.js.
  126. CKEDITOR.add = function( editor )
  127. {
  128. // For now, just put the editor in the pending list. It will be
  129. // processed as soon as the full code gets loaded.
  130. var pending = this._.pending || ( this._.pending = [] );
  131. pending.push( editor );
  132. };
  133. /**
  134. * Replace all &lt;textarea&gt; elements available in the document with
  135. * editor instances.
  136. * @example
  137. * // Replace all &lt;textarea&gt; elements in the page.
  138. * CKEDITOR.replaceAll();
  139. * @example
  140. * // Replace all &lt;textarea class="myClassName"&gt; elements in the page.
  141. * CKEDITOR.replaceAll( 'myClassName' );
  142. * @example
  143. * // Selectively replace &lt;textarea&gt; elements, based on custom assertions.
  144. * CKEDITOR.replaceAll( function( textarea, config )
  145. * {
  146. * // Custom code to evaluate the replace, returning false
  147. * // if it must not be done.
  148. * // It also passes the "config" parameter, so the
  149. * // developer can customize the instance.
  150. * } );
  151. */
  152. CKEDITOR.replaceAll = function()
  153. {
  154. var textareas = document.getElementsByTagName( 'textarea' );
  155. for ( var i = 0 ; i < textareas.length ; i++ )
  156. {
  157. var config = null,
  158. textarea = textareas[i];
  159. // The "name" and/or "id" attribute must exist.
  160. if ( !textarea.name && !textarea.id )
  161. continue;
  162. if ( typeof arguments[0] == 'string' )
  163. {
  164. // The textarea class name could be passed as the function
  165. // parameter.
  166. var classRegex = new RegExp( '(?:^|\\s)' + arguments[0] + '(?:$|\\s)' );
  167. if ( !classRegex.test( textarea.className ) )
  168. continue;
  169. }
  170. else if ( typeof arguments[0] == 'function' )
  171. {
  172. // An assertion function could be passed as the function parameter.
  173. // It must explicitly return "false" to ignore a specific <textarea>.
  174. config = {};
  175. if ( arguments[0]( textarea, config ) === false )
  176. continue;
  177. }
  178. this.replace( textarea, config );
  179. }
  180. };
  181. (function()
  182. {
  183. var onload = function()
  184. {
  185. var loadFullCore = CKEDITOR.loadFullCore,
  186. loadFullCoreTimeout = CKEDITOR.loadFullCoreTimeout;
  187. // Replace all textareas with the default class name.
  188. if ( CKEDITOR.replaceByClassEnabled )
  189. CKEDITOR.replaceAll( CKEDITOR.replaceClass );
  190. CKEDITOR.status = 'basic_ready';
  191. if ( loadFullCore && loadFullCore._load )
  192. loadFullCore();
  193. else if ( loadFullCoreTimeout )
  194. {
  195. setTimeout( function()
  196. {
  197. if ( CKEDITOR.loadFullCore )
  198. CKEDITOR.loadFullCore();
  199. }
  200. , loadFullCoreTimeout * 1000 );
  201. }
  202. };
  203. if ( window.addEventListener )
  204. window.addEventListener( 'load', onload, false );
  205. else if ( window.attachEvent )
  206. window.attachEvent( 'onload', onload );
  207. })();
  208. CKEDITOR.status = 'basic_loaded';
  209. })();
  210. }