~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/js/tinymce/themes/advanced/js/color_picker.js

  • Committer: Paul Collins
  • Date: 2011-07-13 02:31:10 UTC
  • Revision ID: paul.collins@canonical.com-20110713023110-rvp7cjj31rsaomkr
import Wordpress 3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
tinyMCEPopup.requireLangPack();
2
2
 
3
 
var detail = 50, strhex = "0123456789abcdef", i, isMouseDown = false, isMouseOver = false;
 
3
var detail = 50, strhex = "0123456789ABCDEF", i, isMouseDown = false, isMouseOver = false;
4
4
 
5
5
var colors = [
6
6
        "#000000","#000033","#000066","#000099","#0000cc","#0000ff","#330000","#330033",
33
33
];
34
34
 
35
35
var named = {
36
 
        '#F0F8FF':'AliceBlue','#FAEBD7':'AntiqueWhite','#00FFFF':'Aqua','#7FFFD4':'Aquamarine','#F0FFFF':'Azure','#F5F5DC':'Beige',
37
 
        '#FFE4C4':'Bisque','#000000':'Black','#FFEBCD':'BlanchedAlmond','#0000FF':'Blue','#8A2BE2':'BlueViolet','#A52A2A':'Brown',
38
 
        '#DEB887':'BurlyWood','#5F9EA0':'CadetBlue','#7FFF00':'Chartreuse','#D2691E':'Chocolate','#FF7F50':'Coral','#6495ED':'CornflowerBlue',
39
 
        '#FFF8DC':'Cornsilk','#DC143C':'Crimson','#00FFFF':'Cyan','#00008B':'DarkBlue','#008B8B':'DarkCyan','#B8860B':'DarkGoldenRod',
40
 
        '#A9A9A9':'DarkGray','#A9A9A9':'DarkGrey','#006400':'DarkGreen','#BDB76B':'DarkKhaki','#8B008B':'DarkMagenta','#556B2F':'DarkOliveGreen',
41
 
        '#FF8C00':'Darkorange','#9932CC':'DarkOrchid','#8B0000':'DarkRed','#E9967A':'DarkSalmon','#8FBC8F':'DarkSeaGreen','#483D8B':'DarkSlateBlue',
42
 
        '#2F4F4F':'DarkSlateGray','#2F4F4F':'DarkSlateGrey','#00CED1':'DarkTurquoise','#9400D3':'DarkViolet','#FF1493':'DeepPink','#00BFFF':'DeepSkyBlue',
43
 
        '#696969':'DimGray','#696969':'DimGrey','#1E90FF':'DodgerBlue','#B22222':'FireBrick','#FFFAF0':'FloralWhite','#228B22':'ForestGreen',
44
 
        '#FF00FF':'Fuchsia','#DCDCDC':'Gainsboro','#F8F8FF':'GhostWhite','#FFD700':'Gold','#DAA520':'GoldenRod','#808080':'Gray','#808080':'Grey',
45
 
        '#008000':'Green','#ADFF2F':'GreenYellow','#F0FFF0':'HoneyDew','#FF69B4':'HotPink','#CD5C5C':'IndianRed','#4B0082':'Indigo','#FFFFF0':'Ivory',
46
 
        '#F0E68C':'Khaki','#E6E6FA':'Lavender','#FFF0F5':'LavenderBlush','#7CFC00':'LawnGreen','#FFFACD':'LemonChiffon','#ADD8E6':'LightBlue',
47
 
        '#F08080':'LightCoral','#E0FFFF':'LightCyan','#FAFAD2':'LightGoldenRodYellow','#D3D3D3':'LightGray','#D3D3D3':'LightGrey','#90EE90':'LightGreen',
48
 
        '#FFB6C1':'LightPink','#FFA07A':'LightSalmon','#20B2AA':'LightSeaGreen','#87CEFA':'LightSkyBlue','#778899':'LightSlateGray','#778899':'LightSlateGrey',
49
 
        '#B0C4DE':'LightSteelBlue','#FFFFE0':'LightYellow','#00FF00':'Lime','#32CD32':'LimeGreen','#FAF0E6':'Linen','#FF00FF':'Magenta','#800000':'Maroon',
50
 
        '#66CDAA':'MediumAquaMarine','#0000CD':'MediumBlue','#BA55D3':'MediumOrchid','#9370D8':'MediumPurple','#3CB371':'MediumSeaGreen','#7B68EE':'MediumSlateBlue',
51
 
        '#00FA9A':'MediumSpringGreen','#48D1CC':'MediumTurquoise','#C71585':'MediumVioletRed','#191970':'MidnightBlue','#F5FFFA':'MintCream','#FFE4E1':'MistyRose','#FFE4B5':'Moccasin',
52
 
        '#FFDEAD':'NavajoWhite','#000080':'Navy','#FDF5E6':'OldLace','#808000':'Olive','#6B8E23':'OliveDrab','#FFA500':'Orange','#FF4500':'OrangeRed','#DA70D6':'Orchid',
53
 
        '#EEE8AA':'PaleGoldenRod','#98FB98':'PaleGreen','#AFEEEE':'PaleTurquoise','#D87093':'PaleVioletRed','#FFEFD5':'PapayaWhip','#FFDAB9':'PeachPuff',
54
 
        '#CD853F':'Peru','#FFC0CB':'Pink','#DDA0DD':'Plum','#B0E0E6':'PowderBlue','#800080':'Purple','#FF0000':'Red','#BC8F8F':'RosyBrown','#4169E1':'RoyalBlue',
55
 
        '#8B4513':'SaddleBrown','#FA8072':'Salmon','#F4A460':'SandyBrown','#2E8B57':'SeaGreen','#FFF5EE':'SeaShell','#A0522D':'Sienna','#C0C0C0':'Silver',
56
 
        '#87CEEB':'SkyBlue','#6A5ACD':'SlateBlue','#708090':'SlateGray','#708090':'SlateGrey','#FFFAFA':'Snow','#00FF7F':'SpringGreen',
57
 
        '#4682B4':'SteelBlue','#D2B48C':'Tan','#008080':'Teal','#D8BFD8':'Thistle','#FF6347':'Tomato','#40E0D0':'Turquoise','#EE82EE':'Violet',
58
 
        '#F5DEB3':'Wheat','#FFFFFF':'White','#F5F5F5':'WhiteSmoke','#FFFF00':'Yellow','#9ACD32':'YellowGreen'
 
36
        '#F0F8FF':'Alice Blue','#FAEBD7':'Antique White','#00FFFF':'Aqua','#7FFFD4':'Aquamarine','#F0FFFF':'Azure','#F5F5DC':'Beige',
 
37
        '#FFE4C4':'Bisque','#000000':'Black','#FFEBCD':'Blanched Almond','#0000FF':'Blue','#8A2BE2':'Blue Violet','#A52A2A':'Brown',
 
38
        '#DEB887':'Burly Wood','#5F9EA0':'Cadet Blue','#7FFF00':'Chartreuse','#D2691E':'Chocolate','#FF7F50':'Coral','#6495ED':'Cornflower Blue',
 
39
        '#FFF8DC':'Cornsilk','#DC143C':'Crimson','#00FFFF':'Cyan','#00008B':'Dark Blue','#008B8B':'Dark Cyan','#B8860B':'Dark Golden Rod',
 
40
        '#A9A9A9':'Dark Gray','#A9A9A9':'Dark Grey','#006400':'Dark Green','#BDB76B':'Dark Khaki','#8B008B':'Dark Magenta','#556B2F':'Dark Olive Green',
 
41
        '#FF8C00':'Darkorange','#9932CC':'Dark Orchid','#8B0000':'Dark Red','#E9967A':'Dark Salmon','#8FBC8F':'Dark Sea Green','#483D8B':'Dark Slate Blue',
 
42
        '#2F4F4F':'Dark Slate Gray','#2F4F4F':'Dark Slate Grey','#00CED1':'Dark Turquoise','#9400D3':'Dark Violet','#FF1493':'Deep Pink','#00BFFF':'Deep Sky Blue',
 
43
        '#696969':'Dim Gray','#696969':'Dim Grey','#1E90FF':'Dodger Blue','#B22222':'Fire Brick','#FFFAF0':'Floral White','#228B22':'Forest Green',
 
44
        '#FF00FF':'Fuchsia','#DCDCDC':'Gainsboro','#F8F8FF':'Ghost White','#FFD700':'Gold','#DAA520':'Golden Rod','#808080':'Gray','#808080':'Grey',
 
45
        '#008000':'Green','#ADFF2F':'Green Yellow','#F0FFF0':'Honey Dew','#FF69B4':'Hot Pink','#CD5C5C':'Indian Red','#4B0082':'Indigo','#FFFFF0':'Ivory',
 
46
        '#F0E68C':'Khaki','#E6E6FA':'Lavender','#FFF0F5':'Lavender Blush','#7CFC00':'Lawn Green','#FFFACD':'Lemon Chiffon','#ADD8E6':'Light Blue',
 
47
        '#F08080':'Light Coral','#E0FFFF':'Light Cyan','#FAFAD2':'Light Golden Rod Yellow','#D3D3D3':'Light Gray','#D3D3D3':'Light Grey','#90EE90':'Light Green',
 
48
        '#FFB6C1':'Light Pink','#FFA07A':'Light Salmon','#20B2AA':'Light Sea Green','#87CEFA':'Light Sky Blue','#778899':'Light Slate Gray','#778899':'Light Slate Grey',
 
49
        '#B0C4DE':'Light Steel Blue','#FFFFE0':'Light Yellow','#00FF00':'Lime','#32CD32':'Lime Green','#FAF0E6':'Linen','#FF00FF':'Magenta','#800000':'Maroon',
 
50
        '#66CDAA':'Medium Aqua Marine','#0000CD':'Medium Blue','#BA55D3':'Medium Orchid','#9370D8':'Medium Purple','#3CB371':'Medium Sea Green','#7B68EE':'Medium Slate Blue',
 
51
        '#00FA9A':'Medium Spring Green','#48D1CC':'Medium Turquoise','#C71585':'Medium Violet Red','#191970':'Midnight Blue','#F5FFFA':'Mint Cream','#FFE4E1':'Misty Rose','#FFE4B5':'Moccasin',
 
52
        '#FFDEAD':'Navajo White','#000080':'Navy','#FDF5E6':'Old Lace','#808000':'Olive','#6B8E23':'Olive Drab','#FFA500':'Orange','#FF4500':'Orange Red','#DA70D6':'Orchid',
 
53
        '#EEE8AA':'Pale Golden Rod','#98FB98':'Pale Green','#AFEEEE':'Pale Turquoise','#D87093':'Pale Violet Red','#FFEFD5':'Papaya Whip','#FFDAB9':'Peach Puff',
 
54
        '#CD853F':'Peru','#FFC0CB':'Pink','#DDA0DD':'Plum','#B0E0E6':'Powder Blue','#800080':'Purple','#FF0000':'Red','#BC8F8F':'Rosy Brown','#4169E1':'Royal Blue',
 
55
        '#8B4513':'Saddle Brown','#FA8072':'Salmon','#F4A460':'Sandy Brown','#2E8B57':'Sea Green','#FFF5EE':'Sea Shell','#A0522D':'Sienna','#C0C0C0':'Silver',
 
56
        '#87CEEB':'Sky Blue','#6A5ACD':'Slate Blue','#708090':'Slate Gray','#708090':'Slate Grey','#FFFAFA':'Snow','#00FF7F':'Spring Green',
 
57
        '#4682B4':'Steel Blue','#D2B48C':'Tan','#008080':'Teal','#D8BFD8':'Thistle','#FF6347':'Tomato','#40E0D0':'Turquoise','#EE82EE':'Violet',
 
58
        '#F5DEB3':'Wheat','#FFFFFF':'White','#F5F5F5':'White Smoke','#FFFF00':'Yellow','#9ACD32':'Yellow Green'
59
59
};
60
60
 
 
61
var namedLookup = {};
 
