annotate media/js/tiny_mce/plugins/table/editor_plugin_src.js @ 201:bc958bc3c6eb

Futzing with CSS side blocks
author Brian Neal <bgneal@gmail.com>
date Mon, 12 Apr 2010 02:56:31 +0000
parents 149c3567fec1
children 237710206167
rev   line source
bgneal@45 1 /**
bgneal@183 2 * editor_plugin_src.js
bgneal@45 3 *
bgneal@183 4 * Copyright 2009, Moxiecode Systems AB
bgneal@183 5 * Released under LGPL License.
bgneal@183 6 *
bgneal@183 7 * License: http://tinymce.moxiecode.com/license
bgneal@183 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@45 9 */
bgneal@45 10
bgneal@183 11 (function(tinymce) {
bgneal@45 12 var each = tinymce.each;
bgneal@45 13
bgneal@183 14 /**
bgneal@183 15 * Table Grid class.
bgneal@183 16 */
bgneal@183 17 function TableGrid(table, dom, selection) {
bgneal@183 18 var grid, startPos, endPos, selectedCell;
bgneal@183 19
bgneal@183 20 buildGrid();
bgneal@183 21 selectedCell = dom.getParent(selection.getStart(), 'th,td');
bgneal@183 22 if (selectedCell) {
bgneal@183 23 startPos = getPos(selectedCell);
bgneal@183 24 endPos = findEndPos();
bgneal@183 25 selectedCell = getCell(startPos.x, startPos.y);
bgneal@183 26 }
bgneal@183 27
bgneal@183 28 function buildGrid() {
bgneal@183 29 var startY = 0;
bgneal@183 30
bgneal@183 31 grid = [];
bgneal@183 32
bgneal@183 33 each(['thead', 'tbody', 'tfoot'], function(part) {
bgneal@183 34 var rows = dom.select(part + ' tr', table);
bgneal@183 35
bgneal@183 36 each(rows, function(tr, y) {
bgneal@183 37 y += startY;
bgneal@183 38
bgneal@183 39 each(dom.select('td,th', tr), function(td, x) {
bgneal@183 40 var x2, y2, rowspan, colspan;
bgneal@183 41
bgneal@183 42 // Skip over existing cells produced by rowspan
bgneal@183 43 if (grid[y]) {
bgneal@183 44 while (grid[y][x])
bgneal@183 45 x++;
bgneal@183 46 }
bgneal@183 47
bgneal@183 48 // Get col/rowspan from cell
bgneal@183 49 rowspan = getSpanVal(td, 'rowspan');
bgneal@183 50 colspan = getSpanVal(td, 'colspan');
bgneal@183 51
bgneal@183 52 // Fill out rowspan/colspan right and down
bgneal@183 53 for (y2 = y; y2 < y + rowspan; y2++) {
bgneal@183 54 if (!grid[y2])
bgneal@183 55 grid[y2] = [];
bgneal@183 56
bgneal@183 57 for (x2 = x; x2 < x + colspan; x2++) {
bgneal@183 58 grid[y2][x2] = {
bgneal@183 59 part : part,
bgneal@183 60 real : y2 == y && x2 == x,
bgneal@183 61 elm : td,
bgneal@183 62 rowspan : rowspan,
bgneal@183 63 colspan : colspan
bgneal@183 64 };
bgneal@183 65 }
bgneal@183 66 }
bgneal@183 67 });
bgneal@183 68 });
bgneal@183 69
bgneal@183 70 startY += rows.length;
bgneal@183 71 });
bgneal@183 72 };
bgneal@183 73
bgneal@183 74 function getCell(x, y) {
bgneal@183 75 var row;
bgneal@183 76
bgneal@183 77 row = grid[y];
bgneal@183 78 if (row)
bgneal@183 79 return row[x];
bgneal@183 80 };
bgneal@183 81
bgneal@183 82 function getSpanVal(td, name) {
bgneal@183 83 return parseInt(td.getAttribute(name) || 1);
bgneal@183 84 };
bgneal@183 85
bgneal@183 86 function isCellSelected(cell) {
bgneal@183 87 return dom.hasClass(cell.elm, 'mceSelected') || cell == selectedCell;
bgneal@183 88 };
bgneal@183 89
bgneal@183 90 function getSelectedRows() {
bgneal@183 91 var rows = [];
bgneal@183 92
bgneal@183 93 each(table.rows, function(row) {
bgneal@183 94 each(row.cells, function(cell) {
bgneal@183 95 if (dom.hasClass(cell, 'mceSelected') || cell == selectedCell.elm) {
bgneal@183 96 rows.push(row);
bgneal@183 97 return false;
bgneal@183 98 }
bgneal@183 99 });
bgneal@183 100 });
bgneal@183 101
bgneal@183 102 return rows;
bgneal@183 103 };
bgneal@183 104
bgneal@183 105 function deleteTable() {
bgneal@183 106 var rng = dom.createRng();
bgneal@183 107
bgneal@183 108 rng.setStartAfter(table);
bgneal@183 109 rng.setEndAfter(table);
bgneal@183 110
bgneal@183 111 selection.setRng(rng);
bgneal@183 112
bgneal@183 113 dom.remove(table);
bgneal@183 114 };
bgneal@183 115
bgneal@183 116 function cloneCell(cell) {
bgneal@183 117 var formatNode;
bgneal@183 118
bgneal@183 119 // Clone formats
bgneal@183 120 tinymce.walk(cell, function(node) {
bgneal@183 121 var curNode;
bgneal@183 122
bgneal@183 123 if (node.nodeType == 3) {
bgneal@183 124 each(dom.getParents(node.parentNode, null, cell).reverse(), function(node) {
bgneal@183 125 node = node.cloneNode(false);
bgneal@183 126
bgneal@183 127 if (!formatNode)
bgneal@183 128 formatNode = curNode = node;
bgneal@183 129 else if (curNode)
bgneal@183 130 curNode.appendChild(node);
bgneal@183 131
bgneal@183 132 curNode = node;
bgneal@183 133 });
bgneal@183 134
bgneal@183 135 // Add something to the inner node
bgneal@183 136 if (curNode)
bgneal@183 137 curNode.innerHTML = tinymce.isIE ? '&nbsp;' : '<br _mce_bogus="1" />';
bgneal@183 138
bgneal@183 139 return false;
bgneal@183 140 }
bgneal@183 141 }, 'childNodes');
bgneal@183 142
bgneal@183 143 cell = cell.cloneNode(false);
bgneal@183 144 cell.rowSpan = cell.colSpan = 1;
bgneal@183 145
bgneal@183 146 if (formatNode) {
bgneal@183 147 cell.appendChild(formatNode);
bgneal@183 148 } else {
bgneal@183 149 if (!tinymce.isIE)
bgneal@183 150 cell.innerHTML = '<br _mce_bogus="1" />';
bgneal@183 151 }
bgneal@183 152
bgneal@183 153 return cell;
bgneal@183 154 };
bgneal@183 155
bgneal@183 156 function cleanup() {
bgneal@183 157 var rng = dom.createRng();
bgneal@183 158
bgneal@183 159 // Empty rows
bgneal@183 160 each(dom.select('tr', table), function(tr) {
bgneal@183 161 if (tr.cells.length == 0)
bgneal@183 162 dom.remove(tr);
bgneal@183 163 });
bgneal@183 164
bgneal@183 165 // Empty table
bgneal@183 166 if (dom.select('tr', table).length == 0) {
bgneal@183 167 rng.setStartAfter(table);
bgneal@183 168 rng.setEndAfter(table);
bgneal@183 169 selection.setRng(rng);
bgneal@183 170 dom.remove(table);
bgneal@183 171 return;
bgneal@183 172 }
bgneal@183 173
bgneal@183 174 // Empty header/body/footer
bgneal@183 175 each(dom.select('thead,tbody,tfoot', table), function(part) {
bgneal@183 176 if (part.rows.length == 0)
bgneal@183 177 dom.remove(part);
bgneal@183 178 });
bgneal@183 179
bgneal@183 180 // Restore selection to start position if it still exists
bgneal@183 181 buildGrid();
bgneal@183 182
bgneal@183 183 // Restore the selection to the closest table position
bgneal@183 184 row = grid[Math.min(grid.length - 1, startPos.y)];
bgneal@183 185 if (row) {
bgneal@183 186 selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
bgneal@183 187 selection.collapse(true);
bgneal@183 188 }
bgneal@183 189 };
bgneal@183 190
bgneal@183 191 function fillLeftDown(x, y, rows, cols) {
bgneal@183 192 var tr, x2, r, c, cell;
bgneal@183 193
bgneal@183 194 tr = grid[y][x].elm.parentNode;
bgneal@183 195 for (r = 1; r <= rows; r++) {
bgneal@183 196 tr = dom.getNext(tr, 'tr');
bgneal@183 197
bgneal@183 198 if (tr) {
bgneal@183 199 // Loop left to find real cell
bgneal@183 200 for (x2 = x; x2 >= 0; x2--) {
bgneal@183 201 cell = grid[y + r][x2].elm;
bgneal@183 202
bgneal@183 203 if (cell.parentNode == tr) {
bgneal@183 204 // Append clones after
bgneal@183 205 for (c = 1; c <= cols; c++)
bgneal@183 206 dom.insertAfter(cloneCell(cell), cell);
bgneal@183 207
bgneal@183 208 break;
bgneal@183 209 }
bgneal@183 210 }
bgneal@183 211
bgneal@183 212 if (x2 == -1) {
bgneal@183 213 // Insert nodes before first cell
bgneal@183 214 for (c = 1; c <= cols; c++)
bgneal@183 215 tr.insertBefore(cloneCell(tr.cells[0]), tr.cells[0]);
bgneal@183 216 }
bgneal@183 217 }
bgneal@183 218 }
bgneal@183 219 };
bgneal@183 220
bgneal@183 221 function split() {
bgneal@183 222 each(grid, function(row, y) {
bgneal@183 223 each(row, function(cell, x) {
bgneal@183 224 var colSpan, rowSpan, newCell, i;
bgneal@183 225
bgneal@183 226 if (isCellSelected(cell)) {
bgneal@183 227 cell = cell.elm;
bgneal@183 228 colSpan = getSpanVal(cell, 'colspan');
bgneal@183 229 rowSpan = getSpanVal(cell, 'rowspan');
bgneal@183 230
bgneal@183 231 if (colSpan > 1 || rowSpan > 1) {
bgneal@183 232 cell.colSpan = cell.rowSpan = 1;
bgneal@183 233
bgneal@183 234 // Insert cells right
bgneal@183 235 for (i = 0; i < colSpan - 1; i++)
bgneal@183 236 dom.insertAfter(cloneCell(cell), cell);
bgneal@183 237
bgneal@183 238 fillLeftDown(x, y, rowSpan - 1, colSpan);
bgneal@183 239 }
bgneal@183 240 }
bgneal@183 241 });
bgneal@183 242 });
bgneal@183 243 };
bgneal@183 244
bgneal@183 245 function merge(cell, cols, rows) {
bgneal@183 246 var startX, startY, endX, endY, x, y, startCell, endCell, cell, children;
bgneal@183 247
bgneal@183 248 // Use specified cell and cols/rows
bgneal@183 249 if (cell) {
bgneal@183 250 pos = getPos(cell);
bgneal@183 251 startX = pos.x;
bgneal@183 252 startY = pos.y;
bgneal@183 253 endX = startX + (cols - 1);
bgneal@183 254 endY = startY + (rows - 1);
bgneal@183 255 } else {
bgneal@183 256 // Use selection
bgneal@183 257 startX = startPos.x;
bgneal@183 258 startY = startPos.y;
bgneal@183 259 endX = endPos.x;
bgneal@183 260 endY = endPos.y;
bgneal@183 261 }
bgneal@183 262
bgneal@183 263 // Find start/end cells
bgneal@183 264 startCell = getCell(startX, startY);
bgneal@183 265 endCell = getCell(endX, endY);
bgneal@183 266
bgneal@183 267 // Check if the cells exists and if they are of the same part for example tbody = tbody
bgneal@183 268 if (startCell && endCell && startCell.part == endCell.part) {
bgneal@183 269 // Split and rebuild grid
bgneal@183 270 split();
bgneal@183 271 buildGrid();
bgneal@183 272
bgneal@183 273 // Set row/col span to start cell
bgneal@183 274 startCell = getCell(startX, startY).elm;
bgneal@183 275 startCell.colSpan = (endX - startX) + 1;
bgneal@183 276 startCell.rowSpan = (endY - startY) + 1;
bgneal@183 277
bgneal@183 278 // Remove other cells and add it's contents to the start cell
bgneal@183 279 for (y = startY; y <= endY; y++) {
bgneal@183 280 for (x = startX; x <= endX; x++) {
bgneal@183 281 cell = grid[y][x].elm;
bgneal@183 282
bgneal@183 283 if (cell != startCell) {
bgneal@183 284 // Move children to startCell
bgneal@183 285 children = tinymce.grep(cell.childNodes);
bgneal@183 286 each(children, function(node, i) {
bgneal@183 287 // Jump over last BR element
bgneal@183 288 if (node.nodeName != 'BR' || i != children.length - 1)
bgneal@183 289 startCell.appendChild(node);
bgneal@183 290 });
bgneal@183 291
bgneal@183 292 // Remove cell
bgneal@183 293 dom.remove(cell);
bgneal@183 294 }
bgneal@183 295 }
bgneal@183 296 }
bgneal@183 297
bgneal@183 298 // Remove empty rows etc and restore caret location
bgneal@183 299 cleanup();
bgneal@183 300 }
bgneal@183 301 };
bgneal@183 302
bgneal@183 303 function insertRow(before) {
bgneal@183 304 var posY, cell, lastCell, x, rowElm, newRow, newCell, otherCell;
bgneal@183 305
bgneal@183 306 // Find first/last row
bgneal@183 307 each(grid, function(row, y) {
bgneal@183 308 each(row, function(cell, x) {
bgneal@183 309 if (isCellSelected(cell)) {
bgneal@183 310 cell = cell.elm;
bgneal@183 311 rowElm = cell.parentNode;
bgneal@183 312 newRow = rowElm.cloneNode(false);
bgneal@183 313 posY = y;
bgneal@183 314
bgneal@183 315 if (before)
bgneal@183 316 return false;
bgneal@183 317 }
bgneal@183 318 });
bgneal@183 319
bgneal@183 320 if (before)
bgneal@183 321 return !posY;
bgneal@183 322 });
bgneal@183 323
bgneal@183 324 for (x = 0; x < grid[0].length; x++) {
bgneal@183 325 cell = grid[posY][x].elm;
bgneal@183 326
bgneal@183 327 if (cell != lastCell) {
bgneal@183 328 if (!before) {
bgneal@183 329 rowSpan = getSpanVal(cell, 'rowspan');
bgneal@183 330 if (rowSpan > 1) {
bgneal@183 331 cell.rowSpan = rowSpan + 1;
bgneal@183 332 continue;
bgneal@183 333 }
bgneal@183 334 } else {
bgneal@183 335 // Check if cell above can be expanded
bgneal@183 336 if (posY > 0 && grid[posY - 1][x]) {
bgneal@183 337 otherCell = grid[posY - 1][x].elm;
bgneal@183 338 rowSpan = getSpanVal(otherCell, 'rowspan');
bgneal@183 339 if (rowSpan > 1) {
bgneal@183 340 otherCell.rowSpan = rowSpan + 1;
bgneal@183 341 continue;
bgneal@183 342 }
bgneal@183 343 }
bgneal@183 344 }
bgneal@183 345
bgneal@183 346 // Insert new cell into new row
bgneal@183 347 newCell = cloneCell(cell)
bgneal@183 348 newCell.colSpan = cell.colSpan;
bgneal@183 349 newRow.appendChild(newCell);
bgneal@183 350
bgneal@183 351 lastCell = cell;
bgneal@183 352 }
bgneal@183 353 }
bgneal@183 354
bgneal@183 355 if (newRow.hasChildNodes()) {
bgneal@183 356 if (!before)
bgneal@183 357 dom.insertAfter(newRow, rowElm);
bgneal@183 358 else
bgneal@183 359 rowElm.parentNode.insertBefore(newRow, rowElm);
bgneal@183 360 }
bgneal@183 361 };
bgneal@183 362
bgneal@183 363 function insertCol(before) {
bgneal@183 364 var posX, lastCell;
bgneal@183 365
bgneal@183 366 // Find first/last column
bgneal@183 367 each(grid, function(row, y) {
bgneal@183 368 each(row, function(cell, x) {
bgneal@183 369 if (isCellSelected(cell)) {
bgneal@183 370 posX = x;
bgneal@183 371
bgneal@183 372 if (before)
bgneal@183 373 return false;
bgneal@183 374 }
bgneal@183 375 });
bgneal@183 376
bgneal@183 377 if (before)
bgneal@183 378 return !posX;
bgneal@183 379 });
bgneal@183 380
bgneal@183 381 each(grid, function(row, y) {
bgneal@183 382 var cell = row[posX].elm, rowSpan, colSpan;
bgneal@183 383
bgneal@183 384 if (cell != lastCell) {
bgneal@183 385 colSpan = getSpanVal(cell, 'colspan');
bgneal@183 386 rowSpan = getSpanVal(cell, 'rowspan');
bgneal@183 387
bgneal@183 388 if (colSpan == 1) {
bgneal@183 389 if (!before) {
bgneal@183 390 dom.insertAfter(cloneCell(cell), cell);
bgneal@183 391 fillLeftDown(posX, y, rowSpan - 1, colSpan);
bgneal@183 392 } else {
bgneal@183 393 cell.parentNode.insertBefore(cloneCell(cell), cell);
bgneal@183 394 fillLeftDown(posX, y, rowSpan - 1, colSpan);
bgneal@183 395 }
bgneal@183 396 } else
bgneal@183 397 cell.colSpan++;
bgneal@183 398
bgneal@183 399 lastCell = cell;
bgneal@183 400 }
bgneal@183 401 });
bgneal@183 402 };
bgneal@183 403
bgneal@183 404 function deleteCols() {
bgneal@183 405 var cols = [];
bgneal@183 406
bgneal@183 407 // Get selected column indexes
bgneal@183 408 each(grid, function(row, y) {
bgneal@183 409 each(row, function(cell, x) {
bgneal@183 410 if (isCellSelected(cell) && tinymce.inArray(cols, x) === -1) {
bgneal@183 411 each(grid, function(row) {
bgneal@183 412 var cell = row[x].elm, colSpan;
bgneal@183 413
bgneal@183 414 colSpan = getSpanVal(cell, 'colspan');
bgneal@183 415
bgneal@183 416 if (colSpan > 1)
bgneal@183 417 cell.colSpan = colSpan - 1;
bgneal@183 418 else
bgneal@183 419 dom.remove(cell);
bgneal@183 420 });
bgneal@183 421
bgneal@183 422 cols.push(x);
bgneal@183 423 }
bgneal@183 424 });
bgneal@183 425 });
bgneal@183 426
bgneal@183 427 cleanup();
bgneal@183 428 };
bgneal@183 429
bgneal@183 430 function deleteRows() {
bgneal@183 431 var rows;
bgneal@183 432
bgneal@183 433 function deleteRow(tr) {
bgneal@183 434 var nextTr, pos, lastCell;
bgneal@183 435
bgneal@183 436 nextTr = dom.getNext(tr, 'tr');
bgneal@183 437
bgneal@183 438 // Move down row spanned cells
bgneal@183 439 each(tr.cells, function(cell) {
bgneal@183 440 var rowSpan = getSpanVal(cell, 'rowspan');
bgneal@183 441
bgneal@183 442 if (rowSpan > 1) {
bgneal@183 443 cell.rowSpan = rowSpan - 1;
bgneal@183 444 pos = getPos(cell);
bgneal@183 445 fillLeftDown(pos.x, pos.y, 1, 1);
bgneal@183 446 }
bgneal@183 447 });
bgneal@183 448
bgneal@183 449 // Delete cells
bgneal@183 450 pos = getPos(tr.cells[0]);
bgneal@183 451 each(grid[pos.y], function(cell) {
bgneal@183 452 var rowSpan;
bgneal@183 453
bgneal@183 454 cell = cell.elm;
bgneal@183 455
bgneal@183 456 if (cell != lastCell) {
bgneal@183 457 rowSpan = getSpanVal(cell, 'rowspan');
bgneal@183 458
bgneal@183 459 if (rowSpan <= 1)
bgneal@183 460 dom.remove(cell);
bgneal@183 461 else
bgneal@183 462 cell.rowSpan = rowSpan - 1;
bgneal@183 463
bgneal@183 464 lastCell = cell;
bgneal@183 465 }
bgneal@183 466 });
bgneal@183 467 };
bgneal@183 468
bgneal@183 469 // Get selected rows and move selection out of scope
bgneal@183 470 rows = getSelectedRows();
bgneal@183 471
bgneal@183 472 // Delete all selected rows
bgneal@183 473 each(rows.reverse(), function(tr) {
bgneal@183 474 deleteRow(tr);
bgneal@183 475 });
bgneal@183 476
bgneal@183 477 cleanup();
bgneal@183 478 };
bgneal@183 479
bgneal@183 480 function cutRows() {
bgneal@183 481 var rows = getSelectedRows();
bgneal@183 482
bgneal@183 483 dom.remove(rows);
bgneal@183 484 cleanup();
bgneal@183 485
bgneal@183 486 return rows;
bgneal@183 487 };
bgneal@183 488
bgneal@183 489 function copyRows() {
bgneal@183 490 var rows = getSelectedRows();
bgneal@183 491
bgneal@183 492 each(rows, function(row, i) {
bgneal@183 493 rows[i] = row.cloneNode(true);
bgneal@183 494 });
bgneal@183 495
bgneal@183 496 return rows;
bgneal@183 497 };
bgneal@183 498
bgneal@183 499 function pasteRows(rows, before) {
bgneal@183 500 var selectedRows = getSelectedRows(),
bgneal@183 501 targetRow = selectedRows[before ? 0 : selectedRows.length - 1],
bgneal@183 502 targetCellCount = targetRow.cells.length;
bgneal@183 503
bgneal@183 504 // Calc target cell count
bgneal@183 505 each(grid, function(row) {
bgneal@183 506 var match;
bgneal@183 507
bgneal@183 508 targetCellCount = 0;
bgneal@183 509 each(row, function(cell, x) {
bgneal@183 510 if (cell.real)
bgneal@183 511 targetCellCount += cell.colspan;
bgneal@183 512
bgneal@183 513 if (cell.elm.parentNode == targetRow)
bgneal@183 514 match = 1;
bgneal@183 515 });
bgneal@183 516
bgneal@183 517 if (match)
bgneal@183 518 return false;
bgneal@183 519 });
bgneal@183 520
bgneal@183 521 if (!before)
bgneal@183 522 rows.reverse();
bgneal@183 523
bgneal@183 524 each(rows, function(row) {
bgneal@183 525 var cellCount = row.cells.length, cell;
bgneal@183 526
bgneal@183 527 // Remove col/rowspans
bgneal@183 528 for (i = 0; i < cellCount; i++) {
bgneal@183 529 cell = row.cells[i];
bgneal@183 530 cell.colSpan = cell.rowSpan = 1;
bgneal@183 531 }
bgneal@183 532
bgneal@183 533 // Needs more cells
bgneal@183 534 for (i = cellCount; i < targetCellCount; i++)
bgneal@183 535 row.appendChild(cloneCell(row.cells[cellCount - 1]));
bgneal@183 536
bgneal@183 537 // Needs less cells
bgneal@183 538 for (i = targetCellCount; i < cellCount; i++)
bgneal@183 539 dom.remove(row.cells[i]);
bgneal@183 540
bgneal@183 541 // Add before/after
bgneal@183 542 if (before)
bgneal@183 543 targetRow.parentNode.insertBefore(row, targetRow);
bgneal@183 544 else
bgneal@183 545 dom.insertAfter(row, targetRow);
bgneal@183 546 });
bgneal@183 547 };
bgneal@183 548
bgneal@183 549 function getPos(target) {
bgneal@183 550 var pos;
bgneal@183 551
bgneal@183 552 each(grid, function(row, y) {
bgneal@183 553 each(row, function(cell, x) {
bgneal@183 554 if (cell.elm == target) {
bgneal@183 555 pos = {x : x, y : y};
bgneal@183 556 return false;
bgneal@183 557 }
bgneal@183 558 });
bgneal@183 559
bgneal@183 560 return !pos;
bgneal@183 561 });
bgneal@183 562
bgneal@183 563 return pos;
bgneal@183 564 };
bgneal@183 565
bgneal@183 566 function setStartCell(cell) {
bgneal@183 567 startPos = getPos(cell);
bgneal@183 568 };
bgneal@183 569
bgneal@183 570 function findEndPos() {
bgneal@183 571 var pos, maxX, maxY;
bgneal@183 572
bgneal@183 573 maxX = maxY = 0;
bgneal@183 574
bgneal@183 575 each(grid, function(row, y) {
bgneal@183 576 each(row, function(cell, x) {
bgneal@183 577 var colSpan, rowSpan;
bgneal@183 578
bgneal@183 579 if (isCellSelected(cell)) {
bgneal@183 580 cell = grid[y][x];
bgneal@183 581
bgneal@183 582 if (x > maxX)
bgneal@183 583 maxX = x;
bgneal@183 584
bgneal@183 585 if (y > maxY)
bgneal@183 586 maxY = y;
bgneal@183 587
bgneal@183 588 if (cell.real) {
bgneal@183 589 colSpan = cell.colspan - 1;
bgneal@183 590 rowSpan = cell.rowspan - 1;
bgneal@183 591
bgneal@183 592 if (colSpan) {
bgneal@183 593 if (x + colSpan > maxX)
bgneal@183 594 maxX = x + colSpan;
bgneal@183 595 }
bgneal@183 596
bgneal@183 597 if (rowSpan) {
bgneal@183 598 if (y + rowSpan > maxY)
bgneal@183 599 maxY = y + rowSpan;
bgneal@183 600 }
bgneal@183 601 }
bgneal@183 602 }
bgneal@183 603 });
bgneal@183 604 });
bgneal@183 605
bgneal@183 606 return {x : maxX, y : maxY};
bgneal@183 607 };
bgneal@183 608
bgneal@183 609 function setEndCell(cell) {
bgneal@183 610 var startX, startY, endX, endY, maxX, maxY, colSpan, rowSpan;
bgneal@183 611
bgneal@183 612 endPos = getPos(cell);
bgneal@183 613
bgneal@183 614 if (startPos && endPos) {
bgneal@183 615 // Get start/end positions
bgneal@183 616 startX = Math.min(startPos.x, endPos.x);
bgneal@183 617 startY = Math.min(startPos.y, endPos.y);
bgneal@183 618 endX = Math.max(startPos.x, endPos.x);
bgneal@183 619 endY = Math.max(startPos.y, endPos.y);
bgneal@183 620
bgneal@183 621 // Expand end positon to include spans
bgneal@183 622 maxX = endX;
bgneal@183 623 maxY = endY;
bgneal@183 624
bgneal@183 625 // Expand startX
bgneal@183 626 for (y = startY; y <= maxY; y++) {
bgneal@183 627 cell = grid[y][startX];
bgneal@183 628
bgneal@183 629 if (!cell.real) {
bgneal@183 630 if (startX - (cell.colspan - 1) < startX)
bgneal@183 631 startX -= cell.colspan - 1;
bgneal@183 632 }
bgneal@183 633 }
bgneal@183 634
bgneal@183 635 // Expand startY
bgneal@183 636 for (x = startX; x <= maxX; x++) {
bgneal@183 637 cell = grid[startY][x];
bgneal@183 638
bgneal@183 639 if (!cell.real) {
bgneal@183 640 if (startY - (cell.rowspan - 1) < startY)
bgneal@183 641 startY -= cell.rowspan - 1;
bgneal@183 642 }
bgneal@183 643 }
bgneal@183 644
bgneal@183 645 // Find max X, Y
bgneal@183 646 for (y = startY; y <= endY; y++) {
bgneal@183 647 for (x = startX; x <= endX; x++) {
bgneal@183 648 cell = grid[y][x];
bgneal@183 649
bgneal@183 650 if (cell.real) {
bgneal@183 651 colSpan = cell.colspan - 1;
bgneal@183 652 rowSpan = cell.rowspan - 1;
bgneal@183 653
bgneal@183 654 if (colSpan) {
bgneal@183 655 if (x + colSpan > maxX)
bgneal@183 656 maxX = x + colSpan;
bgneal@183 657 }
bgneal@183 658
bgneal@183 659 if (rowSpan) {
bgneal@183 660 if (y + rowSpan > maxY)
bgneal@183 661 maxY = y + rowSpan;
bgneal@183 662 }
bgneal@183 663 }
bgneal@183 664 }
bgneal@183 665 }
bgneal@183 666
bgneal@183 667 // Remove current selection
bgneal@183 668 dom.removeClass(dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
bgneal@183 669
bgneal@183 670 // Add new selection
bgneal@183 671 for (y = startY; y <= maxY; y++) {
bgneal@183 672 for (x = startX; x <= maxX; x++)
bgneal@183 673 dom.addClass(grid[y][x].elm, 'mceSelected');
bgneal@183 674 }
bgneal@183 675 }
bgneal@183 676 };
bgneal@183 677
bgneal@183 678 // Expose to public
bgneal@183 679 tinymce.extend(this, {
bgneal@183 680 deleteTable : deleteTable,
bgneal@183 681 split : split,
bgneal@183 682 merge : merge,
bgneal@183 683 insertRow : insertRow,
bgneal@183 684 insertCol : insertCol,
bgneal@183 685 deleteCols : deleteCols,
bgneal@183 686 deleteRows : deleteRows,
bgneal@183 687 cutRows : cutRows,
bgneal@183 688 copyRows : copyRows,
bgneal@183 689 pasteRows : pasteRows,
bgneal@183 690 getPos : getPos,
bgneal@183 691 setStartCell : setStartCell,
bgneal@183 692 setEndCell : setEndCell
bgneal@183 693 });
bgneal@183 694 };
bgneal@183 695
bgneal@45 696 tinymce.create('tinymce.plugins.TablePlugin', {
bgneal@45 697 init : function(ed, url) {
bgneal@183 698 var winMan, clipboardRows;
bgneal@45 699
bgneal@183 700 function createTableGrid(node) {
bgneal@183 701 var selection = ed.selection, tblElm = ed.dom.getParent(node || selection.getNode(), 'table');
bgneal@183 702
bgneal@183 703 if (tblElm)
bgneal@183 704 return new TableGrid(tblElm, ed.dom, selection);
bgneal@183 705 };
bgneal@183 706
bgneal@183 707 function cleanup() {
bgneal@183 708 // Restore selection possibilities
bgneal@183 709 ed.getBody().style.webkitUserSelect = '';
bgneal@183 710 ed.dom.removeClass(ed.dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
bgneal@183 711 };
bgneal@45 712
bgneal@45 713 // Register buttons
bgneal@45 714 each([
bgneal@45 715 ['table', 'table.desc', 'mceInsertTable', true],
bgneal@45 716 ['delete_table', 'table.del', 'mceTableDelete'],
bgneal@45 717 ['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
bgneal@45 718 ['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
bgneal@45 719 ['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
bgneal@45 720 ['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
bgneal@45 721 ['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
bgneal@45 722 ['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
bgneal@45 723 ['row_props', 'table.row_desc', 'mceTableRowProps', true],
bgneal@45 724 ['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
bgneal@45 725 ['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
bgneal@45 726 ['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
bgneal@45 727 ], function(c) {
bgneal@45 728 ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
bgneal@45 729 });
bgneal@45 730
bgneal@183 731 // Select whole table is a table border is clicked
bgneal@183 732 if (!tinymce.isIE) {
bgneal@183 733 ed.onClick.add(function(ed, e) {
bgneal@183 734 e = e.target;
bgneal@45 735
bgneal@183 736 if (e.nodeName === 'TABLE')
bgneal@183 737 ed.selection.select(e);
bgneal@45 738 });
bgneal@45 739 }
bgneal@45 740
bgneal@183 741 // Handle node change updates
bgneal@183 742 ed.onNodeChange.add(function(ed, cm, n) {
bgneal@183 743 var p;
bgneal@183 744
bgneal@183 745 n = ed.selection.getStart();
bgneal@183 746 p = ed.dom.getParent(n, 'td,th,caption');
bgneal@183 747 cm.setActive('table', n.nodeName === 'TABLE' || !!p);
bgneal@183 748
bgneal@183 749 // Disable table tools if we are in caption
bgneal@183 750 if (p && p.nodeName === 'CAPTION')
bgneal@183 751 p = 0;
bgneal@183 752
bgneal@183 753 cm.setDisabled('delete_table', !p);
bgneal@183 754 cm.setDisabled('delete_col', !p);
bgneal@183 755 cm.setDisabled('delete_table', !p);
bgneal@183 756 cm.setDisabled('delete_row', !p);
bgneal@183 757 cm.setDisabled('col_after', !p);
bgneal@183 758 cm.setDisabled('col_before', !p);
bgneal@183 759 cm.setDisabled('row_after', !p);
bgneal@183 760 cm.setDisabled('row_before', !p);
bgneal@183 761 cm.setDisabled('row_props', !p);
bgneal@183 762 cm.setDisabled('cell_props', !p);
bgneal@183 763 cm.setDisabled('split_cells', !p);
bgneal@183 764 cm.setDisabled('merge_cells', !p);
bgneal@183 765 });
bgneal@183 766
bgneal@183 767 ed.onInit.add(function(ed) {
bgneal@183 768 var startTable, startCell, dom = ed.dom, tableGrid;
bgneal@183 769
bgneal@183 770 winMan = ed.windowManager;
bgneal@183 771
bgneal@183 772 // Add cell selection logic
bgneal@183 773 ed.onMouseDown.add(function(ed, e) {
bgneal@183 774 if (e.button != 2) {
bgneal@183 775 cleanup();
bgneal@183 776
bgneal@183 777 startCell = dom.getParent(e.target, 'td,th');
bgneal@183 778 startTable = dom.getParent(startCell, 'table');
bgneal@183 779 }
bgneal@183 780 });
bgneal@183 781
bgneal@183 782 dom.bind(ed.getDoc(), 'mouseover', function(e) {
bgneal@183 783 var sel, table, target = e.target;
bgneal@183 784
bgneal@183 785 if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
bgneal@183 786 table = dom.getParent(target, 'table');
bgneal@183 787 if (table == startTable) {
bgneal@183 788 if (!tableGrid) {
bgneal@183 789 tableGrid = createTableGrid(table);
bgneal@183 790 tableGrid.setStartCell(startCell);
bgneal@183 791
bgneal@183 792 ed.getBody().style.webkitUserSelect = 'none';
bgneal@183 793 }
bgneal@183 794
bgneal@183 795 tableGrid.setEndCell(target);
bgneal@183 796 }
bgneal@183 797
bgneal@183 798 // Remove current selection
bgneal@183 799 sel = ed.selection.getSel();
bgneal@183 800
bgneal@183 801 if (sel.removeAllRanges)
bgneal@183 802 sel.removeAllRanges();
bgneal@183 803 else
bgneal@183 804 sel.empty();
bgneal@183 805
bgneal@183 806 e.preventDefault();
bgneal@183 807 }
bgneal@183 808 });
bgneal@183 809
bgneal@183 810 ed.onMouseUp.add(function(ed, e) {
bgneal@183 811 var rng, sel = ed.selection, selectedCells, nativeSel = sel.getSel(), walker, node, lastNode, endNode;
bgneal@183 812
bgneal@183 813 // Move selection to startCell
bgneal@183 814 if (startCell) {
bgneal@183 815 if (tableGrid)
bgneal@183 816 ed.getBody().style.webkitUserSelect = '';
bgneal@183 817
bgneal@183 818 function setPoint(node, start) {
bgneal@183 819 var walker = new tinymce.dom.TreeWalker(node, node);
bgneal@183 820
bgneal@183 821 do {
bgneal@183 822 // Text node
bgneal@183 823 if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
bgneal@183 824 if (start)
bgneal@183 825 rng.setStart(node, 0);
bgneal@183 826 else
bgneal@183 827 rng.setEnd(node, node.nodeValue.length);
bgneal@183 828
bgneal@183 829 return;
bgneal@183 830 }
bgneal@183 831
bgneal@183 832 // BR element
bgneal@183 833 if (node.nodeName == 'BR') {
bgneal@183 834 if (start)
bgneal@183 835 rng.setStartBefore(node);
bgneal@183 836 else
bgneal@183 837 rng.setEndBefore(node);
bgneal@183 838
bgneal@183 839 return;
bgneal@183 840 }
bgneal@183 841 } while (node = (start ? walker.next() : walker.prev()));
bgneal@183 842 };
bgneal@183 843
bgneal@183 844 // Try to expand text selection as much as we can only Gecko supports cell selection
bgneal@183 845 selectedCells = dom.select('td.mceSelected,th.mceSelected');
bgneal@183 846 if (selectedCells.length > 0) {
bgneal@183 847 rng = dom.createRng();
bgneal@183 848 node = selectedCells[0];
bgneal@183 849 endNode = selectedCells[selectedCells.length - 1];
bgneal@183 850
bgneal@183 851 setPoint(node, 1);
bgneal@183 852 walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
bgneal@183 853
bgneal@183 854 do {
bgneal@183 855 if (node.nodeName == 'TD' || node.nodeName == 'TH') {
bgneal@183 856 if (!dom.hasClass(node, 'mceSelected'))
bgneal@183 857 break;
bgneal@183 858
bgneal@183 859 lastNode = node;
bgneal@183 860 }
bgneal@183 861 } while (node = walker.next());
bgneal@183 862
bgneal@183 863 setPoint(lastNode);
bgneal@183 864
bgneal@183 865 sel.setRng(rng);
bgneal@183 866 }
bgneal@183 867
bgneal@183 868 ed.nodeChanged();
bgneal@183 869 startCell = tableGrid = startTable = null;
bgneal@183 870 }
bgneal@183 871 });
bgneal@183 872
bgneal@183 873 ed.onKeyUp.add(function(ed, e) {
bgneal@183 874 cleanup();
bgneal@183 875 });
bgneal@183 876
bgneal@183 877 // Add context menu
bgneal@45 878 if (ed && ed.plugins.contextmenu) {
bgneal@45 879 ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
bgneal@45 880 var sm, se = ed.selection, el = se.getNode() || ed.getBody();
bgneal@45 881
bgneal@45 882 if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) {
bgneal@45 883 m.removeAll();
bgneal@45 884
bgneal@45 885 if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
bgneal@45 886 m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
bgneal@45 887 m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
bgneal@45 888 m.addSeparator();
bgneal@45 889 }
bgneal@45 890
bgneal@45 891 if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
bgneal@45 892 m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
bgneal@45 893 m.addSeparator();
bgneal@45 894 }
bgneal@45 895
bgneal@183 896 m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', value : {action : 'insert'}});
bgneal@183 897 m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable'});
bgneal@183 898 m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete'});
bgneal@45 899 m.addSeparator();
bgneal@45 900
bgneal@45 901 // Cell menu
bgneal@45 902 sm = m.addMenu({title : 'table.cell'});
bgneal@183 903 sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps'});
bgneal@183 904 sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells'});
bgneal@183 905 sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells'});
bgneal@45 906
bgneal@45 907 // Row menu
bgneal@45 908 sm = m.addMenu({title : 'table.row'});
bgneal@183 909 sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps'});
bgneal@45 910 sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
bgneal@45 911 sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
bgneal@45 912 sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
bgneal@45 913 sm.addSeparator();
bgneal@45 914 sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
bgneal@45 915 sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
bgneal@183 916 sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}).setDisabled(!clipboardRows);
bgneal@183 917 sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}).setDisabled(!clipboardRows);
bgneal@45 918
bgneal@45 919 // Column menu
bgneal@45 920 sm = m.addMenu({title : 'table.col'});
bgneal@45 921 sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
bgneal@45 922 sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
bgneal@45 923 sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
bgneal@45 924 } else
bgneal@183 925 m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable'});
bgneal@45 926 });
bgneal@45 927 }
bgneal@183 928
bgneal@183 929 // Fixes an issue on Gecko where it's impossible to place the caret behind a table
bgneal@183 930 // This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
bgneal@183 931 if (!tinymce.isIE) {
bgneal@183 932 function fixTableCaretPos() {
bgneal@183 933 var last;
bgneal@183 934
bgneal@183 935 // Skip empty text nodes form the end
bgneal@183 936 for (last = ed.getBody().lastChild; last && last.nodeType == 3 && !last.nodeValue.length; last = last.previousSibling) ;
bgneal@183 937
bgneal@183 938 if (last && last.nodeName == 'TABLE')
bgneal@183 939 ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
bgneal@183 940 };
bgneal@183 941
bgneal@183 942 // Fixes an bug where it's impossible to place the caret before a table in Gecko
bgneal@183 943 // this fix solves it by detecting when the caret is at the beginning of such a table
bgneal@183 944 // and then manually moves the caret infront of the table
bgneal@183 945 if (tinymce.isGecko) {
bgneal@183 946 ed.onKeyDown.add(function(ed, e) {
bgneal@183 947 var rng, table, dom = ed.dom;
bgneal@183 948
bgneal@183 949 // On gecko it's not possible to place the caret before a table
bgneal@183 950 if (e.keyCode == 37 || e.keyCode == 38) {
bgneal@183 951 rng = ed.selection.getRng();
bgneal@183 952 table = dom.getParent(rng.startContainer, 'table');
bgneal@183 953
bgneal@183 954 if (table && ed.getBody().firstChild == table) {
bgneal@183 955 if (isAtStart(rng, table)) {
bgneal@183 956 rng = dom.createRng();
bgneal@183 957
bgneal@183 958 rng.setStartBefore(table);
bgneal@183 959 rng.setEndBefore(table);
bgneal@183 960
bgneal@183 961 ed.selection.setRng(rng);
bgneal@183 962
bgneal@183 963 e.preventDefault();
bgneal@183 964 }
bgneal@183 965 }
bgneal@183 966 }
bgneal@183 967 });
bgneal@183 968 }
bgneal@183 969
bgneal@183 970 ed.onKeyUp.add(fixTableCaretPos);
bgneal@183 971 ed.onSetContent.add(fixTableCaretPos);
bgneal@183 972 ed.onVisualAid.add(fixTableCaretPos);
bgneal@183 973
bgneal@183 974 ed.onPreProcess.add(function(ed, o) {
bgneal@183 975 var last = o.node.lastChild;
bgneal@183 976
bgneal@183 977 if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
bgneal@183 978 ed.dom.remove(last);
bgneal@183 979 });
bgneal@183 980
bgneal@183 981 fixTableCaretPos();
bgneal@183 982 }
bgneal@45 983 });
bgneal@45 984
bgneal@183 985 // Register action commands
bgneal@183 986 each({
bgneal@183 987 mceTableSplitCells : function(grid) {
bgneal@183 988 grid.split();
bgneal@183 989 },
bgneal@183 990
bgneal@183 991 mceTableMergeCells : function(grid) {
bgneal@183 992 var rowSpan, colSpan, cell;
bgneal@183 993
bgneal@183 994 cell = ed.dom.getParent(ed.selection.getNode(), 'th,td');
bgneal@183 995 if (cell) {
bgneal@183 996 rowSpan = cell.rowSpan;
bgneal@183 997 colSpan = cell.colSpan;
bgneal@45 998 }
bgneal@45 999
bgneal@183 1000 if (!ed.dom.select('td.mceSelected,th.mceSelected').length) {
bgneal@183 1001 winMan.open({
bgneal@183 1002 url : url + '/merge_cells.htm',
bgneal@183 1003 width : 240 + parseInt(ed.getLang('table.merge_cells_delta_width', 0)),
bgneal@183 1004 height : 110 + parseInt(ed.getLang('table.merge_cells_delta_height', 0)),
bgneal@183 1005 inline : 1
bgneal@183 1006 }, {
bgneal@183 1007 rows : rowSpan,
bgneal@183 1008 cols : colSpan,
bgneal@183 1009 onaction : function(data) {
bgneal@183 1010 grid.merge(cell, data.cols, data.rows);
bgneal@183 1011 },
bgneal@183 1012 plugin_url : url
bgneal@183 1013 });
bgneal@183 1014 } else
bgneal@183 1015 grid.merge();
bgneal@183 1016 },
bgneal@183 1017
bgneal@183 1018 mceTableInsertRowBefore : function(grid) {
bgneal@183 1019 grid.insertRow(true);
bgneal@183 1020 },
bgneal@183 1021
bgneal@183 1022 mceTableInsertRowAfter : function(grid) {
bgneal@183 1023 grid.insertRow();
bgneal@183 1024 },
bgneal@183 1025
bgneal@183 1026 mceTableInsertColBefore : function(grid) {
bgneal@183 1027 grid.insertCol(true);
bgneal@183 1028 },
bgneal@183 1029
bgneal@183 1030 mceTableInsertColAfter : function(grid) {
bgneal@183 1031 grid.insertCol();
bgneal@183 1032 },
bgneal@183 1033
bgneal@183 1034 mceTableDeleteCol : function(grid) {
bgneal@183 1035 grid.deleteCols();
bgneal@183 1036 },
bgneal@183 1037
bgneal@183 1038 mceTableDeleteRow : function(grid) {
bgneal@183 1039 grid.deleteRows();
bgneal@183 1040 },
bgneal@183 1041
bgneal@183 1042 mceTableCutRow : function(grid) {
bgneal@183 1043 clipboardRows = grid.cutRows();
bgneal@183 1044 },
bgneal@183 1045
bgneal@183 1046 mceTableCopyRow : function(grid) {
bgneal@183 1047 clipboardRows = grid.copyRows();
bgneal@183 1048 },
bgneal@183 1049
bgneal@183 1050 mceTablePasteRowBefore : function(grid) {
bgneal@183 1051 grid.pasteRows(clipboardRows, true);
bgneal@183 1052 },
bgneal@183 1053
bgneal@183 1054 mceTablePasteRowAfter : function(grid) {
bgneal@183 1055 grid.pasteRows(clipboardRows);
bgneal@183 1056 },
bgneal@183 1057
bgneal@183 1058 mceTableDelete : function(grid) {
bgneal@183 1059 grid.deleteTable();
bgneal@45 1060 }
bgneal@183 1061 }, function(func, name) {
bgneal@183 1062 ed.addCommand(name, function() {
bgneal@183 1063 var grid = createTableGrid();
bgneal@183 1064
bgneal@183 1065 if (grid) {
bgneal@183 1066 func(grid);
bgneal@183 1067 ed.execCommand('mceRepaint');
bgneal@183 1068 cleanup();
bgneal@183 1069 }
bgneal@183 1070 });
bgneal@45 1071 });
bgneal@45 1072
bgneal@183 1073 // Register dialog commands
bgneal@183 1074 each({
bgneal@183 1075 mceInsertTable : function(val) {
bgneal@183 1076 winMan.open({
bgneal@183 1077 url : url + '/table.htm',
bgneal@183 1078 width : 400 + parseInt(ed.getLang('table.table_delta_width', 0)),
bgneal@183 1079 height : 320 + parseInt(ed.getLang('table.table_delta_height', 0)),
bgneal@183 1080 inline : 1
bgneal@183 1081 }, {
bgneal@183 1082 plugin_url : url,
bgneal@183 1083 action : val ? val.action : 0
bgneal@183 1084 });
bgneal@183 1085 },
bgneal@45 1086
bgneal@183 1087 mceTableRowProps : function() {
bgneal@183 1088 winMan.open({
bgneal@183 1089 url : url + '/row.htm',
bgneal@183 1090 width : 400 + parseInt(ed.getLang('table.rowprops_delta_width', 0)),
bgneal@183 1091 height : 295 + parseInt(ed.getLang('table.rowprops_delta_height', 0)),
bgneal@183 1092 inline : 1
bgneal@183 1093 }, {
bgneal@183 1094 plugin_url : url
bgneal@183 1095 });
bgneal@183 1096 },
bgneal@183 1097
bgneal@183 1098 mceTableCellProps : function() {
bgneal@183 1099 winMan.open({
bgneal@183 1100 url : url + '/cell.htm',
bgneal@183 1101 width : 400 + parseInt(ed.getLang('table.cellprops_delta_width', 0)),
bgneal@183 1102 height : 295 + parseInt(ed.getLang('table.cellprops_delta_height', 0)),
bgneal@183 1103 inline : 1
bgneal@183 1104 }, {
bgneal@183 1105 plugin_url : url
bgneal@45 1106 });
bgneal@45 1107 }
bgneal@183 1108 }, function(func, name) {
bgneal@183 1109 ed.addCommand(name, function(ui, val) {
bgneal@183 1110 func(val);
bgneal@183 1111 });
bgneal@45 1112 });
bgneal@45 1113 }
bgneal@45 1114 });
bgneal@45 1115
bgneal@45 1116 // Register plugin
bgneal@45 1117 tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
bgneal@183 1118 })(tinymce);