Mimimum syndical pour en faire un produit zope / cmf.
[ckeditor.git] / skins / ckeditor / _source / plugins / editingblock / plugin.js
diff --git a/skins/ckeditor/_source/plugins/editingblock/plugin.js b/skins/ckeditor/_source/plugins/editingblock/plugin.js
new file mode 100644 (file)
index 0000000..7d7742f
--- /dev/null
@@ -0,0 +1,275 @@
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview The default editing block plugin, which holds the editing area\r
+ *             and source view.\r
+ */\r
+\r
+(function()\r
+{\r
+       // This is a semaphore used to avoid recursive calls between\r
+       // the following data handling functions.\r
+       var isHandlingData;\r
+\r
+       CKEDITOR.plugins.add( 'editingblock',\r
+       {\r
+               init : function( editor )\r
+               {\r
+                       if ( !editor.config.editingBlock )\r
+                               return;\r
+\r
+                       editor.on( 'themeSpace', function( event )\r
+                               {\r
+                                       if ( event.data.space == 'contents' )\r
+                                               event.data.html += '<br>';\r
+                               });\r
+\r
+                       editor.on( 'themeLoaded', function()\r
+                               {\r
+                                       editor.fireOnce( 'editingBlockReady' );\r
+                               });\r
+\r
+                       editor.on( 'uiReady', function()\r
+                               {\r
+                                       editor.setMode( editor.config.startupMode );\r
+                               });\r
+\r
+                       editor.on( 'afterSetData', function()\r
+                               {\r
+                                       if ( !isHandlingData )\r
+                                       {\r
+                                               function setData()\r
+                                               {\r
+                                                       isHandlingData = true;\r
+                                                       editor.getMode().loadData( editor.getData() );\r
+                                                       isHandlingData = false;\r
+                                               }\r
+\r
+                                               if ( editor.mode )\r
+                                                       setData();\r
+                                               else\r
+                                               {\r
+                                                       editor.on( 'mode', function()\r
+                                                               {\r
+                                                                       if ( editor.mode )\r
+                                                                       {\r
+                                                                               setData();\r
+                                                                               editor.removeListener( 'mode', arguments.callee );\r
+                                                                       }\r
+                                                               });\r
+                                               }\r
+                                       }\r
+                               });\r
+\r
+                       editor.on( 'beforeGetData', function()\r
+                               {\r
+                                       if ( !isHandlingData && editor.mode )\r
+                                       {\r
+                                               isHandlingData = true;\r
+                                               editor.setData( editor.getMode().getData(), null, 1 );\r
+                                               isHandlingData = false;\r
+                                       }\r
+                               });\r
+\r
+                       editor.on( 'getSnapshot', function( event )\r
+                               {\r
+                                       if ( editor.mode )\r
+                                               event.data = editor.getMode().getSnapshotData();\r
+                               });\r
+\r
+                       editor.on( 'loadSnapshot', function( event )\r
+                               {\r
+                                       if ( editor.mode )\r
+                                               editor.getMode().loadSnapshotData( event.data );\r
+                               });\r
+\r
+                       // For the first "mode" call, we'll also fire the "instanceReady"\r
+                       // event.\r
+                       editor.on( 'mode', function( event )\r
+                               {\r
+                                       // Do that once only.\r
+                                       event.removeListener();\r
+\r
+                                       // Redirect the focus into editor for webkit. (#5713)\r
+                                       CKEDITOR.env.webkit && editor.container.on( 'focus', function()\r
+                                               {\r
+                                                       editor.focus();\r
+                                               });\r
+\r
+                                       if ( editor.config.startupFocus )\r
+                                               editor.focus();\r
+\r
+                                       // Fire instanceReady for both the editor and CKEDITOR, but\r
+                                       // defer this until the whole execution has completed\r
+                                       // to guarantee the editor is fully responsible.\r
+                                       setTimeout( function(){\r
+                                               editor.fireOnce( 'instanceReady' );\r
+                                               CKEDITOR.fire( 'instanceReady', null, editor );\r
+                                       }, 0 );\r
+                               });\r
+\r
+                       editor.on( 'destroy', function ()\r
+                       {\r
+                               // ->           currentMode.unload( holderElement );\r
+                               if ( this.mode )\r
+                                       this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );\r
+                       });\r
+               }\r
+       });\r
+\r
+       /**\r
+        * The current editing mode. An editing mode is basically a viewport for\r
+        * editing or content viewing. By default the possible values for this\r
+        * property are "wysiwyg" and "source".\r
+        * @type String\r
+        * @example\r
+        * alert( CKEDITOR.instances.editor1.mode );  // "wysiwyg" (e.g.)\r
+        */\r
+       CKEDITOR.editor.prototype.mode = '';\r
+\r
+       /**\r
+        * Registers an editing mode. This function is to be used mainly by plugins.\r
+        * @param {String} mode The mode name.\r
+        * @param {Object} modeEditor The mode editor definition.\r
+        * @example\r
+        */\r
+       CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )\r
+       {\r
+               modeEditor.name = mode;\r
+               ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;\r
+       };\r
+\r
+       /**\r
+        * Sets the current editing mode in this editor instance.\r
+        * @param {String} mode A registered mode name.\r
+        * @example\r
+        * // Switch to "source" view.\r
+        * CKEDITOR.instances.editor1.setMode( 'source' );\r
+        */\r
+       CKEDITOR.editor.prototype.setMode = function( mode )\r
+       {\r
+               this.fire( 'beforeSetMode', { newMode : mode } );\r
+\r
+               var data,\r
+                       holderElement = this.getThemeSpace( 'contents' ),\r
+                       isDirty = this.checkDirty();\r
+\r
+               // Unload the previous mode.\r
+               if ( this.mode )\r
+               {\r
+                       if ( mode == this.mode )\r
+                               return;\r
+\r
+                       this.fire( 'beforeModeUnload' );\r
+\r
+                       var currentMode = this.getMode();\r
+                       data = currentMode.getData();\r
+                       currentMode.unload( holderElement );\r
+                       this.mode = '';\r
+               }\r
+\r
+               holderElement.setHtml( '' );\r
+\r
+               // Load required mode.\r
+               var modeEditor = this.getMode( mode );\r
+               if ( !modeEditor )\r
+                       throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';\r
+\r
+               if ( !isDirty )\r
+               {\r
+                       this.on( 'mode', function()\r
+                               {\r
+                                       this.resetDirty();\r
+                                       this.removeListener( 'mode', arguments.callee );\r
+                               });\r
+               }\r
+\r
+               modeEditor.load( holderElement, ( typeof data ) != 'string'  ? this.getData() : data);\r
+       };\r
+\r
+       /**\r
+        * Gets the current or any of the objects that represent the editing\r
+        * area modes. The two most common editing modes are "wysiwyg" and "source".\r
+        * @param {String} [mode] The mode to be retrieved. If not specified, the\r
+        *              current one is returned.\r
+        */\r
+       CKEDITOR.editor.prototype.getMode = function( mode )\r
+       {\r
+               return this._.modes && this._.modes[ mode || this.mode ];\r
+       };\r
+\r
+       /**\r
+        * Moves the selection focus to the editing are space in the editor.\r
+        */\r
+       CKEDITOR.editor.prototype.focus = function()\r
+       {\r
+               this.forceNextSelectionCheck();\r
+               var mode = this.getMode();\r
+               if ( mode )\r
+                       mode.focus();\r
+       };\r
+})();\r
+\r
+/**\r
+ * The mode to load at the editor startup. It depends on the plugins\r
+ * loaded. By default, the "wysiwyg" and "source" modes are available.\r
+ * @type String\r
+ * @default 'wysiwyg'\r
+ * @example\r
+ * config.startupMode = 'source';\r
+ */\r
+CKEDITOR.config.startupMode = 'wysiwyg';\r
+\r
+/**\r
+ * Sets whether the editor should have the focus when the page loads.\r
+ * @name CKEDITOR.config.startupFocus\r
+ * @type Boolean\r
+ * @default false\r
+ * @example\r
+ * config.startupFocus = true;\r
+ */\r
+\r
+/**\r
+ * Whether to render or not the editing block area in the editor interface.\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.editingBlock = false;\r
+ */\r
+CKEDITOR.config.editingBlock = true;\r
+\r
+/**\r
+ * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.\r
+ * @name CKEDITOR#instanceReady\r
+ * @event\r
+ * @param {CKEDITOR.editor} editor The editor instance that has been created.\r
+ */\r
+\r
+/**\r
+ * Fired when the CKEDITOR instance is created, fully initialized and ready for interaction.\r
+ * @name CKEDITOR.editor#instanceReady\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Fired before changing the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#mode\r
+ * @name CKEDITOR.editor#beforeModeUnload\r
+ * @event\r
+ */\r
+\r
+ /**\r
+ * Fired before the editor mode is set. See also CKEDITOR.editor#mode and CKEDITOR.editor#beforeModeUnload\r
+ * @name CKEDITOR.editor#beforeSetMode\r
+ * @event\r
+ * @since 3.5.3\r
+ * @param {String} newMode The name of the mode which is about to be set.\r
+ */\r
+\r
+/**\r
+ * Fired after setting the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#beforeModeUnload\r
+ * @name CKEDITOR.editor#mode\r
+ * @event\r
+ */\r