/*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
* @constant\r
* @example\r
*/\r
-CKEDITOR.UI_BUTTON = 1;\r
+CKEDITOR.UI_BUTTON = 'button';\r
\r
/**\r
* Represents a button UI element. This class should not be called directly. To\r
}\r
};\r
\r
+( function()\r
+{\r
CKEDITOR.ui.button.prototype =\r
{\r
- canGroup : true,\r
-\r
/**\r
* Renders the button.\r
* @param {CKEDITOR.editor} editor The editor instance which this button is\r
*/\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
\r
- var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber();\r
this._.editor = editor;\r
\r
var instance =\r
}\r
};\r
\r
- var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
+ var keydownFn = CKEDITOR.tools.addFunction( function( ev )\r
+ {\r
+ if ( instance.onkey )\r
+ {\r
+ ev = new CKEDITOR.dom.event( ev );\r
+ return ( instance.onkey( instance, ev.getKeystroke() ) !== false );\r
+ }\r
+ });\r
+\r
+ var focusFn = CKEDITOR.tools.addFunction( function( ev )\r
+ {\r
+ var retVal;\r
+\r
+ if ( instance.onfocus )\r
+ retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false );\r
\r
- var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;\r
+ // FF2: prevent focus event been bubbled up to editor container, which caused unexpected editor focus.\r
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )\r
+ ev.preventBubble();\r
+ return retVal;\r
+ });\r
\r
- var classes = '';\r
+ instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
\r
- // Get the command name.\r
- var command = this.command;\r
\r
+ // Indicate a mode sensitive button.\r
if ( this.modes )\r
{\r
- editor.on( 'mode', function()\r
+ var modeStates = {};\r
+\r
+ function updateState()\r
+ {\r
+ // "this" is a CKEDITOR.ui.button instance.\r
+\r
+ var mode = editor.mode;\r
+\r
+ if ( mode )\r
+ {\r
+ // Restore saved button state.\r
+ var state = this.modes[ mode ] ? modeStates[ mode ] != undefined ? modeStates[ mode ] :\r
+ CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;\r
+\r
+ this.setState( editor.readOnly && !this.readOnly ? CKEDITOR.TRISTATE_DISABLED : state );\r
+ }\r
+ }\r
+\r
+ editor.on( 'beforeModeUnload', function()\r
{\r
- this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );\r
- }, this);\r
+ if ( editor.mode && this._.state != CKEDITOR.TRISTATE_DISABLED )\r
+ modeStates[ editor.mode ] = this._.state;\r
+ }, this );\r
+\r
+ editor.on( 'mode', updateState, this);\r
+\r
+ // If this button is sensitive to readOnly state, update it accordingly.\r
+ !this.readOnly && editor.on( 'readOnly', updateState, this);\r
}\r
else if ( command )\r
{\r
classes += ' ' + this.className;\r
\r
output.push(\r
- '<span class="cke_button">',\r
+ '<span class="cke_button' + ( this.icon && this.icon.indexOf( '.png' ) == -1 ? ' cke_noalphafix' : '' ) + '">',\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
}\r
\r
output.push(\r
- ' onkeydown="return CKEDITOR.ui.button._.keydown(', index, ', event);"' +\r
- ' onfocus="return CKEDITOR.ui.button._.focus(', index, ', event);"' +\r
+ ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', event);"' +\r
+ ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', event);"' +\r
' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +\r
'<span class="cke_icon"' );\r
\r
}\r
\r
output.push(\r
- '></span>' +\r
- '<span class="cke_label">', this.label, '</span>' );\r
+ '> </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 ? '▼' : ' ' )\r
+ + '</span>' );\r
}\r
\r
output.push(\r
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
-\r
- if ( state == CKEDITOR.TRISTATE_DISABLED )\r
- htmlTitle = unavailable.replace( '%1', this.title );\r
+ state == CKEDITOR.TRISTATE_ON ?\r
+ element.setAttribute( 'aria-pressed', true ) :\r
+ element.removeAttribute( 'aria-pressed' );\r
\r
- labelElement.setHtml( htmlTitle );\r
+ return true;\r
}\r
-\r
- this._.state = state;\r
+ else\r
+ return false;\r
}\r
};\r
\r
-/**\r
- * Handles a button click.\r
- * @private\r
- */\r
-CKEDITOR.ui.button._ =\r
-{\r
- instances : [],\r
-\r
- keydown : function( index, ev )\r
- {\r
- var instance = CKEDITOR.ui.button._.instances[ index ];\r
-\r
- if ( instance.onkey )\r
- {\r
- ev = new CKEDITOR.dom.event( ev );\r
- return ( instance.onkey( instance, ev.getKeystroke() ) !== false );\r
- }\r
- },\r
-\r
- focus : function( index, ev )\r
- {\r
- var instance = CKEDITOR.ui.button._.instances[ index ],\r
- retVal;\r
-\r
- if ( instance.onfocus )\r
- retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false );\r
-\r
- // FF2: prevent focus event been bubbled up to editor container, which caused unexpected editor focus.\r
- if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )\r
- ev.preventBubble();\r
- return retVal;\r
- }\r
-};\r
+})();\r
\r
/**\r
* Adds a button definition to the UI elements list.\r
- * @param {String} The button name.\r
- * @param {Object} The button definition.\r
+ * @param {String} name The button name.\r
+ * @param {Object} definition The button definition.\r
* @example\r
* editorInstance.ui.addButton( 'MyBold',\r
* {\r