12
12
/*eslint consistent-this:0 */
14
14
tinymce.PluginManager.add('textcolor', function(editor) {
17
rows = editor.settings.textcolor_rows || 5;
18
cols = editor.settings.textcolor_cols || 8;
20
function getCurrentColor(format) {
23
editor.dom.getParents(editor.selection.getStart(), function(elm) {
26
if ((value = elm.style[format == 'forecolor' ? 'color' : 'background-color'])) {
15
34
function mapColors() {
16
35
var i, colors = [], colorMap;
71
89
function renderColorPicker() {
72
var ctrl = this, colors, color, html, last, rows, cols, x, y, i;
90
var ctrl = this, colors, color, html, last, x, y, i, id = ctrl._id, count = 0;
92
function getColorCellHtml(color, title) {
93
var isNoColor = color == 'transparent';
96
'<td class="mce-grid-cell' + (isNoColor ? ' mce-colorbtn-trans' : '') + '">' +
97
'<div id="' + id + '-' + (count++) + '"' +
98
' data-mce-color="' + (color ? color : '') + '"' +
101
' style="' + (color ? 'background-color: ' + color : '') + '"' +
102
' title="' + tinymce.translate(title) + '">' +
103
(isNoColor ? '×' : '') +
74
109
colors = mapColors();
111
text: tinymce.translate("No color"),
76
115
html = '<table class="mce-grid mce-grid-border mce-colorbutton-grid" role="list" cellspacing="0"><tbody>';
77
116
last = colors.length - 1;
78
rows = editor.settings.textcolor_rows || 5;
79
cols = editor.settings.textcolor_cols || 8;
81
118
for (y = 0; y < rows; y++) {
88
125
html += '<td></td>';
90
127
color = colors[i];
93
'<div id="' + ctrl._id + '-' + i + '"' +
94
' data-mce-color="' + color.color + '"' +
97
' style="' + (color ? 'background-color: #' + color.color : '') + '"' +
98
' title="' + color.text + '">' +
128
html += getColorCellHtml(color.color, color.text);
135
if (editor.settings.color_picker_callback) {
138
'<td colspan="' + cols + '" class="mce-custom-color-btn">' +
139
'<div id="' + id + '-c" class="mce-widget mce-btn mce-btn-small mce-btn-flat" ' +
140
'role="button" tabindex="-1" aria-labelledby="' + id + '-c" style="width: 100%">' +
141
'<button type="button" role="presentation" tabindex="-1">' + tinymce.translate('Custom...') + '</button>' +
149
for (x = 0; x < cols; x++) {
150
html += getColorCellHtml('', 'Custom color');
108
156
html += '</tbody></table>';
161
function applyFormat(format, value) {
163
editor.formatter.apply(format, {value: value});
164
editor.nodeChanged();
167
function removeFormat(format) {
169
editor.formatter.remove(format, {value: null}, null, true);
170
editor.nodeChanged();
113
173
function onPanelClick(e) {
114
174
var buttonCtrl = this.parent(), value;
116
if ((value = e.target.getAttribute('data-mce-color'))) {
176
function selectColor(value) {
177
buttonCtrl.hidePanel();
178
buttonCtrl.color(value);
179
applyFormat(buttonCtrl.settings.format, value);
182
function setDivColor(div, value) {
183
div.style.background = value;
184
div.setAttribute('data-mce-color', value);
187
if (tinymce.DOM.getParent(e.target, '.mce-custom-color-btn')) {
188
buttonCtrl.hidePanel();
190
editor.settings.color_picker_callback.call(editor, function(value) {
191
var tableElm = buttonCtrl.panel.getEl().getElementsByTagName('table')[0];
192
var customColorCells, div, i;
194
customColorCells = tinymce.map(tableElm.rows[tableElm.rows.length - 1].childNodes, function(elm) {
195
return elm.firstChild;
198
for (i = 0; i < customColorCells.length; i++) {
199
div = customColorCells[i];
200
if (!div.getAttribute('data-mce-color')) {
205
// Shift colors to the right
206
// TODO: Might need to be the left on RTL
208
for (i = 0; i < cols - 1; i++) {
209
setDivColor(customColorCells[i], customColorCells[i + 1].getAttribute('data-mce-color'));
213
setDivColor(div, value);
215
}, getCurrentColor(buttonCtrl.settings.format));
218
value = e.target.getAttribute('data-mce-color');
117
220
if (this.lastId) {
118
221
document.getElementById(this.lastId).setAttribute('aria-selected', false);
121
224
e.target.setAttribute('aria-selected', true);
122
225
this.lastId = e.target.id;
227
if (value == 'transparent') {
228
removeFormat(buttonCtrl.settings.format);
229
buttonCtrl.hidePanel();
234
} else if (value !== null) {
124
235
buttonCtrl.hidePanel();
126
buttonCtrl.color(value);
127
editor.execCommand(buttonCtrl.settings.selectcmd, false, value);