[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /* Import plugin specific language pack */ 2 tinyMCE.importPluginLanguagePack('table', 'en,ar,cs,da,de,el,es,fi,fr_ca,hu,it,ja,ko,nl,no,pl,pt,sv,tw,zh_cn,fr,de'); 3 4 function TinyMCE_table_initInstance(inst) { 5 if (tinyMCE.isGecko) 6 tinyMCE.addEvent(inst.getDoc(), "mouseup", TinyMCE_table_mouseDownHandler); 7 8 inst.tableRowClipboard = null; 9 } 10 11 function TinyMCE_table_mouseDownHandler(e) { 12 var elm = tinyMCE.isMSIE ? event.srcElement : e.target; 13 var focusElm = tinyMCE.selectedInstance.getFocusElement(); 14 15 // If press on special Mozilla create TD/TR thingie 16 if (elm.nodeName == "BODY" && (focusElm.nodeName == "TD" || (focusElm.parentNode && focusElm.parentNode.nodeName == "TD"))) { 17 window.setTimeout(function() { 18 var tableElm = tinyMCE.getParentElement(focusElm, "table"); 19 tinyMCE.handleVisualAid(tableElm, true, tinyMCE.settings['visual']); 20 }, 10); 21 } 22 } 23 24 /** 25 * Returns the HTML contents of the table control. 26 */ 27 function TinyMCE_table_getControlHTML(control_name) { 28 var controls = new Array( 29 ['table', 'table.gif', '{$lang_table_desc}', 'mceInsertTable', true], 30 ['delete_col', 'table_delete_col.gif', '{$lang_table_delete_col_desc}', 'mceTableDeleteCol'], 31 ['delete_row', 'table_delete_row.gif', '{$lang_table_delete_row_desc}', 'mceTableDeleteRow'], 32 ['col_after', 'table_insert_col_after.gif', '{$lang_table_insert_col_after_desc}', 'mceTableInsertColAfter'], 33 ['col_before', 'table_insert_col_before.gif', '{$lang_table_insert_col_before_desc}', 'mceTableInsertColBefore'], 34 ['row_after', 'table_insert_row_after.gif', '{$lang_table_insert_row_after_desc}', 'mceTableInsertRowAfter'], 35 ['row_before', 'table_insert_row_before.gif', '{$lang_table_insert_row_before_desc}', 'mceTableInsertRowBefore'], 36 ['row_props', 'table_row_props.gif', '{$lang_table_row_desc}', 'mceTableRowProps', true], 37 ['cell_props', 'table_cell_props.gif', '{$lang_table_cell_desc}', 'mceTableCellProps', true], 38 ['split_cells', 'table_split_cells.gif', '{$lang_table_split_cells_desc}', 'mceTableSplitCells', true], 39 ['merge_cells', 'table_merge_cells.gif', '{$lang_table_merge_cells_desc}', 'mceTableMergeCells', true]); 40 41 // Render table control 42 for (var i=0; i<controls.length; i++) { 43 var but = controls[i]; 44 var safariPatch = '" onclick="'; 45 46 if (tinyMCE.isSafari) 47 safariPatch = ""; 48 49 if (but[0] == control_name && (tinyMCE.isMSIE || !tinyMCE.settings['button_tile_map'])) 50 return '<img id="{$editor_id}_' + but[0] + '" src="{$pluginurl}/images/' + but[1] + '" title="' + but[2] + '" width="20" height="20" class="mceButtonDisabled" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');' + safariPatch + 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + but[3] + '\', ' + (but.length > 4 ? but[4] : false) + (but.length > 5 ? ', \'' + but[5] + '\'' : '') + ')">'; 51 else if (but[0] == control_name) 52 return '<img id="{$editor_id}_' + but[0] + '" src="{$themeurl}/images/spacer.gif" style="background-image:url({$pluginurl}/images/buttons.gif); background-position: ' + (0-(i*20)) + 'px 0px" title="' + but[2] + '" width="20" height="20" class="mceButtonDisabled" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');' + safariPatch + 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + but[3] + '\', ' + (but.length > 4 ? but[4] : false) + (but.length > 5 ? ', \'' + but[5] + '\'' : '') + ')">'; 53 } 54 55 // Special tablecontrols 56 if (control_name == "tablecontrols") { 57 var html = ""; 58 59 html += tinyMCE.getControlHTML("table"); 60 html += tinyMCE.getControlHTML("separator"); 61 html += tinyMCE.getControlHTML("row_props"); 62 html += tinyMCE.getControlHTML("cell_props"); 63 html += tinyMCE.getControlHTML("separator"); 64 html += tinyMCE.getControlHTML("row_before"); 65 html += tinyMCE.getControlHTML("row_after"); 66 html += tinyMCE.getControlHTML("delete_row"); 67 html += tinyMCE.getControlHTML("separator"); 68 html += tinyMCE.getControlHTML("col_before"); 69 html += tinyMCE.getControlHTML("col_after"); 70 html += tinyMCE.getControlHTML("delete_col"); 71 html += tinyMCE.getControlHTML("separator"); 72 html += tinyMCE.getControlHTML("split_cells"); 73 html += tinyMCE.getControlHTML("merge_cells"); 74 75 return html; 76 } 77 78 return ""; 79 } 80 81 /** 82 * Executes the table commands. 83 */ 84 function TinyMCE_table_execCommand(editor_id, element, command, user_interface, value) { 85 var inst = tinyMCE.getInstanceById(editor_id); 86 var focusElm = inst.getFocusElement(); 87 var trElm = tinyMCE.getParentElement(focusElm, "tr"); 88 var tdElm = tinyMCE.getParentElement(focusElm, "td"); 89 var tableElm = tinyMCE.getParentElement(focusElm, "table"); 90 var doc = inst.contentWindow.document; 91 var tableBorder = tableElm ? tableElm.getAttribute("border") : ""; 92 93 // Get first TD if no TD found 94 if (trElm && tdElm == null) 95 tdElm = trElm.cells[0]; 96 97 // ------- Inner functions --------- 98 function inArray(ar, v) { 99 for (var i=0; i<ar.length; i++) { 100 // Is array 101 if (ar[i].length > 0 && inArray(ar[i], v)) 102 return true; 103 104 // Found value 105 if (ar[i] == v) 106 return true; 107 } 108 109 return false; 110 } 111 112 function makeTD() { 113 var newTD = doc.createElement("td"); 114 newTD.innerHTML = " "; 115 } 116 117 function getColRowSpan(td) { 118 var colspan = tinyMCE.getAttrib(td, "colspan"); 119 var rowspan = tinyMCE.getAttrib(td, "rowspan"); 120 121 colspan = colspan == "" ? 1 : parseInt(colspan); 122 rowspan = rowspan == "" ? 1 : parseInt(rowspan); 123 124 return {colspan : colspan, rowspan : rowspan}; 125 } 126 127 function getCellPos(grid, td) { 128 for (var y=0; y<grid.length; y++) { 129 for (var x=0; x<grid[y].length; x++) { 130 if (grid[y][x] == td) 131 return {cellindex : x, rowindex : y}; 132 } 133 } 134 135 return null; 136 } 137 138 function getCell(grid, row, col) { 139 if (grid[row] && grid[row][col]) 140 return grid[row][col]; 141 142 return null; 143 } 144 145 function getTableGrid(table) { 146 var grid = new Array(); 147 var rows = table.rows; 148 149 for (var y=0; y<rows.length; y++) { 150 for (var x=0; x<rows[y].cells.length; x++) { 151 var td = rows[y].cells[x]; 152 var sd = getColRowSpan(td); 153 154 // All ready filled 155 for (xstart = x; grid[y] && grid[y][xstart]; xstart++) ; 156 157 // Fill box 158 for (var y2=y; y2<y+sd['rowspan']; y2++) { 159 if (!grid[y2]) 160 grid[y2] = new Array(); 161 162 for (var x2=xstart; x2<xstart+sd['colspan']; x2++) { 163 grid[y2][x2] = td; 164 } 165 } 166 } 167 } 168 169 return grid; 170 } 171 172 function trimRow(table, tr, td, new_tr) { 173 var grid = getTableGrid(table); 174 var cpos = getCellPos(grid, td); 175 176 // Time to crop away some 177 if (new_tr.cells.length != tr.childNodes.length) { 178 var cells = tr.childNodes; 179 var lastElm = null; 180 181 for (var x=0; td = getCell(grid, cpos.rowindex, x); x++) { 182 var remove = true; 183 var sd = getColRowSpan(td); 184 185 // Remove due to rowspan 186 if (inArray(cells, td)) { 187 new_tr.childNodes[x]._delete = true; 188 } else if ((lastElm == null || td != lastElm) && sd.colspan > 1) { // Remove due to colspan 189 for (var i=x; i<x+td.colSpan; i++) 190 new_tr.childNodes[i]._delete = true; 191 } 192 193 if ((lastElm == null || td != lastElm) && sd.rowspan > 1) 194 td.rowSpan = sd.rowspan + 1; 195 196 lastElm = td; 197 } 198 199 deleteMarked(tableElm); 200 } 201 } 202 203 function prevElm(node, name) { 204 while ((node = node.previousSibling) != null) { 205 if (node.nodeName == name) 206 return node; 207 } 208 209 return null; 210 } 211 212 function nextElm(node, name) { 213 while ((node = node.nextSibling) != null) { 214 if (node.nodeName == name) 215 return node; 216 } 217 218 return null; 219 } 220 221 function deleteMarked(tbl) { 222 if (tbl.rows == 0) 223 return; 224 225 var tr = tbl.rows[0]; 226 do { 227 var next = nextElm(tr, "TR"); 228 229 // Delete row 230 if (tr._delete) { 231 tr.parentNode.removeChild(tr); 232 continue; 233 } 234 235 // Delete cells 236 var td = tr.cells[0]; 237 if (td.cells > 1) { 238 do { 239 var nexttd = nextElm(td, "TD"); 240 241 if (td._delete) 242 td.parentNode.removeChild(td); 243 } while ((td = nexttd) != null); 244 } 245 } while ((tr = next) != null); 246 } 247 248 function addRows(td_elm, tr_elm, rowspan) { 249 // Add rows 250 td_elm.rowSpan = 1; 251 var trNext = nextElm(tr_elm, "TR"); 252 for (var i=1; i<rowspan && trNext; i++) { 253 var newTD = doc.createElement("td"); 254 newTD.innerHTML = " "; 255 256 if (tinyMCE.isMSIE) 257 trNext.insertBefore(newTD, trNext.cells(td_elm.cellIndex)); 258 else 259 trNext.insertBefore(newTD, trNext.cells[td_elm.cellIndex]); 260 261 trNext = nextElm(trNext, "TR"); 262 } 263 } 264 265 function copyRow(doc, table, tr) { 266 var grid = getTableGrid(table); 267 var newTR = tr.cloneNode(false); 268 var cpos = getCellPos(grid, tr.cells[0]); 269 var lastCell = null; 270 var tableBorder = tinyMCE.getAttrib(table, "border"); 271 var tdElm = null; 272 273 for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) { 274 var newTD = null; 275 276 if (lastCell != tdElm) { 277 for (var i=0; i<tr.cells.length; i++) { 278 if (tdElm == tr.cells[i]) { 279 newTD = tdElm.cloneNode(true); 280 break; 281 } 282 } 283 } 284 285 if (newTD == null) { 286 newTD = doc.createElement("td"); 287 newTD.innerHTML = " "; 288 } 289 290 // Reset col/row span 291 newTD.colSpan = 1; 292 newTD.rowSpan = 1; 293 294 newTR.appendChild(newTD); 295 296 lastCell = tdElm; 297 } 298 299 return newTR; 300 } 301 302 // ---- Commands ----- 303 304 // Handle commands 305 switch (command) { 306 case "mceTableRowProps": 307 if (trElm == null) 308 return true; 309 310 if (user_interface) { 311 // Setup template 312 var template = new Array(); 313 314 template['file'] = '../../plugins/table/row.htm'; 315 316 if (tinyMCE.settings['table_color_fields']) { 317 template['width'] = 400; 318 template['height'] = 220; 319 } else { 320 template['width'] = 340; 321 template['height'] = 220; 322 } 323 324 // Open window 325 tinyMCE.openWindow(template, {editor_id : inst.editorId, align : tinyMCE.getAttrib(trElm, 'align'), valign : tinyMCE.getAttrib(trElm, 'valign'), height : tinyMCE.getAttrib(trElm, 'height'), className : tinyMCE.getVisualAidClass(tinyMCE.getAttrib(trElm, 'class'), false), bordercolor : tinyMCE.getAttrib(trElm, 'bordercolor'), bgcolor : tinyMCE.getAttrib(trElm, 'bgcolor')}); 326 } else { 327 inst.execCommand("mceAddUndoLevel"); 328 329 trElm.setAttribute('align', value['align']); 330 trElm.setAttribute('vAlign', value['valign']); 331 trElm.setAttribute('height', value['height']); 332 trElm.setAttribute('bordercolor', value['bordercolor']); 333 trElm.setAttribute('bgcolor', value['bgcolor']); 334 tinyMCE.setAttrib(trElm, 'class', value['className']); 335 336 trElm.borderColor = value['bordercolor']; 337 trElm.bgColor = value['bgcolor']; 338 } 339 340 tinyMCE.triggerNodeChange(); 341 return true; 342 343 case "mceTableCellProps": 344 if (tdElm == null) 345 return true; 346 347 if (user_interface) { 348 // Setup template 349 var template = new Array(); 350 351 template['file'] = '../../plugins/table/cell.htm'; 352 353 if (tinyMCE.settings['table_color_fields']) { 354 template['width'] = 400; 355 template['height'] = 240; 356 } else { 357 template['width'] = 340; 358 template['height'] = 220; 359 } 360 361 // Open window 362 tinyMCE.openWindow(template, {editor_id : inst.editorId, align : tinyMCE.getAttrib(tdElm, 'align'), valign : tinyMCE.getAttrib(tdElm, 'valign'), width : tinyMCE.getAttrib(tdElm, 'width'), height : tinyMCE.getAttrib(tdElm, 'height'), className : tinyMCE.getVisualAidClass(tinyMCE.getAttrib(tdElm, 'class'), false), bordercolor : tinyMCE.getAttrib(tdElm, 'bordercolor'), bgcolor : tinyMCE.getAttrib(tdElm, 'bgcolor')}); 363 } else { 364 inst.execCommand("mceAddUndoLevel"); 365 366 tdElm.setAttribute('align', value['align']); 367 tdElm.setAttribute('vAlign', value['valign']); 368 tdElm.setAttribute('width', value['width']); 369 tdElm.setAttribute('height', value['height']); 370 tdElm.setAttribute('bordercolor', value['bordercolor']); 371 tdElm.setAttribute('bgcolor', value['bgcolor']); 372 tinyMCE.setAttrib(tdElm, 'class', tinyMCE.getVisualAidClass(value['className'])); 373 374 tdElm.borderColor = value['bordercolor']; 375 tdElm.bgColor = value['bgcolor']; 376 } 377 378 tinyMCE.triggerNodeChange(); 379 return true; 380 381 case "mceInsertTable": 382 if (user_interface) { 383 var cols = 2, rows = 2, border = 0, cellpadding = "", cellspacing = "", align = "", width = "", height = "", bordercolor = "", bgcolor = "", action = "insert", className = ""; 384 385 tinyMCE.tableElm = tinyMCE.getParentElement(inst.getFocusElement(), "table"); 386 387 if (tinyMCE.tableElm) { 388 var rowsAr = tinyMCE.tableElm.rows; 389 var cols = 0; 390 for (var i=0; i<rowsAr.length; i++) 391 if (rowsAr[i].cells.length > cols) 392 cols = rowsAr[i].cells.length; 393 394 cols = cols; 395 rows = rowsAr.length; 396 397 border = tinyMCE.getAttrib(tinyMCE.tableElm, 'border', border); 398 cellpadding = tinyMCE.getAttrib(tinyMCE.tableElm, 'cellpadding', ""); 399 cellspacing = tinyMCE.getAttrib(tinyMCE.tableElm, 'cellspacing', ""); 400 width = tinyMCE.getAttrib(tinyMCE.tableElm, 'width', width); 401 height = tinyMCE.getAttrib(tinyMCE.tableElm, 'height', height); 402 bordercolor = tinyMCE.getAttrib(tinyMCE.tableElm, 'bordercolor', bordercolor); 403 bgcolor = tinyMCE.getAttrib(tinyMCE.tableElm, 'bgcolor', bgcolor); 404 align = tinyMCE.getAttrib(tinyMCE.tableElm, 'align', align); 405 className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(tinyMCE.tableElm, 'class'), false); 406 407 if (tinyMCE.isMSIE) { 408 width = tinyMCE.tableElm.style.pixelWidth == 0 ? tinyMCE.tableElm.getAttribute("width") : tinyMCE.tableElm.style.pixelWidth; 409 height = tinyMCE.tableElm.style.pixelHeight == 0 ? tinyMCE.tableElm.getAttribute("height") : tinyMCE.tableElm.style.pixelHeight; 410 } 411 412 action = "update"; 413 } 414 415 // Setup template 416 var template = new Array(); 417 418 template['file'] = '../../plugins/table/table.htm'; 419 if (tinyMCE.settings['table_color_fields']) { 420 template['width'] = 400; 421 template['height'] = 240; 422 } else { 423 template['width'] = 340; 424 template['height'] = 220; 425 } 426 427 // Language specific width and height addons 428 template['width'] += tinyMCE.getLang('lang_insert_table_delta_width', 0); 429 template['height'] += tinyMCE.getLang('lang_insert_table_delta_height', 0); 430 431 // Open window 432 tinyMCE.openWindow(template, {editor_id : inst.editorId, cols : cols, rows : rows, border : border, cellpadding : cellpadding, cellspacing : cellspacing, align : align, width : width, height : height, bordercolor : bordercolor, bgcolor : bgcolor, action : action, className : className}); 433 } else { 434 var html = ''; 435 var cols = 2, rows = 2, border = 0, cellpadding = -1, cellspacing = -1, align, width, height, className; 436 437 if (typeof(value) == 'object') { 438 cols = value['cols']; 439 rows = value['rows']; 440 border = value['border'] != "" ? value['border'] : 0; 441 cellpadding = value['cellpadding'] != "" ? value['cellpadding'] : -1; 442 cellspacing = value['cellspacing'] != "" ? value['cellspacing'] : -1; 443 align = value['align']; 444 width = value['width']; 445 height = value['height']; 446 bordercolor = value['bordercolor']; 447 bgcolor = value['bgcolor']; 448 className = value['className']; 449 } 450 451 // Update table 452 if (tinyMCE.tableElm) { 453 inst.execCommand("mceAddUndoLevel"); 454 455 tinyMCE.setAttrib(tinyMCE.tableElm, 'cellPadding', cellpadding, true); 456 tinyMCE.setAttrib(tinyMCE.tableElm, 'cellSpacing', cellspacing, true); 457 tinyMCE.setAttrib(tinyMCE.tableElm, 'border', border, true); 458 tinyMCE.setAttrib(tinyMCE.tableElm, 'width', width, true); 459 tinyMCE.setAttrib(tinyMCE.tableElm, 'height', height, true); 460 tinyMCE.setAttrib(tinyMCE.tableElm, 'bordercolor', bordercolor); 461 tinyMCE.setAttrib(tinyMCE.tableElm, 'bgcolor', bgcolor); 462 tinyMCE.setAttrib(tinyMCE.tableElm, 'align', align); 463 tinyMCE.setAttrib(tinyMCE.tableElm, 'class', className); 464 465 if (tinyMCE.isMSIE) { 466 tinyMCE.tableElm.style.pixelWidth = (width == null || width == "") ? 0 : width; 467 tinyMCE.tableElm.style.pixelHeight = (height == null || height == "") ? 0 : height; 468 tinyMCE.tableElm.borderColor = bordercolor; 469 tinyMCE.tableElm.bgColor = bgcolor; 470 } 471 472 tinyMCE.handleVisualAid(tinyMCE.tableElm, false, inst.visualAid); 473 474 // Fix for stange MSIE align bug 475 tinyMCE.tableElm.outerHTML = tinyMCE.tableElm.outerHTML; 476 477 //inst.contentWindow.dispatchEvent(createEvent("click")); 478 479 tinyMCE.triggerNodeChange(); 480 return true; 481 } 482 483 // Create new table 484 html += '<table border="' + border + '" '; 485 486 if (cellpadding != -1) 487 html += 'cellpadding="' + cellpadding + '" '; 488 489 if (cellspacing != -1) 490 html += 'cellspacing="' + cellspacing + '" '; 491 492 if (width != 0 && width != "") 493 html += 'width="' + width + '" '; 494 495 if (height != 0 && height != "") 496 html += 'height="' + height + '" '; 497 498 if (bordercolor != 0 && bordercolor != "") 499 html += 'bordercolor="' + bordercolor + '" '; 500 501 if (bgcolor != 0 && bgcolor != "") 502 html += 'bgcolor="' + bgcolor + '" '; 503 504 if (align) 505 html += 'align="' + align + '" '; 506 507 if (className) 508 html += 'class="' + tinyMCE.getVisualAidClass(className, border == 0) + '" '; 509 510 html += '>'; 511 512 for (var y=0; y<rows; y++) { 513 html += "<tr>"; 514 515 for (var x=0; x<cols; x++) 516 html += '<td> </td>'; 517 518 html += "</tr>"; 519 } 520 521 html += "</table>"; 522 523 inst.execCommand('mceInsertContent', false, html); 524 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual']); 525 } 526 527 return true; 528 529 case "mceTableSplitCells": 530 case "mceTableMergeCells": 531 case "mceTableInsertRowBefore": 532 case "mceTableInsertRowAfter": 533 case "mceTableDeleteRow": 534 case "mceTableInsertColBefore": 535 case "mceTableInsertColAfter": 536 case "mceTableDeleteCol": 537 case "mceTableCutRow": 538 case "mceTableCopyRow": 539 case "mceTablePasteRowBefore": 540 case "mceTablePasteRowAfter": 541 inst.execCommand("mceAddUndoLevel"); 542 543 // No table just return (invalid command) 544 if (!tableElm) 545 return true; 546 547 // Table has a tbody use that reference 548 if (tableElm.firstChild && tableElm.firstChild.nodeName.toLowerCase() == "tbody") 549 tableElm = tableElm.firstChild; 550 551 if (tableElm && trElm) { 552 switch (command) { 553 case "mceTableInsertRowBefore": 554 if (!trElm || !tdElm) 555 return true; 556 557 var grid = getTableGrid(tableElm); 558 var cpos = getCellPos(grid, tdElm); 559 var newTR = doc.createElement("tr"); 560 var lastTDElm = null; 561 562 cpos.rowindex--; 563 if (cpos.rowindex < 0) 564 cpos.rowindex = 0; 565 566 // Create cells 567 for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) { 568 if (tdElm != lastTDElm) { 569 var sd = getColRowSpan(tdElm); 570 571 if (sd['rowspan'] == 1) { 572 var newTD = doc.createElement("td"); 573 574 newTD.innerHTML = " "; 575 newTD.colSpan = tdElm.colSpan; 576 577 newTR.appendChild(newTD); 578 } else 579 tdElm.rowSpan = sd['rowspan'] + 1; 580 581 lastTDElm = tdElm; 582 } 583 } 584 585 trElm.parentNode.insertBefore(newTR, trElm); 586 break; 587 588 case "mceTableCutRow": 589 if (!trElm || !tdElm) 590 return true; 591 592 inst.tableRowClipboard = copyRow(doc, tableElm, trElm); 593 inst.execCommand("mceTableDeleteRow"); 594 break; 595 596 case "mceTableCopyRow": 597 if (!trElm || !tdElm) 598 return true; 599 600 inst.tableRowClipboard = copyRow(doc, tableElm, trElm); 601 break; 602 603 case "mceTablePasteRowBefore": 604 if (!trElm || !tdElm) 605 return true; 606 607 var newTR = inst.tableRowClipboard.cloneNode(true); 608 609 var prevTR = prevElm(trElm, "TR"); 610 if (prevTR != null) 611 trimRow(tableElm, prevTR, prevTR.cells[0], newTR); 612 613 trElm.parentNode.insertBefore(newTR, trElm); 614 break; 615 616 case "mceTablePasteRowAfter": 617 if (!trElm || !tdElm) 618 return true; 619 620 var nextTR = nextElm(trElm, "TR"); 621 var newTR = inst.tableRowClipboard.cloneNode(true); 622 623 trimRow(tableElm, trElm, tdElm, newTR); 624 625 if (nextTR == null) 626 trElm.parentNode.appendChild(newTR); 627 else 628 nextTR.parentNode.insertBefore(newTR, nextTR); 629 630 break; 631 632 case "mceTableInsertRowAfter": 633 if (!trElm || !tdElm) 634 return true; 635 636 var grid = getTableGrid(tableElm); 637 var cpos = getCellPos(grid, tdElm); 638 var newTR = doc.createElement("tr"); 639 var lastTDElm = null; 640 641 // Create cells 642 for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) { 643 if (tdElm != lastTDElm) { 644 var sd = getColRowSpan(tdElm); 645 646 if (sd['rowspan'] == 1) { 647 var newTD = doc.createElement("td"); 648 649 newTD.innerHTML = " "; 650 newTD.colSpan = tdElm.colSpan; 651 652 newTR.appendChild(newTD); 653 } else 654 tdElm.rowSpan = sd['rowspan'] + 1; 655 656 lastTDElm = tdElm; 657 } 658 } 659 660 if (newTR.hasChildNodes()) { 661 var nextTR = nextElm(trElm, "TR"); 662 if (nextTR) 663 nextTR.parentNode.insertBefore(newTR, nextTR); 664 else 665 tableElm.appendChild(newTR); 666 } 667 break; 668 669 case "mceTableDeleteRow": 670 if (!trElm || !tdElm) 671 return true; 672 673 var grid = getTableGrid(tableElm); 674 var cpos = getCellPos(grid, tdElm); 675 676 // Only one row, remove whole table 677 if (grid.length == 1) { 678 tableElm.parentNode.removeChild(tableElm); 679 return true; 680 } 681 682 // Move down row spanned cells 683 var cells = trElm.cells; 684 var nextTR = nextElm(trElm, "TR"); 685 for (var x=0; x<cells.length; x++) { 686 if (cells[x].rowSpan > 1) { 687 var newTD = cells[x].cloneNode(true); 688 var sd = getColRowSpan(cells[x]); 689 690 newTD.rowSpan = sd.rowspan - 1; 691 692 var nextTD = nextTR.cells[x]; 693 694 if (nextTD == null) 695 nextTR.appendChild(newTD); 696 else 697 nextTR.insertBefore(newTD, nextTD); 698 } 699 } 700 701 // Delete cells 702 var lastTDElm = null; 703 for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) { 704 if (tdElm != lastTDElm) { 705 var sd = getColRowSpan(tdElm); 706 707 if (sd.rowspan > 1) { 708 tdElm.rowSpan = sd.rowspan - 1; 709 } else { 710 trElm = tdElm.parentNode; 711 712 if (trElm.parentNode) 713 trElm._delete = true; 714 } 715 716 lastTDElm = tdElm; 717 } 718 } 719 720 deleteMarked(tableElm); 721 722 cpos.rowindex--; 723 if (cpos.rowindex < 0) 724 cpos.rowindex = 0; 725 726 inst.selectNode(getCell(grid, cpos.rowindex, 0), true, true); 727 break; 728 729 case "mceTableInsertColBefore": 730 if (!trElm || !tdElm) 731 return true; 732 733 var grid = getTableGrid(tableElm); 734 var cpos = getCellPos(grid, tdElm); 735 var lastTDElm = null; 736 737 for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { 738 if (tdElm != lastTDElm) { 739 var sd = getColRowSpan(tdElm); 740 741 if (sd['colspan'] == 1) { 742 var newTD = doc.createElement("td"); 743 744 newTD.innerHTML = " "; 745 newTD.rowSpan = tdElm.rowSpan; 746 747 tdElm.parentNode.insertBefore(newTD, tdElm); 748 } else 749 tdElm.colSpan++; 750 751 lastTDElm = tdElm; 752 } 753 } 754 break; 755 756 case "mceTableInsertColAfter": 757 if (!trElm || !tdElm) 758 return true; 759 760 var grid = getTableGrid(tableElm); 761 var cpos = getCellPos(grid, tdElm); 762 var lastTDElm = null; 763 764 for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { 765 if (tdElm != lastTDElm) { 766 var sd = getColRowSpan(tdElm); 767 768 if (sd['colspan'] == 1) { 769 var newTD = doc.createElement("td"); 770 771 newTD.innerHTML = " "; 772 newTD.rowSpan = tdElm.rowSpan; 773 774 var nextTD = nextElm(tdElm, "TD"); 775 if (nextTD == null) 776 tdElm.parentNode.appendChild(newTD); 777 else 778 nextTD.parentNode.insertBefore(newTD, nextTD); 779 } else 780 tdElm.colSpan++; 781 782 lastTDElm = tdElm; 783 } 784 } 785 break; 786 787 case "mceTableDeleteCol": 788 if (!trElm || !tdElm) 789 return true; 790 791 var grid = getTableGrid(tableElm); 792 var cpos = getCellPos(grid, tdElm); 793 var lastTDElm = null; 794 795 // Only one col, remove whole table 796 if (grid.length > 1 && grid[0].length <= 1) { 797 tableElm.parentNode.removeChild(tableElm); 798 return true; 799 } 800 801 // Delete cells 802 for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { 803 if (tdElm != lastTDElm) { 804 var sd = getColRowSpan(tdElm); 805 806 if (sd['colspan'] > 1) 807 tdElm.colSpan = sd['colspan'] - 1; 808 else { 809 if (tdElm.parentNode) 810 tdElm.parentNode.removeChild(tdElm); 811 } 812 813 lastTDElm = tdElm; 814 } 815 } 816 817 cpos.cellindex--; 818 if (cpos.cellindex < 0) 819 cpos.cellindex = 0; 820 821 inst.selectNode(getCell(grid, 0, cpos.cellindex), true, true); 822 break; 823 824 case "mceTableSplitCells": 825 if (!trElm || !tdElm) 826 return true; 827 828 var spandata = getColRowSpan(tdElm); 829 830 var colspan = spandata["colspan"]; 831 var rowspan = spandata["rowspan"]; 832 833 // Needs splitting 834 if (colspan > 1 || rowspan > 1) { 835 // Generate cols 836 tdElm.colSpan = 1; 837 for (var i=1; i<colspan; i++) { 838 var newTD = doc.createElement("td"); 839 840 newTD.innerHTML = " "; 841 842 trElm.insertBefore(newTD, nextElm(tdElm, "TD")); 843 844 if (rowspan > 1) 845 addRows(newTD, trElm, rowspan); 846 } 847 848 addRows(tdElm, trElm, rowspan); 849 } 850 851 // Apply visual aids 852 tableElm = tinyMCE.getParentElement(inst.getFocusElement(), "table"); 853 break; 854 855 case "mceTableMergeCells": 856 var rows = new Array(); 857 var sel = inst.getSel(); 858 var grid = getTableGrid(tableElm); 859 860 if (tinyMCE.isMSIE || sel.rangeCount == 1) { 861 if (user_interface) { 862 // Setup template 863 var template = new Array(); 864 var sp = getColRowSpan(tdElm); 865 866 template['file'] = '../../plugins/table/merge_cells.htm'; 867 template['width'] = 160; 868 template['height'] = 220; 869 870 // Open window 871 tinyMCE.openWindow(template, {editor_id : inst.editorId, action : "update", numcols : sp.colspan, numrows : sp.rowspan}); 872 873 return true; 874 } else { 875 var numRows = parseInt(value['numrows']); 876 var numCols = parseInt(value['numcols']); 877 var cpos = getCellPos(grid, tdElm); 878 879 if (("" + numRows) == "NaN") 880 numRows = 1; 881 882 if (("" + numCols) == "NaN") 883 numCols = 1; 884 885 // Get rows and cells 886 var tRows = tableElm.rows; 887 for (var y=cpos.rowindex; y<grid.length; y++) { 888 var rowCells = new Array(); 889 890 for (var x=cpos.cellindex; x<grid[y].length; x++) { 891 var td = getCell(grid, y, x); 892 893 if (td && !inArray(rows, td) && !inArray(rowCells, td)) { 894 var cp = getCellPos(grid, td); 895 896 // Within range 897 if (cp.cellindex < cpos.cellindex+numCols && cp.rowindex < cpos.rowindex+numRows) 898 rowCells[rowCells.length] = td; 899 } 900 } 901 902 if (rowCells.length > 0) 903 rows[rows.length] = rowCells; 904 } 905 906 //return true; 907 } 908 } else { 909 var cells = new Array(); 910 var sel = inst.getSel(); 911 var lastTR = null; 912 var curRow = null; 913 var x1 = -1, y1 = -1, x2, y2; 914 915 // Only one cell selected, whats the point? 916 if (sel.rangeCount < 2) 917 return true; 918 919 // Get all selected cells 920 for (var i=0; i<sel.rangeCount; i++) { 921 var rng = sel.getRangeAt(i); 922 var tdElm = rng.startContainer.childNodes[rng.startOffset]; 923 924 if (!tdElm) 925 break; 926 927 if (tdElm.nodeName == "TD") 928 cells[cells.length] = tdElm; 929 } 930 931 // Get rows and cells 932 var tRows = tableElm.rows; 933 for (var y=0; y<tRows.length; y++) { 934 var rowCells = new Array(); 935 936 for (var x=0; x<tRows[y].cells.length; x++) { 937 var td = tRows[y].cells[x]; 938 939 for (var i=0; i<cells.length; i++) { 940 if (td == cells[i]) { 941 rowCells[rowCells.length] = td; 942 } 943 } 944 } 945 946 if (rowCells.length > 0) 947 rows[rows.length] = rowCells; 948 } 949 950 // Find selected cells in grid and box 951 var curRow = new Array(); 952 var lastTR = null; 953 for (var y=0; y<grid.length; y++) { 954 for (var x=0; x<grid[y].length; x++) { 955 grid[y][x]._selected = false; 956 957 for (var i=0; i<cells.length; i++) { 958 if (grid[y][x] == cells[i]) { 959 // Get start pos 960 if (x1 == -1) { 961 x1 = x; 962 y1 = y; 963 } 964 965 // Get end pos 966 x2 = x; 967 y2 = y; 968 969 grid[y][x]._selected = true; 970 } 971 } 972 } 973 } 974 975 // Is there gaps, if so deny 976 for (var y=y1; y<=y2; y++) { 977 for (var x=x1; x<=x2; x++) { 978 if (!grid[y][x]._selected) { 979 alert("Invalid selection for merge."); 980 return true; 981 } 982 } 983 } 984 } 985 986 // Validate selection and get total rowspan and colspan 987 var rowSpan = 1, colSpan = 1; 988 989 // Validate horizontal and get total colspan 990 var lastRowSpan = -1; 991 for (var y=0; y<rows.length; y++) { 992 var rowColSpan = 0; 993 994 for (var x=0; x<rows[y].length; x++) { 995 var sd = getColRowSpan(rows[y][x]); 996 997 rowColSpan += sd['colspan']; 998 999 if (lastRowSpan != -1 && sd['rowspan'] != lastRowSpan) { 1000 alert("Invalid selection for merge."); 1001 return true; 1002 } 1003 1004 lastRowSpan = sd['rowspan']; 1005 } 1006 1007 if (rowColSpan > colSpan) 1008 colSpan = rowColSpan; 1009 1010 lastRowSpan = -1; 1011 } 1012 1013 // Validate vertical and get total rowspan 1014 var lastColSpan = -1; 1015 for (var x=0; x<rows[0].length; x++) { 1016 var colRowSpan = 0; 1017 1018 for (var y=0; y<rows.length; y++) { 1019 var sd = getColRowSpan(rows[y][x]); 1020 1021 colRowSpan += sd['rowspan']; 1022 1023 if (lastColSpan != -1 && sd['colspan'] != lastColSpan) { 1024 alert("Invalid selection for merge."); 1025 return true; 1026 } 1027 1028 lastColSpan = sd['colspan']; 1029 } 1030 1031 if (colRowSpan > rowSpan) 1032 rowSpan = colRowSpan; 1033 1034 lastColSpan = -1; 1035 } 1036 1037 // Setup td 1038 tdElm = rows[0][0]; 1039 tdElm.rowSpan = rowSpan; 1040 tdElm.colSpan = colSpan; 1041 1042 // Merge cells 1043 for (var y=0; y<rows.length; y++) { 1044 for (var x=0; x<rows[y].length; x++) { 1045 var html = rows[y][x].innerHTML; 1046 var chk = tinyMCE.regexpReplace(html, "[ \t\r\n]", ""); 1047 1048 if (chk != "<br/>" && chk != "<br>" && chk != " " && (x+y > 0)) 1049 tdElm.innerHTML += html; 1050 1051 // Not current cell 1052 if (rows[y][x] != tdElm && !rows[y][x]._deleted) { 1053 var cpos = getCellPos(grid, rows[y][x]); 1054 var tr = rows[y][x].parentNode; 1055 1056 tr.removeChild(rows[y][x]); 1057 rows[y][x]._deleted = true; 1058 1059 // Empty TR, remove it 1060 if (!tr.hasChildNodes()) { 1061 tr.parentNode.removeChild(tr); 1062 1063 var lastCell = null; 1064 for (var x=0; cellElm = getCell(grid, cpos.rowindex, x); x++) { 1065 if (cellElm != lastCell && cellElm.rowSpan > 1) 1066 cellElm.rowSpan--; 1067 1068 lastCell = cellElm; 1069 } 1070 1071 if (tdElm.rowSpan > 1) 1072 tdElm.rowSpan--; 1073 } 1074 } 1075 } 1076 } 1077 1078 break; 1079 } 1080 1081 tableElm = tinyMCE.getParentElement(inst.getFocusElement(), "table"); 1082 tinyMCE.handleVisualAid(tableElm, true, tinyMCE.settings['visual']); 1083 tinyMCE.triggerNodeChange(); 1084 inst.repaint(); 1085 } 1086 1087 return true; 1088 } 1089 1090 // Pass to next handler in chain 1091 return false; 1092 } 1093 1094 function TinyMCE_table_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { 1095 var colspan = "1", rowspan = "1"; 1096 1097 var inst = tinyMCE.getInstanceById(editor_id); 1098 1099 // Reset table controls 1100 tinyMCE.switchClassSticky(editor_id + '_table', 'mceButtonNormal'); 1101 tinyMCE.switchClassSticky(editor_id + '_row_props', 'mceButtonDisabled', true); 1102 tinyMCE.switchClassSticky(editor_id + '_cell_props', 'mceButtonDisabled', true); 1103 tinyMCE.switchClassSticky(editor_id + '_row_before', 'mceButtonDisabled', true); 1104 tinyMCE.switchClassSticky(editor_id + '_row_after', 'mceButtonDisabled', true); 1105 tinyMCE.switchClassSticky(editor_id + '_delete_row', 'mceButtonDisabled', true); 1106 tinyMCE.switchClassSticky(editor_id + '_col_before', 'mceButtonDisabled', true); 1107 tinyMCE.switchClassSticky(editor_id + '_col_after', 'mceButtonDisabled', true); 1108 tinyMCE.switchClassSticky(editor_id + '_delete_col', 'mceButtonDisabled', true); 1109 tinyMCE.switchClassSticky(editor_id + '_split_cells', 'mceButtonDisabled', true); 1110 tinyMCE.switchClassSticky(editor_id + '_merge_cells', 'mceButtonDisabled', true); 1111 1112 // Within a tr element 1113 if (tinyMCE.getParentElement(node, "tr")) 1114 tinyMCE.switchClassSticky(editor_id + '_row_props', 'mceButtonSelected', false); 1115 1116 // Within a td element 1117 if (tdElm = tinyMCE.getParentElement(node, "td")) { 1118 tinyMCE.switchClassSticky(editor_id + '_cell_props', 'mceButtonSelected', false); 1119 tinyMCE.switchClassSticky(editor_id + '_row_before', 'mceButtonNormal', false); 1120 tinyMCE.switchClassSticky(editor_id + '_row_after', 'mceButtonNormal', false); 1121 tinyMCE.switchClassSticky(editor_id + '_delete_row', 'mceButtonNormal', false); 1122 tinyMCE.switchClassSticky(editor_id + '_col_before', 'mceButtonNormal', false); 1123 tinyMCE.switchClassSticky(editor_id + '_col_after', 'mceButtonNormal', false); 1124 tinyMCE.switchClassSticky(editor_id + '_delete_col', 'mceButtonNormal', false); 1125 1126 colspan = tinyMCE.getAttrib(tdElm, "colspan"); 1127 rowspan = tinyMCE.getAttrib(tdElm, "rowspan"); 1128 1129 colspan = colspan == "" ? "1" : colspan; 1130 rowspan = rowspan == "" ? "1" : rowspan; 1131 1132 if (colspan != "1" || rowspan != "1") 1133 tinyMCE.switchClassSticky(editor_id + '_split_cells', 'mceButtonNormal', false); 1134 } 1135 1136 // Within table 1137 if (tinyMCE.getParentElement(node, "table")) { 1138 tinyMCE.switchClassSticky(editor_id + '_table', 'mceButtonSelected'); 1139 tinyMCE.switchClassSticky(editor_id + '_merge_cells', 'mceButtonNormal', false); 1140 } 1141 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |