~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/pub/System/TinyMCEPlugin/tinymce/jscripts/tiny_mce/themes/advanced/jscripts/color_picker.js

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var detail = 50, strhex = "0123456789abcdef", i, isMouseDown = false, isMouseOver = false;
 
2
 
 
3
var colors = new Array(
 
4
        "#000000","#000033","#000066","#000099","#0000cc","#0000ff","#330000","#330033",
 
5
        "#330066","#330099","#3300cc","#3300ff","#660000","#660033","#660066","#660099",
 
6
        "#6600cc","#6600ff","#990000","#990033","#990066","#990099","#9900cc","#9900ff",
 
7
        "#cc0000","#cc0033","#cc0066","#cc0099","#cc00cc","#cc00ff","#ff0000","#ff0033",
 
8
        "#ff0066","#ff0099","#ff00cc","#ff00ff","#003300","#003333","#003366","#003399",
 
9
        "#0033cc","#0033ff","#333300","#333333","#333366","#333399","#3333cc","#3333ff",
 
10
        "#663300","#663333","#663366","#663399","#6633cc","#6633ff","#993300","#993333",
 
11
        "#993366","#993399","#9933cc","#9933ff","#cc3300","#cc3333","#cc3366","#cc3399",
 
12
        "#cc33cc","#cc33ff","#ff3300","#ff3333","#ff3366","#ff3399","#ff33cc","#ff33ff",
 
13
        "#006600","#006633","#006666","#006699","#0066cc","#0066ff","#336600","#336633",
 
14
        "#336666","#336699","#3366cc","#3366ff","#666600","#666633","#666666","#666699",
 
15
        "#6666cc","#6666ff","#996600","#996633","#996666","#996699","#9966cc","#9966ff",
 
16
        "#cc6600","#cc6633","#cc6666","#cc6699","#cc66cc","#cc66ff","#ff6600","#ff6633",
 
17
        "#ff6666","#ff6699","#ff66cc","#ff66ff","#009900","#009933","#009966","#009999",
 
18
        "#0099cc","#0099ff","#339900","#339933","#339966","#339999","#3399cc","#3399ff",
 
19
        "#669900","#669933","#669966","#669999","#6699cc","#6699ff","#999900","#999933",
 
20
        "#999966","#999999","#9999cc","#9999ff","#cc9900","#cc9933","#cc9966","#cc9999",
 
21
        "#cc99cc","#cc99ff","#ff9900","#ff9933","#ff9966","#ff9999","#ff99cc","#ff99ff",
 
22
        "#00cc00","#00cc33","#00cc66","#00cc99","#00cccc","#00ccff","#33cc00","#33cc33",
 
23
        "#33cc66","#33cc99","#33cccc","#33ccff","#66cc00","#66cc33","#66cc66","#66cc99",
 
24
        "#66cccc","#66ccff","#99cc00","#99cc33","#99cc66","#99cc99","#99cccc","#99ccff",
 
25
        "#cccc00","#cccc33","#cccc66","#cccc99","#cccccc","#ccccff","#ffcc00","#ffcc33",
 
26
        "#ffcc66","#ffcc99","#ffcccc","#ffccff","#00ff00","#00ff33","#00ff66","#00ff99",
 
27
        "#00ffcc","#00ffff","#33ff00","#33ff33","#33ff66","#33ff99","#33ffcc","#33ffff",
 
28
        "#66ff00","#66ff33","#66ff66","#66ff99","#66ffcc","#66ffff","#99ff00","#99ff33",
 
29
        "#99ff66","#99ff99","#99ffcc","#99ffff","#ccff00","#ccff33","#ccff66","#ccff99",
 
30
        "#ccffcc","#ccffff","#ffff00","#ffff33","#ffff66","#ffff99","#ffffcc","#ffffff"
 
31
);
 
