annotate media/js/tiny_mce/plugins/table/editor_plugin_src.js @ 217:237710206167

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