JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.3
[ckeditor.git] / _source / plugins / tab / plugin.js
index 55c210a..c66fb43 100644 (file)
@@ -1,15 +1,21 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
 (function()\r
 {\r
+       var meta =\r
+       {\r
+               editorFocus : false,\r
+               modes : { wysiwyg:1, source:1 }\r
+       };\r
+\r
        var blurCommand =\r
                {\r
                        exec : function( editor )\r
                        {\r
-                               editor.container.focusNext( true );\r
+                               editor.container.focusNext( true, editor.tabIndex );\r
                        }\r
                };\r
 \r
@@ -17,7 +23,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        exec : function( editor )\r
                        {\r
-                               editor.container.focusPrevious( true );\r
+                               editor.container.focusPrevious( true, editor.tabIndex );\r
                        }\r
                };\r
 \r
@@ -27,57 +33,46 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                init : function( editor )\r
                {\r
-                       // Register the keystrokes.\r
-                       var keystrokes = editor.keystrokeHandler.keystrokes;\r
-                       keystrokes[ 9 /* TAB */ ] = 'tab';\r
-                       keystrokes[ CKEDITOR.SHIFT + 9 /* TAB */ ] = 'shiftTab';\r
-\r
-                       var tabSpaces = editor.config.tabSpaces,\r
+                       var tabSpaces = editor.config.tabSpaces || 0,\r
                                tabText = '';\r
 \r
                        while ( tabSpaces-- )\r
                                tabText += '\xa0';\r
 \r
-                       // Register the "tab" and "shiftTab" commands.\r
-                       editor.addCommand( 'tab',\r
-                               {\r
-                                       exec : function( editor )\r
+                       if ( tabText )\r
+                       {\r
+                               editor.on( 'key', function( ev )\r
                                        {\r
-                                               // Fire the "tab" event, making it possible to\r
-                                               // customize the TAB key behavior on specific cases.\r
-                                               if ( !editor.fire( 'tab' ) )\r
+                                               if ( ev.data.keyCode == 9 )     // TAB\r
                                                {\r
-                                                       if ( tabText.length > 0 )\r
-                                                               editor.insertHtml( tabText );\r
-                                                       else\r
-                                                       {\r
-                                                               // All browsers jump to the next field on TAB,\r
-                                                               // except Safari, so we have to do that manually\r
-                                                               // here.\r
-                                                               /// https://bugs.webkit.org/show_bug.cgi?id=20597\r
-                                                               return editor.execCommand( 'blur' );\r
-                                                       }\r
+                                                       editor.insertHtml( tabText );\r
+                                                       ev.cancel();\r
                                                }\r
+                                       });\r
+                       }\r
 \r
-                                               return true;\r
-                                       }\r
-                               });\r
-\r
-                       editor.addCommand( 'shiftTab',\r
-                               {\r
-                                       exec : function( editor )\r
+                       if ( CKEDITOR.env.webkit || CKEDITOR.env.gecko )\r
+                       {\r
+                               editor.on( 'key', function( ev )\r
                                        {\r
-                                               // Fire the "tab" event, making it possible to\r
-                                               // customize the TAB key behavior on specific cases.\r
-                                               if ( !editor.fire( 'shiftTab' ) )\r
-                                                       return editor.execCommand( 'blurBack' );\r
+                                               var keyCode = ev.data.keyCode;\r
 \r
-                                               return true;\r
-                                       }\r
-                               });\r
+                                               if ( keyCode == 9 && !tabText )                         // TAB\r
+                                               {\r
+                                                       ev.cancel();\r
+                                                       editor.execCommand( 'blur' );\r
+                                               }\r
+\r
+                                               if ( keyCode == ( CKEDITOR.SHIFT + 9 ) )        // SHIFT+TAB\r
+                                               {\r
+                                                       editor.execCommand( 'blurBack' );\r
+                                                       ev.cancel();\r
+                                               }\r
+                                       });\r
+                       }\r
 \r
-                       editor.addCommand( 'blur', blurCommand );\r
-                       editor.addCommand( 'blurBack', blurBackCommand );\r
+                       editor.addCommand( 'blur', CKEDITOR.tools.extend( blurCommand, meta ) );\r
+                       editor.addCommand( 'blurBack', CKEDITOR.tools.extend( blurBackCommand, meta ) );\r
                }\r
        });\r
 })();\r
@@ -89,10 +84,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * var element = CKEDITOR.document.getById( 'example' );\r
  * element.focusNext();\r
  */\r
-CKEDITOR.dom.element.prototype.focusNext = function( ignoreChildren )\r
+CKEDITOR.dom.element.prototype.focusNext = function( ignoreChildren, indexToUse )\r
 {\r
        var $ = this.$,\r
-               curTabIndex = this.getTabIndex(),\r
+               curTabIndex = ( indexToUse === undefined ? this.getTabIndex() : indexToUse ),\r
                passedCurrent, enteredCurrent,\r
                elected, electedTabIndex,\r
                element, elementTabIndex;\r
@@ -104,7 +99,7 @@ CKEDITOR.dom.element.prototype.focusNext = function( ignoreChildren )
 \r
                element = this.getNextSourceNode( ignoreChildren, CKEDITOR.NODE_ELEMENT );\r
 \r
-               while( element )\r
+               while ( element )\r
                {\r
                        if ( element.isVisible() && element.getTabIndex() === 0 )\r
                        {\r
@@ -125,7 +120,7 @@ CKEDITOR.dom.element.prototype.focusNext = function( ignoreChildren )
 \r
                element = this.getDocument().getBody().getFirst();\r
 \r
-               while( ( element = element.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT ) ) )\r
+               while ( ( element = element.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT ) ) )\r
                {\r
                        if ( !passedCurrent )\r
                        {\r
@@ -177,10 +172,10 @@ CKEDITOR.dom.element.prototype.focusNext = function( ignoreChildren )
  * var element = CKEDITOR.document.getById( 'example' );\r
  * element.focusPrevious();\r
  */\r
-CKEDITOR.dom.element.prototype.focusPrevious = function( ignoreChildren )\r
+CKEDITOR.dom.element.prototype.focusPrevious = function( ignoreChildren, indexToUse )\r
 {\r
        var $ = this.$,\r
-               curTabIndex = this.getTabIndex(),\r
+               curTabIndex = ( indexToUse === undefined ? this.getTabIndex() : indexToUse ),\r
                passedCurrent, enteredCurrent,\r
                elected,\r
                electedTabIndex = 0,\r
@@ -188,7 +183,7 @@ CKEDITOR.dom.element.prototype.focusPrevious = function( ignoreChildren )
 \r
        var element = this.getDocument().getBody().getLast();\r
 \r
-       while( ( element = element.getPreviousSourceNode( false, CKEDITOR.NODE_ELEMENT ) ) )\r
+       while ( ( element = element.getPreviousSourceNode( false, CKEDITOR.NODE_ELEMENT ) ) )\r
        {\r
                if ( !passedCurrent )\r
                {\r
@@ -258,9 +253,9 @@ CKEDITOR.dom.element.prototype.focusPrevious = function( ignoreChildren )
  * Intructs the editor to add a number of spaces ( ) to the text when\r
  * hitting the TAB key. If set to zero, the TAB key will be used to move the\r
  * cursor focus to the next element in the page, out of the editor focus.\r
+ * @name CKEDITOR.config.tabSpaces\r
  * @type Number\r
  * @default 0\r
  * @example\r
  * config.tabSpaces = 4;\r
  */\r
-CKEDITOR.config.tabSpaces = 0 ;\r