X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;h=569fa928ba91ada518de54b54f4a00901e5a528b;hb=9afde8772159bd3436f1f5b7862960307710ae5a;hp=b1dca98038cc122135b09fe8143728c08842032f;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git
diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js
index b1dca98..569fa92 100644
--- a/_source/plugins/button/plugin.js
+++ b/_source/plugins/button/plugin.js
@@ -55,6 +55,45 @@ CKEDITOR.ui.button.handler =
}
};
+/**
+ * Handles a button click.
+ * @private
+ */
+CKEDITOR.ui.button._ =
+{
+ instances : [],
+
+ keydown : function( index, ev )
+ {
+ var instance = CKEDITOR.ui.button._.instances[ index ];
+
+ if ( instance.onkey )
+ {
+ ev = new CKEDITOR.dom.event( ev );
+ return ( instance.onkey( instance, ev.getKeystroke() ) !== false );
+ }
+ },
+
+ focus : function( index, ev )
+ {
+ var instance = CKEDITOR.ui.button._.instances[ index ],
+ retVal;
+
+ if ( instance.onfocus )
+ retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false );
+
+ // FF2: prevent focus event been bubbled up to editor container, which caused unexpected editor focus.
+ if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
+ ev.preventBubble();
+ return retVal;
+ }
+};
+
+( function()
+{
+ var keydownFn = CKEDITOR.tools.addFunction( CKEDITOR.ui.button._.keydown, CKEDITOR.ui.button._ ),
+ focusFn = CKEDITOR.tools.addFunction( CKEDITOR.ui.button._.focus, CKEDITOR.ui.button._ );
+
CKEDITOR.ui.button.prototype =
{
canGroup : true,
@@ -69,9 +108,13 @@ CKEDITOR.ui.button.prototype =
*/
render : function( editor, output )
{
- var env = CKEDITOR.env;
+ var env = CKEDITOR.env,
+ id = this._.id = CKEDITOR.tools.getNextId(),
+ classes = '',
+ command = this.command, // Get the command name.
+ clickFn,
+ index;
- var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber();
this._.editor = editor;
var instance =
@@ -90,20 +133,26 @@ CKEDITOR.ui.button.prototype =
}
};
- var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );
-
- var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;
-
- var classes = '';
+ instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );
- // Get the command name.
- var command = this.command;
+ instance.index = index = CKEDITOR.ui.button._.instances.push( instance ) - 1;
+ // Indicate a mode sensitive button.
if ( this.modes )
{
+ var modeStates = {};
+ editor.on( 'beforeModeUnload', function()
+ {
+ modeStates[ editor.mode ] = this._.state;
+ }, this );
+
editor.on( 'mode', function()
{
- this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
+ var mode = editor.mode;
+ // Restore saved button state.
+ this.setState( this.modes[ mode ] ?
+ modeStates[ mode ] != undefined ? modeStates[ mode ] :
+ CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
}, this);
}
else if ( command )
@@ -134,10 +183,14 @@ CKEDITOR.ui.button.prototype =
output.push(
'',
'= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'", '' )+ '\')"',
' title="', this.title, '"' +
' tabindex="-1"' +
- ' hidefocus="true"' );
+ ' hidefocus="true"' +
+ ' role="button"' +
+ ' aria-labelledby="' + id + '_label"' +
+ ( this.hasArrow ? ' aria-haspopup="true"' : '' ) );
// Some browsers don't cancel key events in the keydown but in the
// keypress.
@@ -157,8 +210,8 @@ CKEDITOR.ui.button.prototype =
}
output.push(
- ' onkeydown="return CKEDITOR.ui.button._.keydown(', index, ', event);"' +
- ' onfocus="return CKEDITOR.ui.button._.focus(', index, ', event);"' +
+ ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', ', index, ', event);"' +
+ ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', ', index, ', event);"' +
' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
'' +
- '', this.label, '' );
+ '> ' +
+ '', this.label, '' );
if ( this.hasArrow )
{
output.push(
- '' );
+ ''
+ // BLACK DOWN-POINTING TRIANGLE
+ + ( CKEDITOR.env.hc ? '▼' : ' ' )
+ + '' );
}
output.push(
@@ -191,61 +247,31 @@ CKEDITOR.ui.button.prototype =
setState : function( state )
{
if ( this._.state == state )
- return;
+ return false;
+
+ this._.state = state;
var element = CKEDITOR.document.getById( this._.id );
if ( element )
{
element.setState( state );
+ state == CKEDITOR.TRISTATE_DISABLED ?
+ element.setAttribute( 'aria-disabled', true ) :
+ element.removeAttribute( 'aria-disabled' );
- var htmlTitle = this.title,
- unavailable = this._.editor.lang.common.unavailable,
- labelElement = element.getChild( 1 );
-
- if ( state == CKEDITOR.TRISTATE_DISABLED )
- htmlTitle = unavailable.replace( '%1', this.title );
+ state == CKEDITOR.TRISTATE_ON ?
+ element.setAttribute( 'aria-pressed', true ) :
+ element.removeAttribute( 'aria-pressed' );
- labelElement.setHtml( htmlTitle );
+ return true;
}
-
- this._.state = state;
+ else
+ return false;
}
};
-/**
- * Handles a button click.
- * @private
- */
-CKEDITOR.ui.button._ =
-{
- instances : [],
-
- keydown : function( index, ev )
- {
- var instance = CKEDITOR.ui.button._.instances[ index ];
-
- if ( instance.onkey )
- {
- ev = new CKEDITOR.dom.event( ev );
- return ( instance.onkey( instance, ev.getKeystroke() ) !== false );
- }
- },
-
- focus : function( index, ev )
- {
- var instance = CKEDITOR.ui.button._.instances[ index ],
- retVal;
-
- if ( instance.onfocus )
- retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false );
-
- // FF2: prevent focus event been bubbled up to editor container, which caused unexpected editor focus.
- if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
- ev.preventBubble();
- return retVal;
- }
-};
+})();
/**
* Adds a button definition to the UI elements list.
@@ -262,3 +288,8 @@ CKEDITOR.ui.prototype.addButton = function( name, definition )
{
this.add( name, CKEDITOR.UI_BUTTON, definition );
};
+
+CKEDITOR.on( 'reset', function()
+ {
+ CKEDITOR.ui.button._.instances = [];
+ });