JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / plugins / listblock / plugin.js
index 3ca89ad..848cc2a 100644 (file)
@@ -9,21 +9,27 @@ CKEDITOR.plugins.add( 'listblock',
 \r
        onLoad : function()\r
        {\r
-               CKEDITOR.ui.panel.prototype.addListBlock = function( name, multiSelect )\r
+               CKEDITOR.ui.panel.prototype.addListBlock = function( name, definiton )\r
                {\r
-                       return this.addBlock( name, new CKEDITOR.ui.listBlock( this.getHolderElement(), multiSelect ) );\r
+                       return this.addBlock( name, new CKEDITOR.ui.listBlock( this.getHolderElement(), definiton ) );\r
                };\r
 \r
                CKEDITOR.ui.listBlock = CKEDITOR.tools.createClass(\r
                        {\r
                                base : CKEDITOR.ui.panel.block,\r
 \r
-                               $ : function( blockHolder, multiSelect )\r
+                               $ : function( blockHolder, blockDefinition )\r
                                {\r
-                                       // Call the base contructor.\r
-                                       this.base( blockHolder );\r
+                                       blockDefinition = blockDefinition || {};\r
+\r
+                                       var attribs = blockDefinition.attributes || ( blockDefinition.attributes = {} );\r
+                                       ( this.multiSelect = !!blockDefinition.multiSelect ) &&\r
+                                               ( attribs[ 'aria-multiselectable' ] = true );\r
+                                       // Provide default role of 'listbox'.\r
+                                       !attribs.role && ( attribs.role = 'listbox' );\r
 \r
-                                       this.multiSelect = !!multiSelect;\r
+                                       // Call the base contructor.\r
+                                       this.base.apply( this, arguments );\r
 \r
                                        var keys = this.keys;\r
                                        keys[ 40 ]      = 'next';                                       // ARROW-DOWN\r
@@ -79,18 +85,21 @@ CKEDITOR.plugins.add( 'listblock',
 \r
                                                if ( !this._.started )\r
                                                {\r
-                                                       pendingHtml.push( '<ul class=cke_panel_list>' );\r
+                                                       pendingHtml.push( '<ul role="presentation" class=cke_panel_list>' );\r
                                                        this._.started = 1;\r
+                                                       this._.size = this._.size || 0;\r
                                                }\r
 \r
                                                this._.items[ value ] = id;\r
 \r
                                                pendingHtml.push(\r
                                                        '<li id=', id, ' class=cke_panel_listItem>' +\r
-                                                               '<a _cke_focus=1 hidefocus=true' +\r
+                                                               '<a id="', id, '_option" _cke_focus=1 hidefocus=true' +\r
                                                                        ' title="', title || value, '"' +\r
                                                                        ' href="javascript:void(\'', value, '\')"' +\r
-                                                                       ' onclick="CKEDITOR.tools.callFunction(', this._.getClick(), ',\'', value, '\'); return false;">',\r
+                                                                       ' onclick="CKEDITOR.tools.callFunction(', this._.getClick(), ',\'', value, '\'); return false;"',\r
+                                                                       ' role="option"' +\r
+                                                                       ' aria-posinset="' + ++this._.size + '">',\r
                                                                        html || value,\r
                                                                '</a>' +\r
                                                        '</li>' );\r
@@ -104,13 +113,20 @@ CKEDITOR.plugins.add( 'listblock',
 \r
                                                this._.groups[ title ] = id;\r
 \r
-                                               this._.pendingHtml.push( '<h1 id=', id, ' class=cke_panel_grouptitle>', title, '</h1>' );\r
+                                               this._.pendingHtml.push( '<h1 role="presentation" id=', id, ' class=cke_panel_grouptitle>', title, '</h1>' );\r
                                        },\r
 \r
                                        commit : function()\r
                                        {\r
                                                this._.close();\r
                                                this.element.appendHtml( this._.pendingHtml.join( '' ) );\r
+\r
+                                               var items = this._.items,\r
+                                                       doc = this.element.getDocument();\r
+                                               for ( var value in items )\r
+                                                       doc.getById( items[ value ] + '_option' ).setAttribute( 'aria-setsize', this._.size );\r
+                                               delete this._.size;\r
+\r
                                                this._.pendingHtml = [];\r
                                        },\r
 \r
@@ -173,7 +189,12 @@ CKEDITOR.plugins.add( 'listblock',
                                                if ( !this.multiSelect )\r
                                                        this.unmarkAll();\r
 \r
-                                               this.element.getDocument().getById( this._.items[ value ] ).addClass( 'cke_selected' );\r
+                                               var itemId = this._.items[ value ],\r
+                                                       item = this.element.getDocument().getById( itemId );\r
+                                               item.addClass( 'cke_selected' );\r
+\r
+                                               this.element.getDocument().getById( itemId + '_option' ).setAttribute( 'aria-selected', true );\r
+                                               this.element.setAttribute( 'aria-activedescendant', itemId + '_option' );\r
                                        },\r
 \r
                                        unmark : function( value )\r