X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;fp=_source%2Fplugins%2Fbutton%2Fplugin.js;h=80c48c1c7725254c7665fabef54af2b086eb52a0;hb=4e70ea24db840898be8cc21c950363a52a2a6aba;hp=a5bbccbac412e64aa0282e94feff998fddd19704;hpb=1056598c95187351dc58f4991d331e2258d038b5;p=ckeditor.git diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js index a5bbccb..80c48c1 100644 --- a/_source/plugins/button/plugin.js +++ b/_source/plugins/button/plugin.js @@ -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,49 +55,10 @@ 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, - /** * Renders the button. * @param {CKEDITOR.editor} editor The editor instance which this button is @@ -112,8 +73,7 @@ CKEDITOR.ui.button.prototype = id = this._.id = CKEDITOR.tools.getNextId(), classes = '', command = this.command, // Get the command name. - clickFn, - index; + clickFn; this._.editor = editor; @@ -133,27 +93,62 @@ CKEDITOR.ui.button.prototype = } }; + 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 ); + + // 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; + }); + instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance ); - instance.index = index = CKEDITOR.ui.button._.instances.push( instance ) - 1; // Indicate a mode sensitive button. if ( this.modes ) { 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() { - modeStates[ editor.mode ] = this._.state; + if ( editor.mode && this._.state != CKEDITOR.TRISTATE_DISABLED ) + modeStates[ editor.mode ] = this._.state; }, this ); - editor.on( 'mode', function() - { - 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); + 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 ) { @@ -210,8 +205,8 @@ CKEDITOR.ui.button.prototype = } output.push( - ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', ', index, ', event);"' + - ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', ', index, ', event);"' + + ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', event);"' + + ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', event);"' + ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' + '