annotate WebContent/jscripts/tiny_mce/plugins/table/editor_plugin_src.js @ 6:5bb7cc86069c

restlet.jar
author dwinter
date Wed, 14 Mar 2012 16:21:45 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function(tinymce) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var each = tinymce.each;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 // Checks if the selection/caret is at the start of the specified block element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 function isAtStart(rng, par) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 var doc = par.ownerDocument, rng2 = doc.createRange(), elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 rng2.setStartBefore(par);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 rng2.setEnd(rng.endContainer, rng.endOffset);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 elm = doc.createElement('body');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 elm.appendChild(rng2.cloneContents());
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 // Check for text characters of other elements that should be treated as content
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 function getSpanVal(td, name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 return parseInt(td.getAttribute(name) || 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 * Table Grid class.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 function TableGrid(table, dom, selection) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 var grid, startPos, endPos, selectedCell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38 buildGrid();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 selectedCell = dom.getParent(selection.getStart(), 'th,td');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 if (selectedCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 startPos = getPos(selectedCell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 endPos = findEndPos();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 selectedCell = getCell(startPos.x, startPos.y);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 function cloneNode(node, children) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 node = node.cloneNode(children);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 node.removeAttribute('id');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 return node;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 function buildGrid() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 var startY = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 grid = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 each(['thead', 'tbody', 'tfoot'], function(part) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 var rows = dom.select('> ' + part + ' tr', table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 each(rows, function(tr, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 y += startY;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 each(dom.select('> td, > th', tr), function(td, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 var x2, y2, rowspan, colspan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 // Skip over existing cells produced by rowspan
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 if (grid[y]) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 while (grid[y][x])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 x++;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 // Get col/rowspan from cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 rowspan = getSpanVal(td, 'rowspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 colspan = getSpanVal(td, 'colspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 // Fill out rowspan/colspan right and down
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 for (y2 = y; y2 < y + rowspan; y2++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 if (!grid[y2])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 grid[y2] = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 for (x2 = x; x2 < x + colspan; x2++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 grid[y2][x2] = {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 part : part,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 real : y2 == y && x2 == x,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 elm : td,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 rowspan : rowspan,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 colspan : colspan
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 startY += rows.length;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 function getCell(x, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 var row;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 row = grid[y];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 if (row)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 return row[x];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 function setSpanVal(td, name, val) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 if (td) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 val = parseInt(val);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 if (val === 1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 td.removeAttribute(name, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 td.setAttribute(name, val, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 function isCellSelected(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 return cell && (dom.hasClass(cell.elm, 'mceSelected') || cell == selectedCell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 function getSelectedRows() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123 var rows = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125 each(table.rows, function(row) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126 each(row.cells, function(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 if (dom.hasClass(cell, 'mceSelected') || cell == selectedCell.elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128 rows.push(row);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134 return rows;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 function deleteTable() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138 var rng = dom.createRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
140 rng.setStartAfter(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
141 rng.setEndAfter(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
142
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
143 selection.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
144
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
145 dom.remove(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
146 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
147
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
148 function cloneCell(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
149 var formatNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
150
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
151 // Clone formats
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
152 tinymce.walk(cell, function(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
153 var curNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
154
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
155 if (node.nodeType == 3) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
156 each(dom.getParents(node.parentNode, null, cell).reverse(), function(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
157 node = cloneNode(node, false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
158
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
159 if (!formatNode)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
160 formatNode = curNode = node;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
161 else if (curNode)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
162 curNode.appendChild(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
163
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
164 curNode = node;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
165 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
166
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
167 // Add something to the inner node
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
168 if (curNode)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
169 curNode.innerHTML = tinymce.isIE ? '&nbsp;' : '<br data-mce-bogus="1" />';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
170
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
171 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
172 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
173 }, 'childNodes');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
174
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
175 cell = cloneNode(cell, false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
176 setSpanVal(cell, 'rowSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
177 setSpanVal(cell, 'colSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
178
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
179 if (formatNode) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
180 cell.appendChild(formatNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
181 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
182 if (!tinymce.isIE)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
183 cell.innerHTML = '<br data-mce-bogus="1" />';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
184 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
185
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
186 return cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
187 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
188
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
189 function cleanup() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
190 var rng = dom.createRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
191
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
192 // Empty rows
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
193 each(dom.select('tr', table), function(tr) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
194 if (tr.cells.length == 0)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
195 dom.remove(tr);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
196 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
197
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
198 // Empty table
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
199 if (dom.select('tr', table).length == 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
200 rng.setStartAfter(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
201 rng.setEndAfter(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
202 selection.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
203 dom.remove(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
204 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
205 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
206
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
207 // Empty header/body/footer
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
208 each(dom.select('thead,tbody,tfoot', table), function(part) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
209 if (part.rows.length == 0)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
210 dom.remove(part);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
211 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
212
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
213 // Restore selection to start position if it still exists
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
214 buildGrid();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
215
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
216 // Restore the selection to the closest table position
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
217 row = grid[Math.min(grid.length - 1, startPos.y)];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
218 if (row) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
219 selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
220 selection.collapse(true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
221 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
222 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
223
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
224 function fillLeftDown(x, y, rows, cols) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
225 var tr, x2, r, c, cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
226
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
227 tr = grid[y][x].elm.parentNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
228 for (r = 1; r <= rows; r++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
229 tr = dom.getNext(tr, 'tr');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
230
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
231 if (tr) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
232 // Loop left to find real cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
233 for (x2 = x; x2 >= 0; x2--) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
234 cell = grid[y + r][x2].elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
235
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
236 if (cell.parentNode == tr) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
237 // Append clones after
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
238 for (c = 1; c <= cols; c++)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
239 dom.insertAfter(cloneCell(cell), cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
240
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
241 break;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
242 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
243 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
244
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
245 if (x2 == -1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
246 // Insert nodes before first cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
247 for (c = 1; c <= cols; c++)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
248 tr.insertBefore(cloneCell(tr.cells[0]), tr.cells[0]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
249 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
250 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
251 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
252 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
253
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
254 function split() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
255 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
256 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
257 var colSpan, rowSpan, newCell, i;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
258
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
259 if (isCellSelected(cell)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
260 cell = cell.elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
261 colSpan = getSpanVal(cell, 'colspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
262 rowSpan = getSpanVal(cell, 'rowspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
263
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
264 if (colSpan > 1 || rowSpan > 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
265 setSpanVal(cell, 'rowSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
266 setSpanVal(cell, 'colSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
267
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
268 // Insert cells right
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
269 for (i = 0; i < colSpan - 1; i++)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
270 dom.insertAfter(cloneCell(cell), cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
271
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
272 fillLeftDown(x, y, rowSpan - 1, colSpan);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
273 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
274 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
275 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
276 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
277 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
278
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
279 function merge(cell, cols, rows) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
280 var startX, startY, endX, endY, x, y, startCell, endCell, cell, children, count;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
281
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
282 // Use specified cell and cols/rows
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
283 if (cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
284 pos = getPos(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
285 startX = pos.x;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
286 startY = pos.y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
287 endX = startX + (cols - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
288 endY = startY + (rows - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
289 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
290 // Use selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
291 startX = startPos.x;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
292 startY = startPos.y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
293 endX = endPos.x;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
294 endY = endPos.y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
295 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
296
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
297 // Find start/end cells
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
298 startCell = getCell(startX, startY);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
299 endCell = getCell(endX, endY);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
300
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
301 // Check if the cells exists and if they are of the same part for example tbody = tbody
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
302 if (startCell && endCell && startCell.part == endCell.part) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
303 // Split and rebuild grid
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
304 split();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
305 buildGrid();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
306
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
307 // Set row/col span to start cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
308 startCell = getCell(startX, startY).elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
309 setSpanVal(startCell, 'colSpan', (endX - startX) + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
310 setSpanVal(startCell, 'rowSpan', (endY - startY) + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
311
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
312 // Remove other cells and add it's contents to the start cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
313 for (y = startY; y <= endY; y++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
314 for (x = startX; x <= endX; x++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
315 if (!grid[y] || !grid[y][x])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
316 continue;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
317
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
318 cell = grid[y][x].elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
319
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
320 if (cell != startCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
321 // Move children to startCell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
322 children = tinymce.grep(cell.childNodes);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
323 each(children, function(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
324 startCell.appendChild(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
325 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
326
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
327 // Remove bogus nodes if there is children in the target cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
328 if (children.length) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
329 children = tinymce.grep(startCell.childNodes);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
330 count = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
331 each(children, function(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
332 if (node.nodeName == 'BR' && dom.getAttrib(node, 'data-mce-bogus') && count++ < children.length - 1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
333 startCell.removeChild(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
334 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
335 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
336
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
337 // Remove cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
338 dom.remove(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
339 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
340 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
341 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
342
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
343 // Remove empty rows etc and restore caret location
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
344 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
345 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
346 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
347
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
348 function insertRow(before) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
349 var posY, cell, lastCell, x, rowElm, newRow, newCell, otherCell, rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
350
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
351 // Find first/last row
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
352 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
353 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
354 if (isCellSelected(cell)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
355 cell = cell.elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
356 rowElm = cell.parentNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
357 newRow = cloneNode(rowElm, false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
358 posY = y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
359
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
360 if (before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
361 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
362 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
363 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
364
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
365 if (before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
366 return !posY;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
367 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
368
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
369 for (x = 0; x < grid[0].length; x++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
370 // Cell not found could be because of an invalid table structure
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
371 if (!grid[posY][x])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
372 continue;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
373
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
374 cell = grid[posY][x].elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
375
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
376 if (cell != lastCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
377 if (!before) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
378 rowSpan = getSpanVal(cell, 'rowspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
379 if (rowSpan > 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
380 setSpanVal(cell, 'rowSpan', rowSpan + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
381 continue;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
382 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
383 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
384 // Check if cell above can be expanded
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
385 if (posY > 0 && grid[posY - 1][x]) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
386 otherCell = grid[posY - 1][x].elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
387 rowSpan = getSpanVal(otherCell, 'rowSpan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
388 if (rowSpan > 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
389 setSpanVal(otherCell, 'rowSpan', rowSpan + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
390 continue;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
391 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
392 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
393 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
394
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
395 // Insert new cell into new row
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
396 newCell = cloneCell(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
397 setSpanVal(newCell, 'colSpan', cell.colSpan);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
398
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
399 newRow.appendChild(newCell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
400
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
401 lastCell = cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
402 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
403 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
404
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
405 if (newRow.hasChildNodes()) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
406 if (!before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
407 dom.insertAfter(newRow, rowElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
408 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
409 rowElm.parentNode.insertBefore(newRow, rowElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
410 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
411 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
412
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
413 function insertCol(before) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
414 var posX, lastCell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
415
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
416 // Find first/last column
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
417 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
418 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
419 if (isCellSelected(cell)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
420 posX = x;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
421
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
422 if (before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
423 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
424 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
425 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
426
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
427 if (before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
428 return !posX;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
429 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
430
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
431 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
432 var cell, rowSpan, colSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
433
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
434 if (!row[posX])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
435 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
436
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
437 cell = row[posX].elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
438 if (cell != lastCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
439 colSpan = getSpanVal(cell, 'colspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
440 rowSpan = getSpanVal(cell, 'rowspan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
441
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
442 if (colSpan == 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
443 if (!before) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
444 dom.insertAfter(cloneCell(cell), cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
445 fillLeftDown(posX, y, rowSpan - 1, colSpan);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
446 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
447 cell.parentNode.insertBefore(cloneCell(cell), cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
448 fillLeftDown(posX, y, rowSpan - 1, colSpan);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
449 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
450 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
451 setSpanVal(cell, 'colSpan', cell.colSpan + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
452
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
453 lastCell = cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
454 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
455 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
456 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
457
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
458 function deleteCols() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
459 var cols = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
460
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
461 // Get selected column indexes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
462 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
463 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
464 if (isCellSelected(cell) && tinymce.inArray(cols, x) === -1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
465 each(grid, function(row) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
466 var cell = row[x].elm, colSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
467
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
468 colSpan = getSpanVal(cell, 'colSpan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
469
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
470 if (colSpan > 1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
471 setSpanVal(cell, 'colSpan', colSpan - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
472 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
473 dom.remove(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
474 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
475
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
476 cols.push(x);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
477 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
478 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
479 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
480
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
481 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
482 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
483
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
484 function deleteRows() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
485 var rows;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
486
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
487 function deleteRow(tr) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
488 var nextTr, pos, lastCell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
489
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
490 nextTr = dom.getNext(tr, 'tr');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
491
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
492 // Move down row spanned cells
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
493 each(tr.cells, function(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
494 var rowSpan = getSpanVal(cell, 'rowSpan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
495
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
496 if (rowSpan > 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
497 setSpanVal(cell, 'rowSpan', rowSpan - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
498 pos = getPos(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
499 fillLeftDown(pos.x, pos.y, 1, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
500 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
501 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
502
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
503 // Delete cells
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
504 pos = getPos(tr.cells[0]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
505 each(grid[pos.y], function(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
506 var rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
507
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
508 cell = cell.elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
509
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
510 if (cell != lastCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
511 rowSpan = getSpanVal(cell, 'rowSpan');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
512
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
513 if (rowSpan <= 1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
514 dom.remove(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
515 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
516 setSpanVal(cell, 'rowSpan', rowSpan - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
517
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
518 lastCell = cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
519 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
520 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
521 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
522
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
523 // Get selected rows and move selection out of scope
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
524 rows = getSelectedRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
525
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
526 // Delete all selected rows
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
527 each(rows.reverse(), function(tr) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
528 deleteRow(tr);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
529 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
530
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
531 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
532 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
533
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
534 function cutRows() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
535 var rows = getSelectedRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
536
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
537 dom.remove(rows);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
538 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
539
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
540 return rows;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
541 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
542
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
543 function copyRows() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
544 var rows = getSelectedRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
545
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
546 each(rows, function(row, i) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
547 rows[i] = cloneNode(row, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
548 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
549
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
550 return rows;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
551 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
552
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
553 function pasteRows(rows, before) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
554 var selectedRows = getSelectedRows(),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
555 targetRow = selectedRows[before ? 0 : selectedRows.length - 1],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
556 targetCellCount = targetRow.cells.length;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
557
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
558 // Calc target cell count
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
559 each(grid, function(row) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
560 var match;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
561
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
562 targetCellCount = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
563 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
564 if (cell.real)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
565 targetCellCount += cell.colspan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
566
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
567 if (cell.elm.parentNode == targetRow)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
568 match = 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
569 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
570
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
571 if (match)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
572 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
573 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
574
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
575 if (!before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
576 rows.reverse();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
577
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
578 each(rows, function(row) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
579 var cellCount = row.cells.length, cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
580
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
581 // Remove col/rowspans
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
582 for (i = 0; i < cellCount; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
583 cell = row.cells[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
584 setSpanVal(cell, 'colSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
585 setSpanVal(cell, 'rowSpan', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
586 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
587
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
588 // Needs more cells
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
589 for (i = cellCount; i < targetCellCount; i++)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
590 row.appendChild(cloneCell(row.cells[cellCount - 1]));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
591
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
592 // Needs less cells
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
593 for (i = targetCellCount; i < cellCount; i++)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
594 dom.remove(row.cells[i]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
595
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
596 // Add before/after
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
597 if (before)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
598 targetRow.parentNode.insertBefore(row, targetRow);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
599 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
600 dom.insertAfter(row, targetRow);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
601 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
602 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
603
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
604 function getPos(target) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
605 var pos;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
606
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
607 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
608 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
609 if (cell.elm == target) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
610 pos = {x : x, y : y};
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
611 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
612 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
613 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
614
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
615 return !pos;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
616 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
617
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
618 return pos;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
619 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
620
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
621 function setStartCell(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
622 startPos = getPos(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
623 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
624
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
625 function findEndPos() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
626 var pos, maxX, maxY;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
627
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
628 maxX = maxY = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
629
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
630 each(grid, function(row, y) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
631 each(row, function(cell, x) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
632 var colSpan, rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
633
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
634 if (isCellSelected(cell)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
635 cell = grid[y][x];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
636
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
637 if (x > maxX)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
638 maxX = x;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
639
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
640 if (y > maxY)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
641 maxY = y;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
642
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
643 if (cell.real) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
644 colSpan = cell.colspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
645 rowSpan = cell.rowspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
646
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
647 if (colSpan) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
648 if (x + colSpan > maxX)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
649 maxX = x + colSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
650 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
651
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
652 if (rowSpan) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
653 if (y + rowSpan > maxY)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
654 maxY = y + rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
655 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
656 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
657 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
658 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
659 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
660
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
661 return {x : maxX, y : maxY};
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
662 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
663
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
664 function setEndCell(cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
665 var startX, startY, endX, endY, maxX, maxY, colSpan, rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
666
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
667 endPos = getPos(cell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
668
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
669 if (startPos && endPos) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
670 // Get start/end positions
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
671 startX = Math.min(startPos.x, endPos.x);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
672 startY = Math.min(startPos.y, endPos.y);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
673 endX = Math.max(startPos.x, endPos.x);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
674 endY = Math.max(startPos.y, endPos.y);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
675
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
676 // Expand end positon to include spans
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
677 maxX = endX;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
678 maxY = endY;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
679
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
680 // Expand startX
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
681 for (y = startY; y <= maxY; y++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
682 cell = grid[y][startX];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
683
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
684 if (!cell.real) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
685 if (startX - (cell.colspan - 1) < startX)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
686 startX -= cell.colspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
687 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
688 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
689
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
690 // Expand startY
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
691 for (x = startX; x <= maxX; x++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
692 cell = grid[startY][x];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
693
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
694 if (!cell.real) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
695 if (startY - (cell.rowspan - 1) < startY)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
696 startY -= cell.rowspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
697 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
698 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
699
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
700 // Find max X, Y
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
701 for (y = startY; y <= endY; y++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
702 for (x = startX; x <= endX; x++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
703 cell = grid[y][x];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
704
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
705 if (cell.real) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
706 colSpan = cell.colspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
707 rowSpan = cell.rowspan - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
708
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
709 if (colSpan) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
710 if (x + colSpan > maxX)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
711 maxX = x + colSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
712 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
713
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
714 if (rowSpan) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
715 if (y + rowSpan > maxY)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
716 maxY = y + rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
717 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
718 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
719 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
720 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
721
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
722 // Remove current selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
723 dom.removeClass(dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
724
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
725 // Add new selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
726 for (y = startY; y <= maxY; y++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
727 for (x = startX; x <= maxX; x++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
728 if (grid[y][x])
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
729 dom.addClass(grid[y][x].elm, 'mceSelected');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
730 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
731 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
732 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
733 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
734
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
735 // Expose to public
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
736 tinymce.extend(this, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
737 deleteTable : deleteTable,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
738 split : split,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
739 merge : merge,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
740 insertRow : insertRow,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
741 insertCol : insertCol,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
742 deleteCols : deleteCols,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
743 deleteRows : deleteRows,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
744 cutRows : cutRows,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
745 copyRows : copyRows,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
746 pasteRows : pasteRows,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
747 getPos : getPos,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
748 setStartCell : setStartCell,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
749 setEndCell : setEndCell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
750 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
751 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
752
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
753 tinymce.create('tinymce.plugins.TablePlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
754 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
755 var winMan, clipboardRows, hasCellSelection = true; // Might be selected cells on reload
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
756
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
757 function createTableGrid(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
758 var selection = ed.selection, tblElm = ed.dom.getParent(node || selection.getNode(), 'table');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
759
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
760 if (tblElm)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
761 return new TableGrid(tblElm, ed.dom, selection);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
762 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
763
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
764 function cleanup() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
765 // Restore selection possibilities
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
766 ed.getBody().style.webkitUserSelect = '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
767
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
768 if (hasCellSelection) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
769 ed.dom.removeClass(ed.dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
770 hasCellSelection = false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
771 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
772 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
773
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
774 // Register buttons
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
775 each([
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
776 ['table', 'table.desc', 'mceInsertTable', true],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
777 ['delete_table', 'table.del', 'mceTableDelete'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
778 ['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
779 ['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
780 ['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
781 ['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
782 ['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
783 ['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
784 ['row_props', 'table.row_desc', 'mceTableRowProps', true],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
785 ['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
786 ['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
787 ['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
788 ], function(c) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
789 ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
790 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
791
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
792 // Select whole table is a table border is clicked
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
793 if (!tinymce.isIE) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
794 ed.onClick.add(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
795 e = e.target;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
796
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
797 if (e.nodeName === 'TABLE') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
798 ed.selection.select(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
799 ed.nodeChanged();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
800 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
801 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
802 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
803
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
804 ed.onPreProcess.add(function(ed, args) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
805 var nodes, i, node, dom = ed.dom, value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
806
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
807 nodes = dom.select('table', args.node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
808 i = nodes.length;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
809 while (i--) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
810 node = nodes[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
811 dom.setAttrib(node, 'data-mce-style', '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
812
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
813 if ((value = dom.getAttrib(node, 'width'))) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
814 dom.setStyle(node, 'width', value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
815 dom.setAttrib(node, 'width', '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
816 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
817
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
818 if ((value = dom.getAttrib(node, 'height'))) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
819 dom.setStyle(node, 'height', value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
820 dom.setAttrib(node, 'height', '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
821 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
822 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
823 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
824
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
825 // Handle node change updates
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
826 ed.onNodeChange.add(function(ed, cm, n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
827 var p;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
828
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
829 n = ed.selection.getStart();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
830 p = ed.dom.getParent(n, 'td,th,caption');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
831 cm.setActive('table', n.nodeName === 'TABLE' || !!p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
832
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
833 // Disable table tools if we are in caption
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
834 if (p && p.nodeName === 'CAPTION')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
835 p = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
836
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
837 cm.setDisabled('delete_table', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
838 cm.setDisabled('delete_col', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
839 cm.setDisabled('delete_table', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
840 cm.setDisabled('delete_row', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
841 cm.setDisabled('col_after', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
842 cm.setDisabled('col_before', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
843 cm.setDisabled('row_after', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
844 cm.setDisabled('row_before', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
845 cm.setDisabled('row_props', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
846 cm.setDisabled('cell_props', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
847 cm.setDisabled('split_cells', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
848 cm.setDisabled('merge_cells', !p);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
849 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
850
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
851 ed.onInit.add(function(ed) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
852 var startTable, startCell, dom = ed.dom, tableGrid;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
853
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
854 winMan = ed.windowManager;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
855
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
856 // Add cell selection logic
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
857 ed.onMouseDown.add(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
858 if (e.button != 2) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
859 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
860
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
861 startCell = dom.getParent(e.target, 'td,th');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
862 startTable = dom.getParent(startCell, 'table');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
863 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
864 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
865
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
866 dom.bind(ed.getDoc(), 'mouseover', function(e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
867 var sel, table, target = e.target;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
868
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
869 if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
870 table = dom.getParent(target, 'table');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
871 if (table == startTable) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
872 if (!tableGrid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
873 tableGrid = createTableGrid(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
874 tableGrid.setStartCell(startCell);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
875
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
876 ed.getBody().style.webkitUserSelect = 'none';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
877 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
878
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
879 tableGrid.setEndCell(target);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
880 hasCellSelection = true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
881 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
882
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
883 // Remove current selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
884 sel = ed.selection.getSel();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
885
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
886 try {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
887 if (sel.removeAllRanges)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
888 sel.removeAllRanges();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
889 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
890 sel.empty();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
891 } catch (ex) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
892 // IE9 might throw errors here
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
893 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
894
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
895 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
896 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
897 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
898
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
899 ed.onMouseUp.add(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
900 var rng, sel = ed.selection, selectedCells, nativeSel = sel.getSel(), walker, node, lastNode, endNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
901
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
902 // Move selection to startCell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
903 if (startCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
904 if (tableGrid)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
905 ed.getBody().style.webkitUserSelect = '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
906
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
907 function setPoint(node, start) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
908 var walker = new tinymce.dom.TreeWalker(node, node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
909
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
910 do {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
911 // Text node
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
912 if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
913 if (start)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
914 rng.setStart(node, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
915 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
916 rng.setEnd(node, node.nodeValue.length);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
917
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
918 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
919 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
920
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
921 // BR element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
922 if (node.nodeName == 'BR') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
923 if (start)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
924 rng.setStartBefore(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
925 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
926 rng.setEndBefore(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
927
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
928 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
929 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
930 } while (node = (start ? walker.next() : walker.prev()));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
931 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
932
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
933 // Try to expand text selection as much as we can only Gecko supports cell selection
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
934 selectedCells = dom.select('td.mceSelected,th.mceSelected');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
935 if (selectedCells.length > 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
936 rng = dom.createRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
937 node = selectedCells[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
938 endNode = selectedCells[selectedCells.length - 1];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
939 rng.setStartBefore(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
940 rng.setEndAfter(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
941
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
942 setPoint(node, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
943 walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
944
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
945 do {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
946 if (node.nodeName == 'TD' || node.nodeName == 'TH') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
947 if (!dom.hasClass(node, 'mceSelected'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
948 break;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
949
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
950 lastNode = node;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
951 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
952 } while (node = walker.next());
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
953
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
954 setPoint(lastNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
955
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
956 sel.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
957 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
958
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
959 ed.nodeChanged();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
960 startCell = tableGrid = startTable = null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
961 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
962 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
963
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
964 ed.onKeyUp.add(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
965 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
966 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
967
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
968 ed.onKeyDown.add(function (ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
969 fixTableCellSelection(ed);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
970 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
971
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
972 ed.onMouseDown.add(function (ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
973 if (e.button != 2) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
974 fixTableCellSelection(ed);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
975 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
976 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
977 function tableCellSelected(ed, rng, n, currentCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
978 // The decision of when a table cell is selected is somewhat involved. The fact that this code is
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
979 // required is actually a pointer to the root cause of this bug. A cell is selected when the start
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
980 // and end offsets are 0, the start container is a text, and the selection node is either a TR (most cases)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
981 // or the parent of the table (in the case of the selection containing the last cell of a table).
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
982 var TEXT_NODE = 3, table = ed.dom.getParent(rng.startContainer, 'TABLE'),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
983 tableParent, allOfCellSelected, tableCellSelection;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
984 if (table)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
985 tableParent = table.parentNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
986 allOfCellSelected =rng.startContainer.nodeType == TEXT_NODE &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
987 rng.startOffset == 0 &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
988 rng.endOffset == 0 &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
989 currentCell &&
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
990 (n.nodeName=="TR" || n==tableParent);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
991 tableCellSelection = (n.nodeName=="TD"||n.nodeName=="TH")&& !currentCell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
992 return allOfCellSelected || tableCellSelection;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
993 // return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
994 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
995
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
996 // this nasty hack is here to work around some WebKit selection bugs.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
997 function fixTableCellSelection(ed) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
998 if (!tinymce.isWebKit)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
999 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1000
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1001 var rng = ed.selection.getRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1002 var n = ed.selection.getNode();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1003 var currentCell = ed.dom.getParent(rng.startContainer, 'TD,TH');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1004
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1005 if (!tableCellSelected(ed, rng, n, currentCell))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1006 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1007 if (!currentCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1008 currentCell=n;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1009 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1010
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1011 // Get the very last node inside the table cell
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1012 var end = currentCell.lastChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1013 while (end.lastChild)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1014 end = end.lastChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1015
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1016 // Select the entire table cell. Nothing outside of the table cell should be selected.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1017 rng.setEnd(end, end.nodeValue.length);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1018 ed.selection.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1019 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1020 ed.plugins.table.fixTableCellSelection=fixTableCellSelection;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1021
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1022 // Add context menu
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1023 if (ed && ed.plugins.contextmenu) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1024 ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1025 var sm, se = ed.selection, el = se.getNode() || ed.getBody();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1026
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1027 if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th') || ed.dom.select('td.mceSelected,th.mceSelected').length) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1028 m.removeAll();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1029
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1030 if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1031 m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1032 m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1033 m.addSeparator();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1034 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1035
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1036 if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1037 m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1038 m.addSeparator();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1039 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1040
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1041 m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', value : {action : 'insert'}});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1042 m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1043 m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1044 m.addSeparator();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1045
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1046 // Cell menu
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1047 sm = m.addMenu({title : 'table.cell'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1048 sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1049 sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1050 sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1051
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1052 // Row menu
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1053 sm = m.addMenu({title : 'table.row'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1054 sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1055 sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1056 sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1057 sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1058 sm.addSeparator();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1059 sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1060 sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1061 sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}).setDisabled(!clipboardRows);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1062 sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}).setDisabled(!clipboardRows);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1063
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1064 // Column menu
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1065 sm = m.addMenu({title : 'table.col'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1066 sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1067 sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1068 sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1069 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1070 m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1071 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1072 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1073
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1074 // Fix to allow navigating up and down in a table in WebKit browsers.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1075 if (tinymce.isWebKit) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1076 function moveSelection(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1077 var VK = tinymce.VK;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1078 var key = e.keyCode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1079
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1080 function handle(upBool, sourceNode, event) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1081 var siblingDirection = upBool ? 'previousSibling' : 'nextSibling';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1082 var currentRow = ed.dom.getParent(sourceNode, 'tr');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1083 var siblingRow = currentRow[siblingDirection];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1084
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1085 if (siblingRow) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1086 moveCursorToRow(ed, sourceNode, siblingRow, upBool);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1087 tinymce.dom.Event.cancel(event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1088 return true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1089 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1090 var tableNode = ed.dom.getParent(currentRow, 'table');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1091 var middleNode = currentRow.parentNode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1092 var parentNodeName = middleNode.nodeName.toLowerCase();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1093 if (parentNodeName === 'tbody' || parentNodeName === (upBool ? 'tfoot' : 'thead')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1094 var targetParent = getTargetParent(upBool, tableNode, middleNode, 'tbody');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1095 if (targetParent !== null) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1096 return moveToRowInTarget(upBool, targetParent, sourceNode, event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1097 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1098 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1099 return escapeTable(upBool, currentRow, siblingDirection, tableNode, event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1100 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1101 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1102
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1103 function getTargetParent(upBool, topNode, secondNode, nodeName) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1104 var tbodies = ed.dom.select('>' + nodeName, topNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1105 var position = tbodies.indexOf(secondNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1106 if (upBool && position === 0 || !upBool && position === tbodies.length - 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1107 return getFirstHeadOrFoot(upBool, topNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1108 } else if (position === -1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1109 var topOrBottom = secondNode.tagName.toLowerCase() === 'thead' ? 0 : tbodies.length - 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1110 return tbodies[topOrBottom];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1111 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1112 return tbodies[position + (upBool ? -1 : 1)];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1113 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1114 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1115
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1116 function getFirstHeadOrFoot(upBool, parent) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1117 var tagName = upBool ? 'thead' : 'tfoot';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1118 var headOrFoot = ed.dom.select('>' + tagName, parent);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1119 return headOrFoot.length !== 0 ? headOrFoot[0] : null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1120 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1121
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1122 function moveToRowInTarget(upBool, targetParent, sourceNode, event) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1123 var targetRow = getChildForDirection(targetParent, upBool);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1124 targetRow && moveCursorToRow(ed, sourceNode, targetRow, upBool);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1125 tinymce.dom.Event.cancel(event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1126 return true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1127 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1128
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1129 function escapeTable(upBool, currentRow, siblingDirection, table, event) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1130 var tableSibling = table[siblingDirection];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1131 if (tableSibling) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1132 moveCursorToStartOfElement(tableSibling);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1133 return true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1134 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1135 var parentCell = ed.dom.getParent(table, 'td,th');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1136 if (parentCell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1137 return handle(upBool, parentCell, event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1138 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1139 var backUpSibling = getChildForDirection(currentRow, !upBool);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1140 moveCursorToStartOfElement(backUpSibling);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1141 return tinymce.dom.Event.cancel(event);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1142 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1143 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1144 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1145
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1146 function getChildForDirection(parent, up) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1147 return parent && parent[up ? 'lastChild' : 'firstChild'];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1148 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1149
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1150 function moveCursorToStartOfElement(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1151 ed.selection.setCursorLocation(n, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1152 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1153
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1154 function isVerticalMovement() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1155 return key == VK.UP || key == VK.DOWN;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1156 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1157
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1158 function isInTable(ed) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1159 var node = ed.selection.getNode();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1160 var currentRow = ed.dom.getParent(node, 'tr');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1161 return currentRow !== null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1162 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1163
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1164 function columnIndex(column) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1165 var colIndex = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1166 var c = column;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1167 while (c.previousSibling) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1168 c = c.previousSibling;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1169 colIndex = colIndex + getSpanVal(c, "colspan");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1170 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1171 return colIndex;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1172 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1173
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1174 function findColumn(rowElement, columnIndex) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1175 var c = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1176 var r = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1177 each(rowElement.children, function(cell, i) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1178 c = c + getSpanVal(cell, "colspan");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1179 r = i;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1180 if (c > columnIndex)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1181 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1182 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1183 return r;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1184 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1185
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1186 function moveCursorToRow(ed, node, row, upBool) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1187 var srcColumnIndex = columnIndex(ed.dom.getParent(node, 'td,th'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1188 var tgtColumnIndex = findColumn(row, srcColumnIndex);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1189 var tgtNode = row.childNodes[tgtColumnIndex];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1190 var rowCellTarget = getChildForDirection(tgtNode, upBool);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1191 moveCursorToStartOfElement(rowCellTarget || tgtNode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1192 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1193
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1194 function shouldFixCaret(preBrowserNode) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1195 var newNode = ed.selection.getNode();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1196 var newParent = ed.dom.getParent(newNode, 'td,th');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1197 var oldParent = ed.dom.getParent(preBrowserNode, 'td,th');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1198 return newParent && newParent !== oldParent && checkSameParentTable(newParent, oldParent)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1199 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1200
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1201 function checkSameParentTable(nodeOne, NodeTwo) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1202 return ed.dom.getParent(nodeOne, 'TABLE') === ed.dom.getParent(NodeTwo, 'TABLE');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1203 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1204
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1205 if (isVerticalMovement() && isInTable(ed)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1206 var preBrowserNode = ed.selection.getNode();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1207 setTimeout(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1208 if (shouldFixCaret(preBrowserNode)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1209 handle(!e.shiftKey && key === VK.UP, preBrowserNode, e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1210 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1211 }, 0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1212 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1213 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1214
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1215 ed.onKeyDown.add(moveSelection);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1216 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1217
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1218 // Fixes an issue on Gecko where it's impossible to place the caret behind a table
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1219 // This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1220 if (!tinymce.isIE) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1221 function fixTableCaretPos() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1222 var last;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1223
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1224 // Skip empty text nodes form the end
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1225 for (last = ed.getBody().lastChild; last && last.nodeType == 3 && !last.nodeValue.length; last = last.previousSibling) ;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1226
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1227 if (last && last.nodeName == 'TABLE')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1228 ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1229 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1230
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1231 // Fixes an bug where it's impossible to place the caret before a table in Gecko
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1232 // this fix solves it by detecting when the caret is at the beginning of such a table
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1233 // and then manually moves the caret infront of the table
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1234 if (tinymce.isGecko) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1235 ed.onKeyDown.add(function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1236 var rng, table, dom = ed.dom;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1237
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1238 // On gecko it's not possible to place the caret before a table
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1239 if (e.keyCode == 37 || e.keyCode == 38) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1240 rng = ed.selection.getRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1241 table = dom.getParent(rng.startContainer, 'table');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1242
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1243 if (table && ed.getBody().firstChild == table) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1244 if (isAtStart(rng, table)) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1245 rng = dom.createRng();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1246
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1247 rng.setStartBefore(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1248 rng.setEndBefore(table);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1249
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1250 ed.selection.setRng(rng);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1251
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1252 e.preventDefault();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1253 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1254 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1255 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1256 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1257 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1258
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1259 ed.onKeyUp.add(fixTableCaretPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1260 ed.onSetContent.add(fixTableCaretPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1261 ed.onVisualAid.add(fixTableCaretPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1262
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1263 ed.onPreProcess.add(function(ed, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1264 var last = o.node.lastChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1265
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1266 if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1267 ed.dom.remove(last);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1268 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1269
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1270 fixTableCaretPos();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1271 ed.startContent = ed.getContent({format : 'raw'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1272 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1273 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1274
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1275 // Register action commands
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1276 each({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1277 mceTableSplitCells : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1278 grid.split();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1279 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1280
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1281 mceTableMergeCells : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1282 var rowSpan, colSpan, cell;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1283
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1284 cell = ed.dom.getParent(ed.selection.getNode(), 'th,td');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1285 if (cell) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1286 rowSpan = cell.rowSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1287 colSpan = cell.colSpan;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1288 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1289
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1290 if (!ed.dom.select('td.mceSelected,th.mceSelected').length) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1291 winMan.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1292 url : url + '/merge_cells.htm',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1293 width : 240 + parseInt(ed.getLang('table.merge_cells_delta_width', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1294 height : 110 + parseInt(ed.getLang('table.merge_cells_delta_height', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1295 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1296 }, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1297 rows : rowSpan,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1298 cols : colSpan,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1299 onaction : function(data) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1300 grid.merge(cell, data.cols, data.rows);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1301 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1302 plugin_url : url
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1303 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1304 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1305 grid.merge();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1306 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1307
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1308 mceTableInsertRowBefore : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1309 grid.insertRow(true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1310 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1311
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1312 mceTableInsertRowAfter : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1313 grid.insertRow();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1314 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1315
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1316 mceTableInsertColBefore : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1317 grid.insertCol(true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1318 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1319
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1320 mceTableInsertColAfter : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1321 grid.insertCol();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1322 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1323
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1324 mceTableDeleteCol : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1325 grid.deleteCols();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1326 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1327
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1328 mceTableDeleteRow : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1329 grid.deleteRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1330 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1331
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1332 mceTableCutRow : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1333 clipboardRows = grid.cutRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1334 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1335
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1336 mceTableCopyRow : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1337 clipboardRows = grid.copyRows();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1338 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1339
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1340 mceTablePasteRowBefore : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1341 grid.pasteRows(clipboardRows, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1342 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1343
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1344 mceTablePasteRowAfter : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1345 grid.pasteRows(clipboardRows);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1346 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1347
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1348 mceTableDelete : function(grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1349 grid.deleteTable();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1350 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1351 }, function(func, name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1352 ed.addCommand(name, function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1353 var grid = createTableGrid();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1354
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1355 if (grid) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1356 func(grid);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1357 ed.execCommand('mceRepaint');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1358 cleanup();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1359 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1360 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1361 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1362
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1363 // Register dialog commands
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1364 each({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1365 mceInsertTable : function(val) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1366 winMan.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1367 url : url + '/table.htm',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1368 width : 400 + parseInt(ed.getLang('table.table_delta_width', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1369 height : 320 + parseInt(ed.getLang('table.table_delta_height', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1370 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1371 }, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1372 plugin_url : url,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1373 action : val ? val.action : 0
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1374 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1375 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1376
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1377 mceTableRowProps : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1378 winMan.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1379 url : url + '/row.htm',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1380 width : 400 + parseInt(ed.getLang('table.rowprops_delta_width', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1381 height : 295 + parseInt(ed.getLang('table.rowprops_delta_height', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1382 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1383 }, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1384 plugin_url : url
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1385 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1386 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1387
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1388 mceTableCellProps : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1389 winMan.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1390 url : url + '/cell.htm',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1391 width : 400 + parseInt(ed.getLang('table.cellprops_delta_width', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1392 height : 295 + parseInt(ed.getLang('table.cellprops_delta_height', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1393 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1394 }, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1395 plugin_url : url
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1396 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1397 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1398 }, function(func, name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1399 ed.addCommand(name, function(ui, val) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1400 func(val);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1401 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1402 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1403 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1404 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1405
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1406 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1407 tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1408 })(tinymce);