2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'colordialog', function( editor )
\r
8 // Define some shorthands.
\r
9 var $el = CKEDITOR.dom.element,
\r
10 $doc = CKEDITOR.document,
\r
11 $tools = CKEDITOR.tools,
\r
12 lang = editor.lang.colordialog;
\r
14 // Reference the dialog.
\r
25 var table = new $el( 'table' );
\r
28 var cellMouseover = function( event )
\r
30 var color = new $el( event.data.getTarget() ).getAttribute( 'title' );
\r
31 $doc.getById( 'hicolor' ).setStyle( 'background-color', color );
\r
32 $doc.getById( 'hicolortext' ).setHtml( color );
\r
35 var cellClick = function( event )
\r
37 var color = new $el( event.data.getTarget() ).getAttribute( 'title' );
\r
38 dialog.getContentElement( 'picker', 'selectedColor' ).setValue( color );
\r
41 function createColorTable()
\r
43 // Create the base colors array.
\r
44 var aColors = ['00','33','66','99','cc','ff'];
\r
46 // This function combines two ranges of three values from the color array into a row.
\r
47 function appendColorRow( rangeA, rangeB )
\r
49 for ( var i = rangeA ; i < rangeA + 3 ; i++ )
\r
51 var row = table.$.insertRow(-1);
\r
53 for ( var j = rangeB ; j < rangeB + 3 ; j++ )
\r
55 for ( var n = 0 ; n < 6 ; n++ )
\r
57 appendColorCell( row, '#' + aColors[j] + aColors[n] + aColors[i] );
\r
63 // This function create a single color cell in the color table.
\r
64 function appendColorCell( targetRow, color )
\r
66 var cell = new $el( targetRow.insertCell( -1 ) );
\r
67 cell.setAttribute( 'class', 'ColorCell' );
\r
68 cell.setStyle( 'background-color', color );
\r
70 cell.setStyle( 'width', '15px' );
\r
71 cell.setStyle( 'height', '15px' );
\r
73 // Pass unparsed color value in some markup-degradable form.
\r
74 cell.setAttribute( 'title', color );
\r
77 appendColorRow( 0, 0 );
\r
78 appendColorRow( 3, 0 );
\r
79 appendColorRow( 0, 3 );
\r
80 appendColorRow( 3, 3 );
\r
82 // Create the last row.
\r
83 var oRow = table.$.insertRow(-1) ;
\r
85 // Create the gray scale colors cells.
\r
86 for ( var n = 0 ; n < 6 ; n++ )
\r
88 appendColorCell( oRow, '#' + aColors[n] + aColors[n] + aColors[n] ) ;
\r
91 // Fill the row with black cells.
\r
92 for ( var i = 0 ; i < 12 ; i++ )
\r
94 appendColorCell( oRow, '#000000' ) ;
\r
100 $doc.getById( 'selhicolor' ).removeStyle( 'background-color' );
\r
101 dialog.getContentElement( 'picker', 'selectedColor' ).setValue( '' );
\r
104 var clearActual = $tools.addFunction( function()
\r
106 $doc.getById( 'hicolor' ).removeStyle( 'background-color' );
\r
107 $doc.getById( 'hicolortext' ).setHtml( ' ' );
\r
111 title : lang.title,
\r
114 onLoad : function()
\r
116 // Update reference.
\r
122 label : lang.title,
\r
129 widths : [ '70%', '10%', '30%' ],
\r
134 html : '<table onmouseout="CKEDITOR.tools.callFunction( ' + clearActual + ' );">' + table.getHtml() + '</table>',
\r
135 onLoad : function()
\r
137 var table = CKEDITOR.document.getById( this.domId );
\r
138 table.on( 'mouseover', cellMouseover );
\r
139 table.on( 'click', cellClick );
\r
146 widths : [ '70%', '5%', '25%' ],
\r
151 html : '<span>' + lang.highlight +'</span>\
\r
152 <div id="hicolor" style="border: 1px solid; height: 74px; width: 74px;"></div>\
\r
153 <div id="hicolortext"> </div>\
\r
154 <span>' + lang.selected +'</span>\
\r
155 <div id="selhicolor" style="border: 1px solid; height: 20px; width: 74px;"></div>'
\r
159 id : 'selectedColor',
\r
160 style : 'width: 74px',
\r
161 onChange : function()
\r
163 // Try to update color preview with new value. If fails, then set it no none.
\r
166 $doc.getById( 'selhicolor' ).setStyle( 'background-color', this.getValue() );
\r
178 style : 'margin-top: 5px',
\r
179 label : lang.clear,
\r