JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / editingblock / plugin.js
index 4d0885b..7d7742f 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\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
@@ -10,11 +10,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       var getMode = function( editor, mode )\r
-       {\r
-               return editor._.modes && editor._.modes[ mode || editor.mode ];\r
-       };\r
-\r
        // This is a semaphore used to avoid recursive calls between\r
        // the following data handling functions.\r
        var isHandlingData;\r
@@ -49,7 +44,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                function setData()\r
                                                {\r
                                                        isHandlingData = true;\r
-                                                       getMode( editor ).loadData( editor.getData() );\r
+                                                       editor.getMode().loadData( editor.getData() );\r
                                                        isHandlingData = false;\r
                                                }\r
 \r
@@ -59,8 +54,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                {\r
                                                        editor.on( 'mode', function()\r
                                                                {\r
-                                                                       setData();\r
-                                                                       editor.removeListener( 'mode', arguments.callee );\r
+                                                                       if ( editor.mode )\r
+                                                                       {\r
+                                                                               setData();\r
+                                                                               editor.removeListener( 'mode', arguments.callee );\r
+                                                                       }\r
                                                                });\r
                                                }\r
                                        }\r
@@ -71,7 +69,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( !isHandlingData && editor.mode )\r
                                        {\r
                                                isHandlingData = true;\r
-                                               editor.setData( getMode( editor ).getData() );\r
+                                               editor.setData( editor.getMode().getData(), null, 1 );\r
                                                isHandlingData = false;\r
                                        }\r
                                });\r
@@ -79,13 +77,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        editor.on( 'getSnapshot', function( event )\r
                                {\r
                                        if ( editor.mode )\r
-                                               event.data = getMode( editor ).getSnapshotData();\r
+                                               event.data = editor.getMode().getSnapshotData();\r
                                });\r
 \r
                        editor.on( 'loadSnapshot', function( event )\r
                                {\r
                                        if ( editor.mode )\r
-                                               getMode( editor ).loadSnapshotData( event.data );\r
+                                               editor.getMode().loadSnapshotData( event.data );\r
                                });\r
 \r
                        // For the first "mode" call, we'll also fire the "instanceReady"\r
@@ -95,21 +93,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        // Do that once only.\r
                                        event.removeListener();\r
 \r
-                                       // Grab editor focus if the editor container is focused. (#3104)\r
-                                       var focusGrabber = editor.container;\r
-\r
-                                       // Safari 3 can't handle tabindex in all elements, so we do\r
-                                       // a trick to make it move the focus to the editor on TAB.\r
-                                       if ( CKEDITOR.env.webkit && CKEDITOR.env.version < 528 )\r
-                                       {\r
-                                               var tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;\r
-                                               focusGrabber = focusGrabber.append( CKEDITOR.dom.element.createFromHtml(\r
-                                                       '<input' +\r
-                                                               ' tabindex="' + tabIndex + '"' +\r
-                                                               ' style="position:absolute; left:-10000">' ) );\r
-                                       }\r
-\r
-                                       focusGrabber.on( 'focus', function()\r
+                                       // Redirect the focus into editor for webkit. (#5713)\r
+                                       CKEDITOR.env.webkit && editor.container.on( 'focus', function()\r
                                                {\r
                                                        editor.focus();\r
                                                });\r
@@ -123,8 +108,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        setTimeout( function(){\r
                                                editor.fireOnce( 'instanceReady' );\r
                                                CKEDITOR.fire( 'instanceReady', null, editor );\r
-                                       } );\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
@@ -159,6 +151,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
         */\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
@@ -171,7 +165,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        this.fire( 'beforeModeUnload' );\r
 \r
-                       var currentMode = getMode( this );\r
+                       var currentMode = this.getMode();\r
                        data = currentMode.getData();\r
                        currentMode.unload( holderElement );\r
                        this.mode = '';\r
@@ -180,7 +174,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                holderElement.setHtml( '' );\r
 \r
                // Load required mode.\r
-               var modeEditor = getMode( this, mode );\r
+               var modeEditor = this.getMode( mode );\r
                if ( !modeEditor )\r
                        throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';\r
 \r
@@ -197,11 +191,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        };\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
-               var mode = getMode( this );\r
+               this.forceNextSelectionCheck();\r
+               var mode = this.getMode();\r
                if ( mode )\r
                        mode.focus();\r
        };\r
@@ -219,12 +225,12 @@ CKEDITOR.config.startupMode = 'wysiwyg';
 \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
-CKEDITOR.config.startupFocus = false;\r
 \r
 /**\r
  * Whether to render or not the editing block area in the editor interface.\r
@@ -234,3 +240,36 @@ CKEDITOR.config.startupFocus = false;
  * 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