-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.js
154 lines (125 loc) · 4.2 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(function () {
"use strict";
var cells,
tabletools,
getSelectedCells;
CKEDITOR.plugins.add('cellselection',
{
onLoad: function () {
// We can't alias these features earlier, as they could be still not loaded.
tabletools = CKEDITOR.plugins.tabletools;
getSelectedCells = tabletools.getSelectedCells;
},
});
CKEDITOR.on('dialogDefinition', function (ev) {
var dialogName = ev.data.name,
dialogDefinition = ev.data.definition,
editor = ev.editor,
tabName = '';
if (dialogName === 'cellProperties') {
tabName = 'info';
dialogDefinition.minHeight += 80;
}
if (tabName === '')
return;
var tab = dialogDefinition.getContents(tabName);
if (!tab)
return;
var select = {
type: 'select',
id: 'cellSelection',
default: 'cell',
items: [
[editor.lang.cellselection.cell, 'cell'],
[editor.lang.cellselection.row, 'row'],
[editor.lang.cellselection.col, 'col'],
[editor.lang.cellselection.all, 'all']
],
setup: function() {
var select = this.getElement();
cells = getSelectedCells(editor.getSelection());
if (cells.length === 1) {
cells = cells.shift();
select.setStyle('display', '')
} else {
select.setStyle('display', 'none')
}
},
onChange: function (event) {
var value = event.data.value;
var elems = getBlocks(cells, value);
var dialog = CKEDITOR.dialog.getCurrent();
if (elems) {
selectCells(editor, elems);
dialog.cells = getSelectedCells(editor.getSelection());
}
}
};
tab.elements.unshift(select);
}, null, null, 9);
// English
addTranslation('en', {
cell: 'Update current cell',
row: 'Update all cells in row',
col: 'Update all cells in column',
all: 'Update all cells in table'
});
// Deutsch
addTranslation('de', {
cell: 'Diese Zelle ver\u00e4ndern',
row: 'Alle Zellen in dieser Zeile ver\u00e4ndern',
col: 'Alle Zellen in einer Kolonne ver\u00e4ndern',
all: 'Alle Zellen der Tabelle ver\u00e4ndern'
});
// Russian
addTranslation('ru', {
cell: "Обновить текущую ячейку",
row: "Обновить все ячейки в строке",
col: "Обновить текущую в столбце",
all: "Обновить все ячейки в таблице",
});
function getBlocks(cell, param) {
var blocks = cell;
var table, index;
if (Array.isArray(cell)) {
return null;
}
table = cell.getAscendant('table');
index = cell.getIndex();
switch (param) {
case 'row':
blocks = cell.getParent().getChildren();
break;
case 'col':
blocks = table.find('td:nth-child(' + (index + 1) + ')');
break;
case 'all':
blocks = table.find('td');
break;
}
return blocks;
}
function addTranslation(lang, texts) {
CKEDITOR.plugins.setLang('cellselection', lang, texts);
}
function selectCells(editor, cells) {
var ranges = [],
item,
i;
if (cells.$ instanceof HTMLElement) {
ranges.push(getRange(editor, cells));
} else {
for (i = 0; i < cells.count(); i++) {
item = cells.getItem(i);
ranges.push(getRange(editor, item));
}
}
editor.getSelection().selectRanges(ranges);
}
function getRange(editor, item) {
var range = editor.createRange();
range.setStartBefore(item);
range.setEndAfter(item);
return range;
}
})();