JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.4
[ckeditor.git] / _source / plugins / button / plugin.js
index b211a28..a5bbccb 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -55,6 +55,45 @@ CKEDITOR.ui.button.handler =
        }\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
@@ -69,9 +108,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 +133,26 @@ CKEDITOR.ui.button.prototype =
                        }\r
                };\r
 \r
-               var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
-\r
-               var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;\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
+               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
@@ -132,10 +181,10 @@ CKEDITOR.ui.button.prototype =
                        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
@@ -161,8 +210,8 @@ CKEDITOR.ui.button.prototype =
                }\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
@@ -173,13 +222,16 @@ CKEDITOR.ui.button.prototype =
                }\r
 \r
                output.push(\r
-                                       '></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
@@ -219,44 +271,12 @@ CKEDITOR.ui.button.prototype =
        }\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
@@ -268,3 +288,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