62
 
61
63
function init() {
62
 
        var inputColor = convertRGBToHex(tinyMCEPopup.getWindowArg('input_color'));
 
64
        var inputColor = convertRGBToHex(tinyMCEPopup.getWindowArg('input_color')), key, value;
63
65
 
64
66
        tinyMCEPopup.resizeToInnerSize();
65
67
 
66
68
        generatePicker();
 
69
        generateWebColors();
 
70
        generateNamedColors();
67
71
 
68
72
        if (inputColor) {
69
73
                changeFinalColor(inputColor);
73
77
                if (col)
74
78
                        updateLight(col.r, col.g, col.b);
75
79
        }
 
80
        
 
81
        for (key in named) {
 
82
                value = named[key];
 
83
                namedLookup[value.replace(/\s+/, '').toLowerCase()] = key.replace(/#/, '').toLowerCase();
 
84
        }
 
85
}
 
86
 
 
87
function toHexColor(color) {
 
88
        var matches, red, green, blue, toInt = parseInt;
 
89
 
 
90
        function hex(value) {
 
91
                value = parseInt(value).toString(16);
 
92
 
 
93
                return value.length > 1 ? value : '0' + value; // Padd with leading zero
 
94
        };
 
95
 
 
96
        color = color.replace(/[\s#]+/g, '').toLowerCase();
 
97
        color = namedLookup[color] || color;
 
98
        matches = /^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)|([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})|([a-f0-9])([a-f0-9])([a-f0-9])$/.exec(color);
 
99
 
 
100
        if (matches) {
 
101
                if (matches[1]) {
 
102
                        red = toInt(matches[1]);
 
103
                        green = toInt(matches[2]);
 
104
                        blue = toInt(matches[3]);
 
105
                } else if (matches[4]) {
 
106
                        red = toInt(matches[4], 16);
 
107
                        green = toInt(matches[5], 16);
 
108
                        blue = toInt(matches[6], 16);
 
109
                } else if (matches[7]) {
 
110
                        red = toInt(matches[7] + matches[7], 16);
 
111
                        green = toInt(matches[8] + matches[8], 16);
 
112
                        blue = toInt(matches[9] + matches[9], 16);
 
113
                }
 
114
 
 
115
                return '#' + hex(red) + hex(green) + hex(blue);
 
116
        }
 
117
 
 
118
        return '';
76
119
}
77
120
 
78
121
function insertAction() {
81
124
        tinyMCEPopup.restoreSelection();
82
125
 
83
126
        if (f)
84
 
                f(color);
 
127
                f(toHexColor(color));
85
128
 
86
129
        tinyMCEPopup.close();
87
130
}
91
134
                document.getElementById("colorname").innerHTML = name;
92
135
 
93
136
        document.getElementById("preview").style.backgroundColor = color;
94
 
        document.getElementById("color").value = color.toLowerCase();
 
137
        document.getElementById("color").value = color.toUpperCase();
95
138
}
96
139
 
97
140
function convertRGBToHex(col) {
153
196
        if (el.className == 'generated')
154
197
                return;
155
198
 
156
 
        h += '<table border="0" cellspacing="1" cellpadding="0">'
 
199
        // TODO: VoiceOver doesn't seem to support legend as a label referenced by labelledby.
 
200
        h += '<div role="listbox" aria-labelledby="webcolors_title" tabindex="0"><table role="presentation" border="0" cellspacing="1" cellpadding="0">'
157
201
                + '<tr>';
158
202
 
159
203
        for (i=0; i<colors.length; i++) {
160
204
                h += '<td bgcolor="' + colors[i] + '" width="10" height="10">'
161
 
                        + '<a href="javascript:insertAction();" onfocus="showColor(\'' + colors[i] +  '\');" onmouseover="showColor(\'' + colors[i] +  '\');" style="display:block;width:10px;height:10px;overflow:hidden;">'
162
 
                        + '</a></td>';
 
205
                        + '<a href="javascript:insertAction();" role="option" tabindex="-1" aria-labelledby="web_colors_' + i + '" onfocus="showColor(\'' + colors[i] + '\');" onmouseover="showColor(\'' + colors[i] + '\');" style="display:block;width:10px;height:10px;overflow:hidden;">';
 
206
                if (tinyMCEPopup.editor.forcedHighContrastMode) {
 
207
                        h += '<canvas class="mceColorSwatch" height="10" width="10" data-color="' + colors[i] + '"></canvas>';
 
208
                }
 
209
                h += '<span class="mceVoiceLabel" style="display:none;" id="web_colors_' + i + '">' + colors[i].toUpperCase() + '</span>';
 
210
                h += '</a></td>';
163
211
                if ((i+1) % 18 == 0)
164
212
                        h += '</tr><tr>';
165
213
        }
166
214
 
167
 
        h += '</table>';
 
215
        h += '</table></div>';
168
216
 
169
217
        el.innerHTML = h;
170
218
        el.className = 'generated';
171
 
}
172
 
 
 
219
 
 
220
        paintCanvas(el);
 
221
        enableKeyboardNavigation(el.firstChild);
 
222
}
 
