X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;h=765522944b9cdc39fa746910bb7d389d69f28a73;hb=f0610347140239143439a511ee2bd48cb784f470;hp=b211a28c08c792ebd513f3ca0f6926b3d4d0b92d;hpb=059b4c2fef02528bf1af189f7996e80652faddfb;p=ckeditor.git diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js index b211a28..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 @@ -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 index = CKEDITOR.ui.button._.instances.push( instance ) - 1; + var focusFn = CKEDITOR.tools.addFunction( function( ev ) + { + var retVal; + + if ( instance.onfocus ) + retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false ); - var classes = ''; + // 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; + }); - // Get the command name. - var command = this.command; + instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance ); + + // 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 ) { - this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED ); - }, this); + // 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() + { + 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,10 +180,10 @@ CKEDITOR.ui.button.prototype = classes += ' ' + this.className; output.push( - '', + '', '= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'"+ '' )+ '\')"', + env.gecko && env.version >= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'", '' )+ '\')"', ' title="', this.title, '"' + ' tabindex="-1"' + ' hidefocus="true"' + @@ -161,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, '' ); if ( this.hasArrow ) { output.push( - '' ); + '' + // BLACK DOWN-POINTING TRIANGLE + + ( CKEDITOR.env.hc ? '▼' : ' ' ) + + '' ); } output.push( @@ -219,44 +271,12 @@ CKEDITOR.ui.button.prototype = } }; -/** - * 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', * {