X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;h=c9284c8d8dd2831026ed609a6dc7b2d46570d0d6;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=db982d5b2a0f1f2327a5426728bcba2d9e4e694a;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js index db982d5..c9284c8 100644 --- a/_source/plugins/button/plugin.js +++ b/_source/plugins/button/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -16,7 +16,7 @@ CKEDITOR.plugins.add( 'button', * @constant * @example */ -CKEDITOR.UI_BUTTON = 1; +CKEDITOR.UI_BUTTON = 'button'; /** * Represents a button UI element. This class should not be called directly. To @@ -55,10 +55,10 @@ CKEDITOR.ui.button.handler = } }; +( function() +{ CKEDITOR.ui.button.prototype = { - canGroup : true, - /** * Renders the button. * @param {CKEDITOR.editor} editor The editor instance which this button is @@ -69,9 +69,12 @@ 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; - var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber(); this._.editor = editor; var instance = @@ -86,25 +89,70 @@ CKEDITOR.ui.button.prototype = }, execute : function() { - this.button.click( editor ); + // IE 6 needs some time before execution (#7922) + if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 ) + CKEDITOR.tools.setTimeout( function(){ this.button.click( editor ); }, 0, this ); + else + this.button.click( editor ); } }; - var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance ); + var keydownFn = CKEDITOR.tools.addFunction( function( ev ) + { + if ( instance.onkey ) + { + ev = new CKEDITOR.dom.event( ev ); + return ( instance.onkey( instance, ev.getKeystroke() ) !== false ); + } + }); + + var focusFn = CKEDITOR.tools.addFunction( function( ev ) + { + var retVal; + + if ( instance.onfocus ) + retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false ); - var index = CKEDITOR.ui.button._.instances.push( instance ) - 1; + // 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; + }); - var classes = ''; + instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance ); - // Get the command name. - var command = this.command; + // Indicate a mode sensitive button. if ( this.modes ) { - editor.on( 'mode', function() + var modeStates = {}; + + function updateState() + { + // "this" is a CKEDITOR.ui.button instance. + + var mode = editor.mode; + + if ( mode ) + { + // Restore saved button state. + var state = this.modes[ mode ] ? modeStates[ mode ] != undefined ? modeStates[ mode ] : + CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; + + this.setState( editor.readOnly && !this.readOnly ? CKEDITOR.TRISTATE_DISABLED : state ); + } + } + + editor.on( 'beforeModeUnload', function() { - this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED ); - }, this); + if ( editor.mode && this._.state != CKEDITOR.TRISTATE_DISABLED ) + modeStates[ editor.mode ] = this._.state; + }, this ); + + editor.on( 'mode', updateState, this); + + // If this button is sensitive to readOnly state, update it accordingly. + !this.readOnly && editor.on( 'readOnly', updateState, this); } else if ( command ) { @@ -132,12 +180,16 @@ CKEDITOR.ui.button.prototype = classes += ' ' + this.className; 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,9 +209,10 @@ CKEDITOR.ui.button.prototype = } output.push( - ' onkeydown="return CKEDITOR.ui.button._.keydown(', index, ', event);"' + - ' onfocus="return CKEDITOR.ui.button._.focus(', index, ', event);"' + - ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' + + ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', event);"' + + ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', event);" ' + + ( CKEDITOR.env.ie ? 'onclick="return false;" onmouseup' : 'onclick' ) + // #188 + '="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,66 +247,36 @@ 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. - * @param {String} The button name. - * @param {Object} The button definition. + * @param {String} name The button name. + * @param {Object} definition The button definition. * @example * editorInstance.ui.addButton( 'MyBold', * {