32
 
 
33
var named = {
 
34
        '#F0F8FF':'AliceBlue','#FAEBD7':'AntiqueWhite','#00FFFF':'Aqua','#7FFFD4':'Aquamarine','#F0FFFF':'Azure','#F5F5DC':'Beige',
 
35
        '#FFE4C4':'Bisque','#000000':'Black','#FFEBCD':'BlanchedAlmond','#0000FF':'Blue','#8A2BE2':'BlueViolet','#A52A2A':'Brown',
 
36
        '#DEB887':'BurlyWood','#5F9EA0':'CadetBlue','#7FFF00':'Chartreuse','#D2691E':'Chocolate','#FF7F50':'Coral','#6495ED':'CornflowerBlue',
 
37
        '#FFF8DC':'Cornsilk','#DC143C':'Crimson','#00FFFF':'Cyan','#00008B':'DarkBlue','#008B8B':'DarkCyan','#B8860B':'DarkGoldenRod',
 
38
        '#A9A9A9':'DarkGray','#A9A9A9':'DarkGrey','#006400':'DarkGreen','#BDB76B':'DarkKhaki','#8B008B':'DarkMagenta','#556B2F':'DarkOliveGreen',
 
39
        '#FF8C00':'Darkorange','#9932CC':'DarkOrchid','#8B0000':'DarkRed','#E9967A':'DarkSalmon','#8FBC8F':'DarkSeaGreen','#483D8B':'DarkSlateBlue',
 
40
        '#2F4F4F':'DarkSlateGray','#2F4F4F':'DarkSlateGrey','#00CED1':'DarkTurquoise','#9400D3':'DarkViolet','#FF1493':'DeepPink','#00BFFF':'DeepSkyBlue',
 
41
        '#696969':'DimGray','#696969':'DimGrey','#1E90FF':'DodgerBlue','#B22222':'FireBrick','#FFFAF0':'FloralWhite','#228B22':'ForestGreen',
 
42
        '#FF00FF':'Fuchsia','#DCDCDC':'Gainsboro','#F8F8FF':'GhostWhite','#FFD700':'Gold','#DAA520':'GoldenRod','#808080':'Gray','#808080':'Grey',
 
43
        '#008000':'Green','#ADFF2F':'GreenYellow','#F0FFF0':'HoneyDew','#FF69B4':'HotPink','#CD5C5C':'IndianRed','#4B0082':'Indigo','#FFFFF0':'Ivory',
 
44
        '#F0E68C':'Khaki','#E6E6FA':'Lavender','#FFF0F5':'LavenderBlush','#7CFC00':'LawnGreen','#FFFACD':'LemonChiffon','#ADD8E6':'LightBlue',
 
45
        '#F08080':'LightCoral','#E0FFFF':'LightCyan','#FAFAD2':'LightGoldenRodYellow','#D3D3D3':'LightGray','#D3D3D3':'LightGrey','#90EE90':'LightGreen',
 
46
        '#FFB6C1':'LightPink','#FFA07A':'LightSalmon','#20B2AA':'LightSeaGreen','#87CEFA':'LightSkyBlue','#778899':'LightSlateGray','#778899':'LightSlateGrey',
 
47
        '#B0C4DE':'LightSteelBlue','#FFFFE0':'LightYellow','#00FF00':'Lime','#32CD32':'LimeGreen','#FAF0E6':'Linen','#FF00FF':'Magenta','#800000':'Maroon',
 
48
        '#66CDAA':'MediumAquaMarine','#0000CD':'MediumBlue','#BA55D3':'MediumOrchid','#9370D8':'MediumPurple','#3CB371':'MediumSeaGreen','#7B68EE':'MediumSlateBlue',
 
49
        '#00FA9A':'MediumSpringGreen','#48D1CC':'MediumTurquoise','#C71585':'MediumVioletRed','#191970':'MidnightBlue','#F5FFFA':'MintCream','#FFE4E1':'MistyRose','#FFE4B5':'Moccasin',
 
50
        '#FFDEAD':'NavajoWhite','#000080':'Navy','#FDF5E6':'OldLace','#808000':'Olive','#6B8E23':'OliveDrab','#FFA500':'Orange','#FF4500':'OrangeRed','#DA70D6':'Orchid',
 
51
        '#EEE8AA':'PaleGoldenRod','#98FB98':'PaleGreen','#AFEEEE':'PaleTurquoise','#D87093':'PaleVioletRed','#FFEFD5':'PapayaWhip','#FFDAB9':'PeachPuff',
 
52
        '#CD853F':'Peru','#FFC0CB':'Pink','#DDA0DD':'Plum','#B0E0E6':'PowderBlue','#800080':'Purple','#FF0000':'Red','#BC8F8F':'RosyBrown','#4169E1':'RoyalBlue',
 
53
        '#8B4513':'SaddleBrown','#FA8072':'Salmon','#F4A460':'SandyBrown','#2E8B57':'SeaGreen','#FFF5EE':'SeaShell','#A0522D':'Sienna','#C0C0C0':'Silver',
 
54
        '#87CEEB':'SkyBlue','#6A5ACD':'SlateBlue','#708090':'SlateGray','#708090':'SlateGrey','#FFFAFA':'Snow','#00FF7F':'SpringGreen',
 
55
        '#4682B4':'SteelBlue','#D2B48C':'Tan','#008080':'Teal','#D8BFD8':'Thistle','#FF6347':'Tomato','#40E0D0':'Turquoise','#EE82EE':'Violet',
 
56
        '#F5DEB3':'Wheat','#FFFFFF':'White','#F5F5F5':'WhiteSmoke','#FFFF00':'Yellow','#9ACD32':'YellowGreen'
 
57
};
 
