/*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2013, 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
-/**\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
( function()\r
{\r
- var keydownFn = CKEDITOR.tools.addFunction( CKEDITOR.ui.button._.keydown, CKEDITOR.ui.button._ ),\r
- focusFn = CKEDITOR.tools.addFunction( CKEDITOR.ui.button._.focus, CKEDITOR.ui.button._ );\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
id = this._.id = CKEDITOR.tools.getNextId(),\r
classes = '',\r
command = this.command, // Get the command name.\r
- clickFn,\r
- index;\r
+ clickFn;\r
\r
this._.editor = editor;\r
\r
},\r
execute : function()\r
{\r
- this.button.click( editor );\r
+ // IE 6 needs some time before execution (#7922)\r
+ if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )\r
+ CKEDITOR.tools.setTimeout( function(){ this.button.click( editor ); }, 0, this );\r
+ else\r
+ this.button.click( editor );\r
}\r
};\r
\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
+ // 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
instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
\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
+\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
- modeStates[ editor.mode ] = this._.state;\r
+ if ( editor.mode && this._.state != CKEDITOR.TRISTATE_DISABLED )\r
+ modeStates[ editor.mode ] = this._.state;\r
}, this );\r
\r
- editor.on( 'mode', function()\r
- {\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
+ 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
}\r
\r
output.push(\r
- ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', ', index, ', event);"' +\r
- ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', ', index, ', event);"' +\r
- ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +\r
+ ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', event);"' +\r
+ ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', event);" ' +\r
+ ( CKEDITOR.env.ie ? 'onclick="return false;" onmouseup' : 'onclick' ) + // #188\r
+ '="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +\r
'<span class="cke_icon"' );\r
\r
if ( this.icon )\r
{\r
this.add( name, CKEDITOR.UI_BUTTON, definition );\r
};\r
-\r
-CKEDITOR.on( 'reset', function()\r
- {\r
- CKEDITOR.ui.button._.instances = [];\r
- });\r