223
 
 
224
function paintCanvas(el) {
 
225
        tinyMCEPopup.getWin().tinymce.each(tinyMCEPopup.dom.select('canvas.mceColorSwatch', el), function(canvas) {
 
226
                var context;
 
227
                if (canvas.getContext && (context = canvas.getContext("2d"))) {
 
228
                        context.fillStyle = canvas.getAttribute('data-color');
 
229
                        context.fillRect(0, 0, 10, 10);
 
230
                }
 
231
        });
 
232
}
173
233
function generateNamedColors() {
174
234
        var el = document.getElementById('namedcolors'), h = '', n, v, i = 0;
175
235
 
178
238
 
179
239
        for (n in named) {
180
240
                v = named[n];
181
 
                h += '<a href="javascript:insertAction();" onmouseover="showColor(\'' + n +  '\',\'' + v + '\');" style="background-color: ' + n + '"><!-- IE --></a>'
 
241
                h += '<a href="javascript:insertAction();" role="option" tabindex="-1" aria-labelledby="named_colors_' + i + '" onfocus="showColor(\'' + n + '\',\'' + v + '\');" onmouseover="showColor(\'' + n + '\',\'' + v + '\');" style="background-color: ' + n + '">';
 
242
                if (tinyMCEPopup.editor.forcedHighContrastMode) {
 
243
                        h += '<canvas class="mceColorSwatch" height="10" width="10" data-color="' + colors[i] + '"></canvas>';
 
244
                }
 
245
                h += '<span class="mceVoiceLabel" style="display:none;" id="named_colors_' + i + '">' + v + '</span>';
 
246
                h += '</a>';
 
247
                i++;
182
248
        }
183
249
 
184
250
        el.innerHTML = h;
185
251
        el.className = 'generated';
 
252
 
 
253
        paintCanvas(el);
 
254
        enableKeyboardNavigation(el);
 
255
}
 
256
 
 
257
function enableKeyboardNavigation(el) {
 
258
        tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {
 
259
                root: el,
 
260
                items: tinyMCEPopup.dom.select('a', el)
 
261
        }, tinyMCEPopup.dom);
186
262
}
187
263
 
188
264
function dechex(n) {