58
 
 
59
function init() {
 
60
        var inputColor = convertRGBToHex(tinyMCE.getWindowArg('input_color'));
 
61
 
 
62
        if (tinyMCE.isMSIE)
 
63
                tinyMCEPopup.resizeToInnerSize();
 
64
 
 
65
        generatePicker();
 
66
 
 
67
        if (inputColor) {
 
68
                changeFinalColor(inputColor);
 
69
 
 
70
                col = convertHexToRGB(inputColor);
 
71
 
 
72
                if (col)
 
73
                        updateLight(col.r, col.g, col.b);
 
74
        }
 
75
}
 
76
 
 
77
function insertAction() {
 
78
        var color = document.getElementById("color").value;
 
79
 
 
80
        tinyMCEPopup.execCommand(tinyMCE.getWindowArg('command'), false, color);
 
81
        tinyMCEPopup.close();
 
82
}
 
83
 
 
84
function showColor(color, name) {
 
85
        if (name)
 
86
                document.getElementById("colorname").innerHTML = name;
 
87
 
 
88
        document.getElementById("preview").style.backgroundColor = color;
 
89
        document.getElementById("color").value = color;
 
90
}
 
91
 
 
92
function convertRGBToHex(col) {
 
93
        var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
 
94
 
 
95
        if (!col)
 
96
                return col;
 
97
 
 
98
        var rgb = col.replace(re, "$1,$2,$3").split(',');
 
99
        if (rgb.length == 3) {
 
100
                r = parseInt(rgb[0]).toString(16);
 
101
                g = parseInt(rgb[1]).toString(16);
 
102
                b = parseInt(rgb[2]).toString(16);
 
103
 
 
104
                r = r.length == 1 ? '0' + r : r;
 
105
                g = g.length == 1 ? '0' + g : g;
 
106
                b = b.length == 1 ? '0' + b : b;
 
107
 
 
108
                return "#" + r + g + b;
 
109
        }
 
110
 
 
111
        return col;
 
112
}
 
113
 
 
114
function convertHexToRGB(col) {
 
115
        if (col.indexOf('#') != -1) {
 
116
                col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
 
117
 
 
118
                r = parseInt(col.substring(0, 2), 16);
 
119
                g = parseInt(col.substring(2, 4), 16);
 
120
                b = parseInt(col.substring(4, 6), 16);
 
121
 
 
122
                return {r : r, g : g, b : b};
 
123
        }
 
124
 
 
125
        return null;
 
126
}
 
127
 
 
128
function generatePicker() {
 
129
        var el = document.getElementById('light'), h = '', i;
 
130
 
 
131
        for (i = 0; i < detail; i++){
 
132
                h += '<div id="gs'+i+'" style="background-color:#000000; width:15px; height:3px; border-style:none; border-width:0px;"'
 
133
                + ' onclick="changeFinalColor(this.style.backgroundColor)"'
 
134
                + ' onmousedown="isMouseDown = true; return false;"'
 
135
                + ' onmouseup="isMouseDown = false;"'
 
136
                + ' onmousemove="if (isMouseDown && isMouseOver) changeFinalColor(this.style.backgroundColor); return false;"'
 
137
                + ' onmouseover="isMouseOver = true;"'
 
138
                + ' onmouseout="isMouseOver = false;"'
 
139
                + '></div>';
 
140
        }
 
141
 
 
142
        el.innerHTML = h;
 
143
}
 
144
 
 
145
function generateWebColors() {
 
146
        var el = document.getElementById('webcolors'), h = '', i;
 
147
 
 
148
        if (el.className == 'generated')
 
149
                return;
 
150
 
 
151
        h += '<table border="0" cellspacing="1" cellpadding="0">'
 
152
                + '<tr>';
 
153
 
 
154
        for (i=0; i<colors.length; i++) {
 
155
                h += '<td bgcolor="' + colors[i] + '">'
 
156
                        + '<a href="javascript:insertAction();" onfocus="showColor(\'' + colors[i] +  '\');" onmouseover="showColor(\'' + colors[i] +  '\');">'
 
157
                        + '<img border="0" src="images/spacer.gif" width="10" height="10" title="' + colors[i] +  '" alt="' + colors[i] +  '" /></a></td>';
 
158
                if ((i+1) % 18 == 0)
 
159
                        h += '</tr><tr>';
 
160
        }
 
161
 
 
162
        h += '</table>';
 
163
 
 
164
        el.innerHTML = h;
 
165
        el.className = 'generated';
 
166
}
 
