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.dialog.add( 'colordialog', function( editor )
|
---|
7 | {
|
---|
8 | // Define some shorthands.
|
---|
9 | var $el = CKEDITOR.dom.element,
|
---|
10 | $doc = CKEDITOR.document,
|
---|
11 | $tools = CKEDITOR.tools,
|
---|
12 | lang = editor.lang.colordialog;
|
---|
13 |
|
---|
14 | // Reference the dialog.
|
---|
15 | var dialog;
|
---|
16 |
|
---|
17 | function spacer()
|
---|
18 | {
|
---|
19 | return {
|
---|
20 | type : 'html',
|
---|
21 | html : ' '
|
---|
22 | };
|
---|
23 | }
|
---|
24 |
|
---|
25 | var table = new $el( 'table' );
|
---|
26 | createColorTable();
|
---|
27 |
|
---|
28 | var cellMouseover = function( event )
|
---|
29 | {
|
---|
30 | var color = new $el( event.data.getTarget() ).getAttribute( 'title' );
|
---|
31 | $doc.getById( 'hicolor' ).setStyle( 'background-color', color );
|
---|
32 | $doc.getById( 'hicolortext' ).setHtml( color );
|
---|
33 | };
|
---|
34 |
|
---|
35 | var cellClick = function( event )
|
---|
36 | {
|
---|
37 | var color = new $el( event.data.getTarget() ).getAttribute( 'title' );
|
---|
38 | dialog.getContentElement( 'picker', 'selectedColor' ).setValue( color );
|
---|
39 | };
|
---|
40 |
|
---|
41 | function createColorTable()
|
---|
42 | {
|
---|
43 | // Create the base colors array.
|
---|
44 | var aColors = ['00','33','66','99','cc','ff'];
|
---|
45 |
|
---|
46 | // This function combines two ranges of three values from the color array into a row.
|
---|
47 | function appendColorRow( rangeA, rangeB )
|
---|
48 | {
|
---|
49 | for ( var i = rangeA ; i < rangeA + 3 ; i++ )
|
---|
50 | {
|
---|
51 | var row = table.$.insertRow(-1);
|
---|
52 |
|
---|
53 | for ( var j = rangeB ; j < rangeB + 3 ; j++ )
|
---|
54 | {
|
---|
55 | for ( var n = 0 ; n < 6 ; n++ )
|
---|
56 | {
|
---|
57 | appendColorCell( row, '#' + aColors[j] + aColors[n] + aColors[i] );
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | // This function create a single color cell in the color table.
|
---|
64 | function appendColorCell( targetRow, color )
|
---|
65 | {
|
---|
66 | var cell = new $el( targetRow.insertCell( -1 ) );
|
---|
67 | cell.setAttribute( 'class', 'ColorCell' );
|
---|
68 | cell.setStyle( 'background-color', color );
|
---|
69 |
|
---|
70 | cell.setStyle( 'width', '15px' );
|
---|
71 | cell.setStyle( 'height', '15px' );
|
---|
72 |
|
---|
73 | // Pass unparsed color value in some markup-degradable form.
|
---|
74 | cell.setAttribute( 'title', color );
|
---|
75 | }
|
---|
76 |
|
---|
77 | appendColorRow( 0, 0 );
|
---|
78 | appendColorRow( 3, 0 );
|
---|
79 | appendColorRow( 0, 3 );
|
---|
80 | appendColorRow( 3, 3 );
|
---|
81 |
|
---|
82 | // Create the last row.
|
---|
83 | var oRow = table.$.insertRow(-1) ;
|
---|
84 |
|
---|
85 | // Create the gray scale colors cells.
|
---|
86 | for ( var n = 0 ; n < 6 ; n++ )
|
---|
87 | {
|
---|
88 | appendColorCell( oRow, '#' + aColors[n] + aColors[n] + aColors[n] ) ;
|
---|
89 | }
|
---|
90 |
|
---|
91 | // Fill the row with black cells.
|
---|
92 | for ( var i = 0 ; i < 12 ; i++ )
|
---|
93 | {
|
---|
94 | appendColorCell( oRow, '#000000' ) ;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | function clear()
|
---|
99 | {
|
---|
100 | $doc.getById( 'selhicolor' ).removeStyle( 'background-color' );
|
---|
101 | dialog.getContentElement( 'picker', 'selectedColor' ).setValue( '' );
|
---|
102 | }
|
---|
103 |
|
---|
104 | var clearActual = $tools.addFunction( function()
|
---|
105 | {
|
---|
106 | $doc.getById( 'hicolor' ).removeStyle( 'background-color' );
|
---|
107 | $doc.getById( 'hicolortext' ).setHtml( ' ' );
|
---|
108 | } );
|
---|
109 |
|
---|
110 | return {
|
---|
111 | title : lang.title,
|
---|
112 | minWidth : 360,
|
---|
113 | minHeight : 220,
|
---|
114 | onLoad : function()
|
---|
115 | {
|
---|
116 | // Update reference.
|
---|
117 | dialog = this;
|
---|
118 | },
|
---|
119 | contents : [
|
---|
120 | {
|
---|
121 | id : 'picker',
|
---|
122 | label : lang.title,
|
---|
123 | accessKey : 'I',
|
---|
124 | elements :
|
---|
125 | [
|
---|
126 | {
|
---|
127 | type : 'hbox',
|
---|
128 | padding : 0,
|
---|
129 | widths : [ '70%', '10%', '30%' ],
|
---|
130 | children :
|
---|
131 | [
|
---|
132 | {
|
---|
133 | type : 'html',
|
---|
134 | html : '<table onmouseout="CKEDITOR.tools.callFunction( ' + clearActual + ' );">' + table.getHtml() + '</table>',
|
---|
135 | onLoad : function()
|
---|
136 | {
|
---|
137 | var table = CKEDITOR.document.getById( this.domId );
|
---|
138 | table.on( 'mouseover', cellMouseover );
|
---|
139 | table.on( 'click', cellClick );
|
---|
140 | }
|
---|
141 | },
|
---|
142 | spacer(),
|
---|
143 | {
|
---|
144 | type : 'vbox',
|
---|
145 | padding : 0,
|
---|
146 | widths : [ '70%', '5%', '25%' ],
|
---|
147 | children :
|
---|
148 | [
|
---|
149 | {
|
---|
150 | type : 'html',
|
---|
151 | html : '<span>' + lang.highlight +'</span>\
|
---|
152 | <div id="hicolor" style="border: 1px solid; height: 74px; width: 74px;"></div>\
|
---|
153 | <div id="hicolortext"> </div>\
|
---|
154 | <span>' + lang.selected +'</span>\
|
---|
155 | <div id="selhicolor" style="border: 1px solid; height: 20px; width: 74px;"></div>'
|
---|
156 | },
|
---|
157 | {
|
---|
158 | type : 'text',
|
---|
159 | id : 'selectedColor',
|
---|
160 | style : 'width: 74px',
|
---|
161 | onChange : function()
|
---|
162 | {
|
---|
163 | // Try to update color preview with new value. If fails, then set it no none.
|
---|
164 | try
|
---|
165 | {
|
---|
166 | $doc.getById( 'selhicolor' ).setStyle( 'background-color', this.getValue() );
|
---|
167 | }
|
---|
168 | catch ( e )
|
---|
169 | {
|
---|
170 | clear();
|
---|
171 | }
|
---|
172 | }
|
---|
173 | },
|
---|
174 | spacer(),
|
---|
175 | {
|
---|
176 | type : 'button',
|
---|
177 | id : 'clear',
|
---|
178 | style : 'margin-top: 5px',
|
---|
179 | label : lang.clear,
|
---|
180 | onClick : clear
|
---|
181 | }
|
---|
182 | ]
|
---|
183 | }
|
---|
184 | ]
|
---|
185 | }
|
---|
186 | ]
|
---|
187 | }
|
---|
188 | ]
|
---|
189 | };
|
---|
190 | }
|
---|
191 | );
|
---|