4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
11 /*global tinymce:true */
13 tinymce.PluginManager.add('textcolor', function(editor) {
14 function mapColors() {
15 var i, colors = [], colorMap;
17 colorMap = editor.settings.textcolor_map || [
19 "993300", "Burnt orange",
20 "333300", "Dark olive",
21 "003300", "Dark green",
22 "003366", "Dark azure",
23 "000080", "Navy Blue",
25 "333333", "Very dark gray",
32 "666699", "Grayish blue",
36 "99CC00", "Yellow green",
37 "339966", "Sea green",
38 "33CCCC", "Turquoise",
39 "3366FF", "Royal blue",
41 "999999", "Medium gray",
52 "FFFF99", "Light yellow",
53 "CCFFCC", "Pale green",
54 "CCFFFF", "Pale cyan",
55 "99CCFF", "Light sky blue",
60 for (i = 0; i < colorMap.length; i += 2) {
62 text: colorMap[i + 1],
70 function renderColorPicker() {
71 var ctrl = this, colors, color, html, last, rows, cols, x, y, i;
75 html = '<table class="mce-grid mce-grid-border mce-colorbutton-grid" role="presentation" cellspacing="0"><tbody>';
76 last = colors.length - 1;
77 rows = editor.settings.textcolor_rows || 5;
78 cols = editor.settings.textcolor_cols || 8;
80 for (y = 0; y < rows; y++) {
83 for (x = 0; x < cols; x++) {
92 '<div id="' + ctrl._id + '-' + i + '"' +
93 ' data-mce-color="' + color.color + '"' +
96 ' style="' + (color ? 'background-color: #' + color.color : '') + '"' +
97 ' title="' + color.text + '">' +
107 html += '</tbody></table>';
112 function onPanelClick(e) {
113 var buttonCtrl = this.parent(), value;
115 if ((value = e.target.getAttribute('data-mce-color'))) {
116 buttonCtrl.hidePanel();
118 buttonCtrl.color(value);
119 editor.execCommand(buttonCtrl.settings.selectcmd, false, value);
123 function onButtonClick() {
127 editor.execCommand(self.settings.selectcmd, false, self._color);
131 editor.addButton('forecolor', {
133 tooltip: 'Text color',
134 popoverAlign: 'bc-tl',
135 selectcmd: 'ForeColor',
137 html: renderColorPicker,
138 onclick: onPanelClick
140 onclick: onButtonClick
143 editor.addButton('backcolor', {
145 tooltip: 'Background color',
146 popoverAlign: 'bc-tl',
147 selectcmd: 'HiliteColor',
149 html: renderColorPicker,
150 onclick: onPanelClick
152 onclick: onButtonClick