+++ /dev/null
-/*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.html or http://ckeditor.com/license\r
-*/\r
-\r
-CKEDITOR.plugins.add( 'button',\r
-{\r
- beforeInit : function( editor )\r
- {\r
- editor.ui.addHandler( CKEDITOR.UI_BUTTON, CKEDITOR.ui.button.handler );\r
- }\r
-});\r
-\r
-/**\r
- * Button UI element.\r
- * @constant\r
- * @example\r
- */\r
-CKEDITOR.UI_BUTTON = 'button';\r
-\r
-/**\r
- * Represents a button UI element. This class should not be called directly. To\r
- * create new buttons use {@link CKEDITOR.ui.prototype.addButton} instead.\r
- * @constructor\r
- * @param {Object} definition The button definition.\r
- * @example\r
- */\r
-CKEDITOR.ui.button = function( definition )\r
-{\r
- // Copy all definition properties to this object.\r
- CKEDITOR.tools.extend( this, definition,\r
- // Set defaults.\r
- {\r
- title : definition.label,\r
- className : definition.className || ( definition.command && 'cke_button_' + definition.command ) || '',\r
- click : definition.click || function( editor )\r
- {\r
- editor.execCommand( definition.command );\r
- }\r
- });\r
-\r
- this._ = {};\r
-};\r
-\r
-/**\r
- * Transforms a button definition in a {@link CKEDITOR.ui.button} instance.\r
- * @type Object\r
- * @example\r
- */\r
-CKEDITOR.ui.button.handler =\r
-{\r
- create : function( definition )\r
- {\r
- return new CKEDITOR.ui.button( definition );\r
- }\r
-};\r
-\r
-( function()\r
-{\r
-CKEDITOR.ui.button.prototype =\r
-{\r
- /**\r
- * Renders the button.\r
- * @param {CKEDITOR.editor} editor The editor instance which this button is\r
- * to be used by.\r
- * @param {Array} output The output array to which append the HTML relative\r
- * to this button.\r
- * @example\r
- */\r
- render : function( editor, output )\r
- {\r
- var env = CKEDITOR.env,\r
- id = this._.id = CKEDITOR.tools.getNextId(),\r
- classes = '',\r
- command = this.command, // Get the command name.\r
- clickFn;\r
-\r
- this._.editor = editor;\r
-\r
- var instance =\r
- {\r
- id : id,\r
- button : this,\r
- editor : editor,\r
- focus : function()\r
- {\r
- var element = CKEDITOR.document.getById( id );\r
- element.focus();\r
- },\r
- execute : function()\r
- {\r
- // IE 6 needs some time before execution (#7922)\r
- if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )\r
- CKEDITOR.tools.setTimeout( function(){ this.button.click( editor ); }, 0, this );\r
- else\r
- this.button.click( editor );\r
- }\r
- };\r
-\r
- var keydownFn = CKEDITOR.tools.addFunction( function( ev )\r
- {\r
- if ( instance.onkey )\r
- {\r
- ev = new CKEDITOR.dom.event( ev );\r
- return ( instance.onkey( instance, ev.getKeystroke() ) !== false );\r
- }\r
- });\r
-\r
- var focusFn = CKEDITOR.tools.addFunction( function( ev )\r
- {\r
- var retVal;\r
-\r
- if ( instance.onfocus )\r
- retVal = ( instance.onfocus( instance, new CKEDITOR.dom.event( ev ) ) !== false );\r
-\r
- // FF2: prevent focus event been bubbled up to editor container, which caused unexpected editor focus.\r
- if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )\r
- ev.preventBubble();\r
- return retVal;\r
- });\r
-\r
- instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );\r
-\r
-\r
- // Indicate a mode sensitive button.\r
- if ( this.modes )\r
- {\r
- var modeStates = {};\r
-\r
- function updateState()\r
- {\r
- // "this" is a CKEDITOR.ui.button instance.\r
-\r
- var mode = editor.mode;\r
-\r
- if ( mode )\r
- {\r
- // Restore saved button state.\r
- var state = this.modes[ mode ] ? modeStates[ mode ] != undefined ? modeStates[ mode ] :\r
- CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;\r
-\r
- this.setState( editor.readOnly && !this.readOnly ? CKEDITOR.TRISTATE_DISABLED : state );\r
- }\r
- }\r
-\r
- editor.on( 'beforeModeUnload', function()\r
- {\r
- if ( editor.mode && this._.state != CKEDITOR.TRISTATE_DISABLED )\r
- modeStates[ editor.mode ] = this._.state;\r
- }, this );\r
-\r
- editor.on( 'mode', updateState, this);\r
-\r
- // If this button is sensitive to readOnly state, update it accordingly.\r
- !this.readOnly && editor.on( 'readOnly', updateState, this);\r
- }\r
- else if ( command )\r
- {\r
- // Get the command instance.\r
- command = editor.getCommand( command );\r
-\r
- if ( command )\r
- {\r
- command.on( 'state', function()\r
- {\r
- this.setState( command.state );\r
- }, this);\r
-\r
- classes += 'cke_' + (\r
- command.state == CKEDITOR.TRISTATE_ON ? 'on' :\r
- command.state == CKEDITOR.TRISTATE_DISABLED ? 'disabled' :\r
- 'off' );\r
- }\r
- }\r
-\r
- if ( !command )\r
- classes += 'cke_off';\r
-\r
- if ( this.className )\r
- classes += ' ' + this.className;\r
-\r
- output.push(\r
- '<span class="cke_button' + ( this.icon && this.icon.indexOf( '.png' ) == -1 ? ' cke_noalphafix' : '' ) + '">',\r
- '<a id="', id, '"' +\r
- ' class="', classes, '"',\r
- env.gecko && env.version >= 10900 && !env.hc ? '' : '" href="javascript:void(\''+ ( this.title || '' ).replace( "'", '' )+ '\')"',\r
- ' title="', this.title, '"' +\r
- ' tabindex="-1"' +\r
- ' hidefocus="true"' +\r
- ' role="button"' +\r
- ' aria-labelledby="' + id + '_label"' +\r
- ( this.hasArrow ? ' aria-haspopup="true"' : '' ) );\r
-\r
- // Some browsers don't cancel key events in the keydown but in the\r
- // keypress.\r
- // TODO: Check if really needed for Gecko+Mac.\r
- if ( env.opera || ( env.gecko && env.mac ) )\r
- {\r
- output.push(\r
- ' onkeypress="return false;"' );\r
- }\r
-\r
- // With Firefox, we need to force the button to redraw, otherwise it\r
- // will remain in the focus state.\r
- if ( env.gecko )\r
- {\r
- output.push(\r
- ' onblur="this.style.cssText = this.style.cssText;"' );\r
- }\r
-\r
- output.push(\r
- ' onkeydown="return CKEDITOR.tools.callFunction(', keydownFn, ', event);"' +\r
- ' onfocus="return CKEDITOR.tools.callFunction(', focusFn,', event);" ' +\r
- ( CKEDITOR.env.ie ? 'onclick="return false;" onmouseup' : 'onclick' ) + // #188\r
- '="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +\r
- '<span class="cke_icon"' );\r
-\r
- if ( this.icon )\r
- {\r
- var offset = ( this.iconOffset || 0 ) * -16;\r
- output.push( ' style="background-image:url(', CKEDITOR.getUrl( this.icon ), ');background-position:0 ' + offset + 'px;"' );\r
- }\r
-\r
- output.push(\r
- '> </span>' +\r
- '<span id="', id, '_label" class="cke_label">', this.label, '</span>' );\r
-\r
- if ( this.hasArrow )\r
- {\r
- output.push(\r
- '<span class="cke_buttonarrow">'\r
- // BLACK DOWN-POINTING TRIANGLE\r
- + ( CKEDITOR.env.hc ? '▼' : ' ' )\r
- + '</span>' );\r
- }\r
-\r
- output.push(\r
- '</a>',\r
- '</span>' );\r
-\r
- if ( this.onRender )\r
- this.onRender();\r
-\r
- return instance;\r
- },\r
-\r
- setState : function( state )\r
- {\r
- if ( this._.state == state )\r
- return false;\r
-\r
- this._.state = state;\r
-\r
- var element = CKEDITOR.document.getById( this._.id );\r
-\r
- if ( element )\r
- {\r
- element.setState( state );\r
- state == CKEDITOR.TRISTATE_DISABLED ?\r
- element.setAttribute( 'aria-disabled', true ) :\r
- element.removeAttribute( 'aria-disabled' );\r
-\r
- state == CKEDITOR.TRISTATE_ON ?\r
- element.setAttribute( 'aria-pressed', true ) :\r
- element.removeAttribute( 'aria-pressed' );\r
-\r
- return true;\r
- }\r
- else\r
- return false;\r
- }\r
-};\r
-\r
-})();\r
-\r
-/**\r
- * Adds a button definition to the UI elements list.\r
- * @param {String} name The button name.\r
- * @param {Object} definition The button definition.\r
- * @example\r
- * editorInstance.ui.addButton( 'MyBold',\r
- * {\r
- * label : 'My Bold',\r
- * command : 'bold'\r
- * });\r
- */\r
-CKEDITOR.ui.prototype.addButton = function( name, definition )\r
-{\r
- this.add( name, CKEDITOR.UI_BUTTON, definition );\r
-};\r