JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / toolbar / plugin.js
index a891c15..029e2dc 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -59,13 +59,37 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        var itemKeystroke = function( item, keystroke )\r
                        {\r
+                               var next, nextToolGroup, groupItemsCount;\r
+                               var rtl = editor.lang.dir == 'rtl';\r
+\r
                                switch ( keystroke )\r
                                {\r
-                                       case 39 :                                       // RIGHT-ARROW\r
+                                       case rtl ? 37 : 39 :                                    // RIGHT-ARROW\r
                                        case 9 :                                        // TAB\r
-                                               // Look for the next item in the toolbar.\r
-                                               while ( ( item = item.next || ( item.toolbar.next && item.toolbar.next.items[ 0 ] ) ) && !item.focus )\r
-                                               { /*jsl:pass*/ }\r
+                                               do\r
+                                               {\r
+                                                       // Look for the next item in the toolbar.\r
+                                                       next = item.next;\r
+\r
+                                                       if ( !next )\r
+                                                       {\r
+                                                               nextToolGroup = item.toolbar.next;\r
+                                                               groupItemsCount = nextToolGroup && nextToolGroup.items.length;\r
+\r
+                                                               // Bypass the empty toolgroups.\r
+                                                               while ( groupItemsCount === 0 )\r
+                                                               {\r
+                                                                       nextToolGroup = nextToolGroup.next;\r
+                                                                       groupItemsCount = nextToolGroup && nextToolGroup.items.length;\r
+                                                               }\r
+\r
+                                                               if ( nextToolGroup )\r
+                                                                       next = nextToolGroup.items[ 0 ];\r
+                                                       }\r
+\r
+                                                       item = next;\r
+                                               }\r
+                                               while ( item && !item.focus )\r
 \r
                                                // If available, just focus it, otherwise focus the\r
                                                // first one.\r
@@ -76,11 +100,32 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                return false;\r
 \r
-                                       case 37 :                                       // LEFT-ARROW\r
+                                       case rtl ? 39 : 37 :                                    // LEFT-ARROW\r
                                        case CKEDITOR.SHIFT + 9 :       // SHIFT + TAB\r
-                                               // Look for the previous item in the toolbar.\r
-                                               while ( ( item = item.previous || ( item.toolbar.previous && item.toolbar.previous.items[ item.toolbar.previous.items.length - 1 ] ) ) && !item.focus )\r
-                                               { /*jsl:pass*/ }\r
+                                               do\r
+                                               {\r
+                                                       // Look for the previous item in the toolbar.\r
+                                                       next = item.previous;\r
+\r
+                                                       if ( !next )\r
+                                                       {\r
+                                                               nextToolGroup = item.toolbar.previous;\r
+                                                               groupItemsCount = nextToolGroup && nextToolGroup.items.length;\r
+\r
+                                                               // Bypass the empty toolgroups.\r
+                                                               while ( groupItemsCount === 0 )\r
+                                                               {\r
+                                                                       nextToolGroup = nextToolGroup.previous;\r
+                                                                       groupItemsCount = nextToolGroup && nextToolGroup.items.length;\r
+                                                               }\r
+\r
+                                                               if ( nextToolGroup )\r
+                                                                       next = nextToolGroup.items[ groupItemsCount - 1 ];\r
+                                                       }\r
+\r
+                                                       item = next;\r
+                                               }\r
+                                               while ( item && !item.focus )\r
 \r
                                                // If available, just focus it, otherwise focus the\r
                                                // last one.\r
@@ -112,12 +157,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        {\r
                                                editor.toolbox = new toolbox();\r
 \r
-                                               var output = [ '<div class="cke_toolbox"' ],\r
+                                               var labelId = CKEDITOR.tools.getNextId();\r
+\r
+                                               var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '" onmousedown="return false;"' ],\r
                                                        expanded =  editor.config.toolbarStartupExpanded !== false,\r
                                                        groupStarted;\r
 \r
                                                output.push( expanded ? '>' : ' style="display:none">' );\r
 \r
+                                               // Sends the ARIA label.\r
+                                               output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );\r
+\r
                                                var toolbars = editor.toolbox.toolbars,\r
                                                        toolbar =\r
                                                                        ( editor.config.toolbar instanceof Array ) ?\r
@@ -137,7 +187,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        if ( !row )\r
                                                                continue;\r
 \r
-                                                       var toolbarId = 'cke_' + CKEDITOR.tools.getNextNumber(),\r
+                                                       var toolbarId = CKEDITOR.tools.getNextId(),\r
                                                                toolbarObj = { id : toolbarId, items : [] };\r
 \r
                                                        if ( groupStarted )\r
@@ -152,7 +202,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                continue;\r
                                                        }\r
 \r
