X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;h=765522944b9cdc39fa746910bb7d389d69f28a73;hb=f0610347140239143439a511ee2bd48cb784f470;hp=c0c8208b5c2a1c80cc7e2a46faec4a7eefd4c56c;hpb=614511639979907ceb0da3614122a4d8eb963ad4;p=ckeditor.git diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js index c0c8208..7655229 100644 --- a/_source/plugins/button/plugin.js +++ b/_source/plugins/button/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, 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 @@ -73,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; @@ -90,31 +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 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 ) { @@ -142,7 +180,7 @@ CKEDITOR.ui.button.prototype = classes += ' ' + this.className; output.push( - '', + '', '= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'", '' )+ '\')"', @@ -171,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;">' + '