JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / plugins / tab / plugin.js
index f2adcf9..c2646fe 100644 (file)
@@ -15,7 +15,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        exec : function( editor )\r
                        {\r
-                               editor.container.focusNext( true );\r
+                               editor.container.focusNext( true, editor.tabIndex );\r
                        }\r
                };\r
 \r
@@ -23,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
@@ -33,54 +33,43 @@ 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', CKEDITOR.tools.extend(\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
-                               }, meta ) );\r
-\r
-                       editor.addCommand( 'shiftTab', CKEDITOR.tools.extend(\r
-                               {\r
-                                       exec : function( editor )\r
+                       if ( CKEDITOR.env.webkit )\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
-                               }, meta ) );\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', CKEDITOR.tools.extend( blurCommand, meta ) );\r
                        editor.addCommand( 'blurBack', CKEDITOR.tools.extend( blurBackCommand, meta ) );\r
@@ -95,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
@@ -183,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
@@ -264,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