X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fbutton%2Fplugin.js;h=589f3f63c7334b07e2f310b67c9d6b6c5971d85b;hb=refs%2Ftags%2Fv3.5.3;hp=54016fb4518f634c048959ec6319944a7709c2fe;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/button/plugin.js b/_source/plugins/button/plugin.js index 54016fb..589f3f6 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 */ @@ -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, @@ -70,7 +109,7 @@ CKEDITOR.ui.button.prototype = render : function( editor, output ) { var env = CKEDITOR.env, - id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber(), + id = this._.id = CKEDITOR.tools.getNextId(), classes = '', command = this.command, // Get the command name. clickFn, @@ -98,11 +137,22 @@ CKEDITOR.ui.button.prototype = 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 ) @@ -131,10 +181,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"' + @@ -160,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, '' ); if ( this.hasArrow ) @@ -180,7 +230,7 @@ CKEDITOR.ui.button.prototype = output.push( '' // BLACK DOWN-POINTING TRIANGLE - + ( CKEDITOR.env.hc ? '▼' : '' ) + + ( CKEDITOR.env.hc ? '▼' : ' ' ) + '' ); } @@ -221,39 +271,7 @@ 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. @@ -270,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 = []; + });