[2000] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | CKEDITOR.plugins.add( 'colorbutton',
|
---|
| 7 | {
|
---|
| 8 | requires : [ 'panelbutton', 'floatpanel', 'styles' ],
|
---|
| 9 |
|
---|
| 10 | init : function( editor )
|
---|
| 11 | {
|
---|
| 12 | var config = editor.config,
|
---|
| 13 | lang = editor.lang.colorButton;
|
---|
| 14 |
|
---|
| 15 | var clickFn;
|
---|
| 16 |
|
---|
| 17 | if ( !CKEDITOR.env.hc )
|
---|
| 18 | {
|
---|
| 19 | addButton( 'TextColor', 'fore', lang.textColorTitle );
|
---|
| 20 | addButton( 'BGColor', 'back', lang.bgColorTitle );
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | function addButton( name, type, title )
|
---|
| 24 | {
|
---|
| 25 | editor.ui.add( name, CKEDITOR.UI_PANELBUTTON,
|
---|
| 26 | {
|
---|
| 27 | label : title,
|
---|
| 28 | title : title,
|
---|
| 29 | className : 'cke_button_' + name.toLowerCase(),
|
---|
| 30 | modes : { wysiwyg : 1 },
|
---|
| 31 |
|
---|
| 32 | panel :
|
---|
| 33 | {
|
---|
| 34 | css : [ CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ]
|
---|
| 35 | },
|
---|
| 36 |
|
---|
| 37 | onBlock : function( panel, blockName )
|
---|
| 38 | {
|
---|
| 39 | var block = panel.addBlock( blockName );
|
---|
| 40 | block.autoSize = true;
|
---|
| 41 | block.element.addClass( 'cke_colorblock' );
|
---|
| 42 | block.element.setHtml( renderColors( panel, type ) );
|
---|
| 43 |
|
---|
| 44 | var keys = block.keys;
|
---|
| 45 | keys[ 39 ] = 'next'; // ARROW-RIGHT
|
---|
| 46 | keys[ 9 ] = 'next'; // TAB
|
---|
| 47 | keys[ 37 ] = 'prev'; // ARROW-LEFT
|
---|
| 48 | keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB
|
---|
| 49 | keys[ 32 ] = 'click'; // SPACE
|
---|
| 50 | }
|
---|
| 51 | });
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | function renderColors( panel, type )
|
---|
| 56 | {
|
---|
| 57 | var output = [],
|
---|
| 58 | colors = config.colorButton_colors.split( ',' );
|
---|
| 59 |
|
---|
| 60 | var clickFn = CKEDITOR.tools.addFunction( function( color, type )
|
---|
| 61 | {
|
---|
| 62 | if ( color == '?' )
|
---|
| 63 | {
|
---|
| 64 | // TODO : Implement the colors dialog.
|
---|
| 65 | // editor.openDialog( '' );
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | editor.focus();
|
---|
| 70 |
|
---|
| 71 | panel.hide();
|
---|
| 72 |
|
---|
| 73 | var style = new CKEDITOR.style( config['colorButton_' + type + 'Style'], color && { color : color } );
|
---|
| 74 |
|
---|
| 75 | editor.fire( 'saveSnapshot' );
|
---|
| 76 | if ( color )
|
---|
| 77 | style.apply( editor.document );
|
---|
| 78 | else
|
---|
| 79 | style.remove( editor.document );
|
---|
| 80 | editor.fire( 'saveSnapshot' );
|
---|
| 81 | });
|
---|
| 82 |
|
---|
| 83 | // Render the "Automatic" button.
|
---|
| 84 | output.push(
|
---|
| 85 | '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
|
---|
| 86 | ' title="', lang.auto, '"' +
|
---|
| 87 | ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
|
---|
| 88 | ' href="javascript:void(\'', lang.auto, '\')">' +
|
---|
| 89 | '<table cellspacing=0 cellpadding=0 width="100%">' +
|
---|
| 90 | '<tr>' +
|
---|
| 91 | '<td>' +
|
---|
| 92 | '<span class="cke_colorbox" style="background-color:#000"></span>' +
|
---|
| 93 | '</td>' +
|
---|
| 94 | '<td colspan=7 align=center>',
|
---|
| 95 | lang.auto,
|
---|
| 96 | '</td>' +
|
---|
| 97 | '</tr>' +
|
---|
| 98 | '</table>' +
|
---|
| 99 | '</a>' +
|
---|
| 100 | '<table cellspacing=0 cellpadding=0 width="100%">' );
|
---|
| 101 |
|
---|
| 102 | // Render the color boxes.
|
---|
| 103 | for ( var i = 0 ; i < colors.length ; i++ )
|
---|
| 104 | {
|
---|
| 105 | if ( ( i % 8 ) === 0 )
|
---|
| 106 | output.push( '</tr><tr>' );
|
---|
| 107 |
|
---|
| 108 | var colorCode = colors[ i ];
|
---|
| 109 | var colorLabel = editor.lang.colors[ colorCode ] || colorCode;
|
---|
| 110 | output.push(
|
---|
| 111 | '<td>' +
|
---|
| 112 | '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' +
|
---|
| 113 | ' title="', colorLabel, '"' +
|
---|
| 114 | ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'#', colorCode, '\',\'', type, '\'); return false;"' +
|
---|
| 115 | ' href="javascript:void(\'', colorLabel, '\')">' +
|
---|
| 116 | '<span class="cke_colorbox" style="background-color:#', colorCode, '"></span>' +
|
---|
| 117 | '</a>' +
|
---|
| 118 | '</td>' );
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | // Render the "More Colors" button.
|
---|
| 122 | if ( config.colorButton_enableMore )
|
---|
| 123 | {
|
---|
| 124 | output.push(
|
---|
| 125 | '</tr>' +
|
---|
| 126 | '<tr>' +
|
---|
| 127 | '<td colspan=8 align=center>' +
|
---|
| 128 | '<a class="cke_colormore" _cke_focus=1 hidefocus=true' +
|
---|
| 129 | ' title="', lang.more, '"' +
|
---|
| 130 | ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'?\',\'', type, '\');return false;"' +
|
---|
| 131 | ' href="javascript:void(\'', lang.more, '\')">',
|
---|
| 132 | lang.more,
|
---|
| 133 | '</a>' +
|
---|
| 134 | '</td>' ); // It is later in the code.
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | output.push( '</tr></table>' );
|
---|
| 138 |
|
---|
| 139 | return output.join( '' );
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | });
|
---|
| 143 |
|
---|
| 144 | /**
|
---|
| 145 | * Whether to enable the "More Colors..." button in the color selectors.
|
---|
| 146 | * @default false
|
---|
| 147 | * @type Boolean
|
---|
| 148 | * @example
|
---|
| 149 | * config.colorButton_enableMore = false;
|
---|
| 150 | */
|
---|
| 151 | CKEDITOR.config.colorButton_enableMore = false;
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
| 154 | * Defines the colors to be displayed in the color selectors. It's a string
|
---|
| 155 | * containing the hexadecimal notation for HTML colors, without the "#" prefix.
|
---|
| 156 | * @type String
|
---|
| 157 | * @default '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF'
|
---|
| 158 | * @example
|
---|
| 159 | * // Brazil colors only.
|
---|
| 160 | * config.colorButton_colors = '00923E,F8C100,28166F';
|
---|
| 161 | */
|
---|
| 162 | CKEDITOR.config.colorButton_colors =
|
---|
| 163 | '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
|
---|
| 164 | 'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
|
---|
| 165 | 'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
|
---|
| 166 | 'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
|
---|
| 167 | 'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * Holds the style definition to be used to apply the text foreground color.
|
---|
| 171 | * @type Object
|
---|
| 172 | * @example
|
---|
| 173 | * // This is basically the default setting value.
|
---|
| 174 | * config.colorButton_foreStyle =
|
---|
| 175 | * {
|
---|
| 176 | * element : 'span',
|
---|
| 177 | * styles : { 'color' : '#(color)' }
|
---|
| 178 | * };
|
---|
| 179 | */
|
---|
| 180 | CKEDITOR.config.colorButton_foreStyle =
|
---|
| 181 | {
|
---|
| 182 | element : 'span',
|
---|
| 183 | styles : { 'color' : '#(color)' },
|
---|
| 184 | overrides : [ { element : 'font', attributes : { 'color' : null } } ]
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
| 188 | * Holds the style definition to be used to apply the text background color.
|
---|
| 189 | * @type Object
|
---|
| 190 | * @example
|
---|
| 191 | * // This is basically the default setting value.
|
---|
| 192 | * config.colorButton_backStyle =
|
---|
| 193 | * {
|
---|
| 194 | * element : 'span',
|
---|
| 195 | * styles : { 'background-color' : '#(color)' }
|
---|
| 196 | * };
|
---|
| 197 | */
|
---|
| 198 | CKEDITOR.config.colorButton_backStyle =
|
---|
| 199 | {
|
---|
| 200 | element : 'span',
|
---|
| 201 | styles : { 'background-color' : '#(color)' }
|
---|
| 202 | };
|
---|