-                                                       output.push( '<span id="', toolbarId, '" class="cke_toolbar"><span class="cke_toolbar_start"></span>' );\r
+                                                       output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );\r
 \r
                                                        // Add the toolbar to the "editor.toolbox.toolbars"\r
                                                        // array.\r
@@ -182,7 +232,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        {\r
                                                                                if ( !groupStarted )\r
                                                                                {\r
-                                                                                       output.push( '<span class="cke_toolgroup">' );\r
+                                                                                       output.push( '<span class="cke_toolgroup" role="presentation">' );\r
                                                                                        groupStarted = 1;\r
                                                                                }\r
                                                                        }\r
@@ -233,22 +283,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                function()\r
                                                                {\r
                                                                        editor.execCommand( 'toolbarCollapse' );\r
-                                                               } );\r
+                                                               });\r
 \r
-                                                       var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber();\r
+                                                       editor.on( 'destroy', function () {\r
+                                                                       CKEDITOR.tools.removeFunction( collapserFn );\r
+                                                               });\r
+\r
+                                                       var collapserId = CKEDITOR.tools.getNextId();\r
 \r
                                                        editor.addCommand( 'toolbarCollapse',\r
                                                                {\r
                                                                        exec : function( editor )\r
                                                                        {\r
-                                                                               var collapser = CKEDITOR.document.getById( collapserId );\r
-                                                                               var toolbox = collapser.getPrevious();\r
-                                                                               var contents = editor.getThemeSpace( 'contents' );\r
-                                                                               var toolboxContainer = toolbox.getParent();\r
-                                                                               var contentHeight = parseInt( contents.$.style.height, 10 );\r
-                                                                               var previousHeight = toolboxContainer.$.offsetHeight;\r
-\r
-                                                                               if ( toolbox.isVisible() )\r
+                                                                               var collapser = CKEDITOR.document.getById( collapserId ),\r
+                                                                                       toolbox = collapser.getPrevious(),\r
+                                                                                       contents = editor.getThemeSpace( 'contents' ),\r
+                                                                                       toolboxContainer = toolbox.getParent(),\r
+                                                                                       contentHeight = parseInt( contents.$.style.height, 10 ),\r
+                                                                                       previousHeight = toolboxContainer.$.offsetHeight,\r
+                                                                                       collapsed = !toolbox.isVisible();\r
+\r
+                                                                               if ( !collapsed )\r
                                                                                {\r
                                                                                        toolbox.hide();\r
                                                                                        collapser.addClass( 'cke_toolbox_collapser_min' );\r
@@ -261,20 +316,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                        collapser.setAttribute( 'title', editor.lang.toolbarCollapse );\r
                                                                                }\r
 \r
+                                                                               // Update collapser symbol.\r
+                                                                               collapser.getFirst().setText( collapsed ?\r
+                                                                                       '\u25B2' :              // BLACK UP-POINTING TRIANGLE\r
+                                                                                       '\u25C0' );             // BLACK LEFT-POINTING TRIANGLE\r
+\r
                                                                                var dy = toolboxContainer.$.offsetHeight - previousHeight;\r
                                                                                contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );\r
+\r
+                                                                               editor.fire( 'resize' );\r
                                                                        },\r
 \r
                                                                        modes : { wysiwyg : 1, source : 1 }\r
                                                                } );\r
 \r
                                                        output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )\r
-                                                                                                         + '" id="' + collapserId + '" class="cke_toolbox_collapser' );\r
+                                                                                                         + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );\r
 \r
                                                        if ( !expanded )\r
                                                                output.push( ' cke_toolbox_collapser_min' );\r
 \r
-                                                       output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')"></a>' );\r
+                                                       output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',\r
+                                                                               '<span>&#9650;</span>',         // BLACK UP-POINTING TRIANGLE\r
+                                                                               '</a>' );\r
                                                }\r
 \r
                                                event.data.html += output.join( '' );\r
@@ -295,7 +359,7 @@ CKEDITOR.ui.separator =
 {\r
        render : function( editor, output )\r
        {\r
-               output.push( '<span class="cke_separator"></span>' );\r
+               output.push( '<span class="cke_separator" role="separator"></span>' );\r
                return {};\r
        }\r
 };\r
@@ -349,8 +413,9 @@ CKEDITOR.config.toolbar_Basic =
  *     ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],\r
  *     '/',\r
  *     ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],\r
- *     ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],\r
+ *     ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],\r
  *     ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],\r
+ *     ['BidiLtr', 'BidiRtl' ],\r
  *     ['Link','Unlink','Anchor'],\r
  *     ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],\r
  *     '/',\r
@@ -367,8 +432,9 @@ CKEDITOR.config.toolbar_Full =
        ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],\r
        '/',\r
        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],\r
-       ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],\r
+       ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],\r
        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],\r
+       ['BidiLtr', 'BidiRtl' ],\r
        ['Link','Unlink','Anchor'],\r
        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],\r
        '/',\r