167
 
 
168
function generateNamedColors() {
 
169
        var el = document.getElementById('namedcolors'), h = '', n, v, i = 0;
 
170
 
 
171
        if (el.className == 'generated')
 
172
                return;
 
173
 
 
174
        for (n in named) {
 
175
                v = named[n];
 
176
                h += '<a href="javascript:insertAction();" onmouseover="showColor(\'' + n +  '\',\'' + v + '\');" style="background-color: ' + n + '"><!-- IE --></a>'
 
177
        }
 
178
 
 
179
        el.innerHTML = h;
 
180
        el.className = 'generated';
 
181
}
 
182
 
 
183
function dechex(n) {
 
184
        return strhex.charAt(Math.floor(n / 16)) + strhex.charAt(n % 16);
 
185
}
 
186
 
 
187
function computeColor(e) {
 
188
        var x, y, partWidth, partDetail, imHeight, r, g, b, coef, i, finalCoef, finalR, finalG, finalB;
 
189
 
 
190
        x = e.offsetX ? e.offsetX : (e.target ? e.clientX - e.target.x : 0);
 
191
        y = e.offsetY ? e.offsetY : (e.target ? e.clientY - e.target.y : 0);
 
192
 
 
193
        partWidth = document.getElementById('colorpicker').width / 6;
 
194
        partDetail = detail / 2;
 
195
        imHeight = document.getElementById('colorpicker').height;
 
196
 
 
197
        r = (x >= 0)*(x < partWidth)*255 + (x >= partWidth)*(x < 2*partWidth)*(2*255 - x * 255 / partWidth) + (x >= 4*partWidth)*(x < 5*partWidth)*(-4*255 + x * 255 / partWidth) + (x >= 5*partWidth)*(x < 6*partWidth)*255;
 
198
        g = (x >= 0)*(x < partWidth)*(x * 255 / partWidth) + (x >= partWidth)*(x < 3*partWidth)*255     + (x >= 3*partWidth)*(x < 4*partWidth)*(4*255 - x * 255 / partWidth);
 
199
        b = (x >= 2*partWidth)*(x < 3*partWidth)*(-2*255 + x * 255 / partWidth) + (x >= 3*partWidth)*(x < 5*partWidth)*255 + (x >= 5*partWidth)*(x < 6*partWidth)*(6*255 - x * 255 / partWidth);
 
200
 
 
201
        coef = (imHeight - y) / imHeight;
 
202
        r = 128 + (r - 128) * coef;
 
203
        g = 128 + (g - 128) * coef;
 
204
        b = 128 + (b - 128) * coef;
 
205
 
 
206
        changeFinalColor('#' + dechex(r) + dechex(g) + dechex(b));
 
207
        updateLight(r, g, b);
 
208
}
 
209
 
 
210
function updateLight(r, g, b) {
 
211
        var i, partDetail = detail / 2, finalCoef, finalR, finalG, finalB, color;
 
212
 
 
213
        for (i=0; i<detail; i++) {
 
214
                if ((i>=0) && (i<partDetail)) {
 
215
                        finalCoef = i / partDetail;
 
216
                        finalR = dechex(255 - (255 - r) * finalCoef);
 
217
                        finalG = dechex(255 - (255 - g) * finalCoef);
 
218
                        finalB = dechex(255 - (255 - b) * finalCoef);
 
219
                } else {
 
220
                        finalCoef = 2 - i / partDetail;
 
221
                        finalR = dechex(r * finalCoef);
 
222
                        finalG = dechex(g * finalCoef);
 
223
                        finalB = dechex(b * finalCoef);
 
224
                }
 
225
 
 
226
                color = finalR + finalG + finalB;
 
227
 
 
228
                document.getElementById('gs' + i).style.backgroundColor = '#'+color;
 
229
        }
 
230
}
 
231
 
 
232
function changeFinalColor(color) {
 
233
        if (color.indexOf('#') == -1)
 
234
                color = convertRGBToHex(color);
 
235
 
 
236
        document.getElementById('preview').style.backgroundColor = color;
 
237
        document.getElementById('color').value = color;
 
238
}
 
239
 
 
240
window.focus();
 
 
b'\\ No newline at end of file'