JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / button / plugin.js
index db982d5..c0c8208 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
@@ -69,9 +69,13 @@ CKEDITOR.ui.button.prototype =
         */\r
        render : function( editor, output )\r
        {\r
-               var env = CKEDITOR.env;\r
+               var env = CKEDITOR.env,\r
+                       id = this._.id = CKEDITOR.tools.getNextId(),\r
+                       classes = '',\r
+                       command = this.command, // Get the command name.\r
+                       clickFn,\r
+                       index;\r
 \r
-               var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber();\r
                this._.editor = editor;\r
 \r
                var instance =\r
@@ -90,20 +94,26 @@ CKEDITOR.ui.button.prototype =
                        }\r
                };\r
 \r
-               var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
+               instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
 \r
-               var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;\r
-\r
-               var classes = '';\r
-\r
-               // Get the command name.\r
-               var command = this.command;\r
+               instance.index = index = CKEDITOR.ui.button._.instances.push( instance ) - 1;\r
 \r
+               // Indicate a mode sensitive button.\r
                if ( this.modes )\r
                {\r
+                       var modeStates = {};\r
+                       editor.on( 'beforeModeUnload', function()\r
+                               {\r
+                                       modeStates[ editor.mode ] = this._.state;\r
+                               }, this );\r
+\r
                        editor.on( 'mode', function()\r
                                {\r
-                                       this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );\r
+                                       var mode = editor.mode;\r
+                                       // Restore saved button state.\r
+                                       this.setState( this.modes[ mode ] ?\r
+                                               modeStates[ mode ] != undefined ? modeStates[ mode ] :\r
+                                                       CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );\r
                                }, this);\r
                }\r
                else if ( command )\r
@@ -134,10 +144,14 @@ CKEDITOR.ui.button.prototype =
                output.push(\r
                        '<span class="cke_button">',\r
                        '<a id="', id, '"' +\r
-                               ' class="', classes, '" href="javascript:void(\'', ( this.title || '' ).replace( "'", '' ), '\')"' +\r
+                               ' class="', classes, '"',\r
+                               env.gecko && env.version >= 10900 && !env.hc  ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'", '' )+ '\')"',\r
                                ' title="', this.title, '"' +\r
                                ' tabindex="-1"' +\r
-                               ' hidefocus="true"' );\r
+                               ' hidefocus="true"' +\r
+                           ' role="button"' +\r
+                               ' aria-labelledby="' + id + '_label"' +\r
+                               ( this.hasArrow ?  ' aria-haspopup="true"' : '' ) );\r
 \r
                // Some browsers don't cancel key events in the keydown but in the\r
                // keypress.\r
@@ -169,13 +183,16 @@ CKEDITOR.ui.button.prototype =
                }\r
 \r
                output.push(\r
-                                       '></span>' +\r
-                                       '<span class="cke_label">', this.label, '</span>' );\r
+                                       '>&nbsp;</span>' +\r
+                                       '<span id="', id, '_label" class="cke_label">', this.label, '</span>' );\r
 \r
                if ( this.hasArrow )\r
                {\r
                        output.push(\r
-                                       '<span class="cke_buttonarrow"></span>' );\r
+                                       '<span class="cke_buttonarrow">'\r
+                                       // BLACK DOWN-POINTING TRIANGLE\r
+                                       + ( CKEDITOR.env.hc ? '&#9660;' : '&nbsp;' )\r
+                                       + '</span>' );\r
                }\r
 \r
                output.push(\r
@@ -191,25 +208,27 @@ CKEDITOR.ui.button.prototype =
        setState : function( state )\r
        {\r
                if ( this._.state == state )\r
-                       return;\r
+                       return false;\r
+\r
+               this._.state = state;\r
 \r
                var element = CKEDITOR.document.getById( this._.id );\r
 \r
                if ( element )\r
                {\r
                        element.setState( state );\r
+                       state == CKEDITOR.TRISTATE_DISABLED ?\r
+                               element.setAttribute( 'aria-disabled', true ) :\r
+                               element.removeAttribute( 'aria-disabled' );\r
 \r
-                       var htmlTitle = this.title,\r
-                               unavailable = this._.editor.lang.common.unavailable,\r
-                               labelElement = element.getChild( 1 );\r
+                       state == CKEDITOR.TRISTATE_ON ?\r
+                               element.setAttribute( 'aria-pressed', true ) :\r
+                               element.removeAttribute( 'aria-pressed' );\r
 \r
-                       if ( state == CKEDITOR.TRISTATE_DISABLED )\r
-                               htmlTitle = unavailable.replace( '%1', this.title );\r
-\r
-                       labelElement.setHtml( htmlTitle );\r
+                       return true;\r
                }\r
-\r
-               this._.state = state;\r
+               else\r
+                       return false;\r
        }\r
 };\r
 \r
@@ -262,3 +281,8 @@ CKEDITOR.ui.prototype.addButton = function( name, definition )
 {\r
        this.add( name, CKEDITOR.UI_BUTTON, definition );\r
 };\r
+\r
+CKEDITOR.on( 'reset', function()\r
+       {\r
+               CKEDITOR.ui.button._.instances = [];\r
+       });\r