/*\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
}\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
render : function( editor, output )\r
{\r
var env = CKEDITOR.env,\r
- id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber(),\r
+ id = this._.id = CKEDITOR.tools.getNextId(),\r
classes = '',\r
command = this.command, // Get the command name.\r
clickFn,\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
+ 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
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, '"',\r
- env.gecko && env.version >= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'"+ '' )+ '\')"',\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
}\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, ', ', index, ', event);"' +\r
+ ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', ', index, ', 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>' +\r
'<span id="', id, '_label" class="cke_label">', this.label, '</span>' );\r
\r
if ( this.hasArrow )\r
output.push(\r
'<span class="cke_buttonarrow">'\r
// BLACK DOWN-POINTING TRIANGLE\r
- + ( CKEDITOR.env.hc ? '▼' : '' )\r
+ + ( CKEDITOR.env.hc ? '▼' : ' ' )\r
+ '</span>' );\r
}\r
\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
{\r
this.add( name, CKEDITOR.UI_BUTTON, definition );\r
};\r
+\r
+CKEDITOR.on( 'reset', function()\r
+ {\r
+ CKEDITOR.ui.button._.instances = [];\r
+ });\r