1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2<!-- 3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 4 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 5 * 6 * == BEGIN LICENSE == 7 * 8 * Licensed under the terms of any of the following licenses at your 9 * choice: 10 * 11 * - GNU General Public License Version 2 or later (the "GPL") 12 * http://www.gnu.org/licenses/gpl.html 13 * 14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 15 * http://www.gnu.org/licenses/lgpl.html 16 * 17 * - Mozilla Public License Version 1.1 or later (the "MPL") 18 * http://www.mozilla.org/MPL/MPL-1.1.html 19 * 20 * == END LICENSE == 21 * 22 * This is the sample "Replace" plugin window. 23--> 24<html> 25 <head> 26 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 27 <meta content="noindex, nofollow" name="robots"> 28 <script type="text/javascript"> 29 30var oEditor = window.parent.InnerDialogLoaded() ; 31var oEditorTables; 32var prevColors; 33var tfrm_ini_done = false; 34var lastSelectedEl; 35var color_name_id; 36var visibleTable; 37var firstTableDone = false; 38var howToULs = new Array('howto_color', 'howto_align', 'howto_size', 'howto_intro', 'howto_insdel'); 39var removedNodes; // tracks td's altered in setSize() 40var insDelNodes; // saves references to nodes inserted or deleted 41var BrowserIsIE; 42var currentHelp; 43var rowParentNode; 44var colParentNode; 45 46 47function OnLoad() 48{ 49 // First of all, translate the dialog box texts 50 oEditor.FCKLanguageManager.TranslatePage( document ) ; 51 52 window.parent.SetAutoSize( true ) ; 53 // window.parent.document.getElementById('btnCancel').style.display = "none"; 54 window.parent.document.getElementById('btnCancel').value = " Close Dialog "; 55 window.parent.SetOkButton( true ) 56 var d = oEditor.FCK.EditorDocument.body; 57 oEditorTables = d.getElementsByTagName('table'); 58 prevColors = new Array(oEditorTables.length); 59 60// set up the table arrays 61 62 for(var i=0; i < prevColors.length; i++) { 63 var row = getNodeList(oEditorTables[i], 'tr'); 64 if(row == null) continue; 65 var rows = row.length 66 prevColors[i] = new Array(rows); 67 for(var j=0; j < rows; j++) { 68 prevColors[i][j] = new Array(); 69 } 70 } 71 72 73 74 removedNodes = new Array(oEditorTables.length); 75 76 insDelNodes = new Array(); 77 for(var i=0; i < removedNodes.length; i++) { 78 removedNodes[i] = new Array(); 79 insDelNodes[i] = new Array(); 80 insDelNodes[i]['col'] = new Array(); 81 insDelNodes[i]['row'] = new Array(); 82 } 83 if(window.parent.dialogArguments) { 84 BrowserIsIE = window.parent.dialogArguments.Editor.FCKBrowserInfo.IsIE; 85 } 86 87 88} 89 90 91function Ok() { 92 //window.close(); 93 return true; 94} 95 96function showFirstTable(id) { 97 if(!tfrm_ini_done) window.setTimeout("showFirstTable(id)", 100); 98 99 if(id != 'color_table') { // color table is loaded initially into the tfrm div, to size the display 100 var save_table = document.getElementById('color_table'); 101 var display_div = document.getElementById('tfrm'); 102 save_table.innerHTML = display_div.innerHTML; 103 display_div.innerHTML = document.getElementById(id).innerHTML; 104 document.getElementById(id).innerHTML = ""; // empty visible tables div 105 } 106 107 display_el('tfrm'); 108 109 visibleTable = id; 110} 111 112function display_el(id) { 113 114 var dom = document.getElementById(id); 115 dom.style.display = "block"; 116 117} 118 119 120function hide_el(id) { 121 var dom = document.getElementById(id); 122 dom.style.display = "none"; 123} 124 125function getHelp() { 126 display_el(currentHelp); 127} 128 129function howToCloseAll() { 130 131 for(var i=0; i < howToULs.length; i++) { 132 var dom = document.getElementById(howToULs[i]) ; 133 dom.style.display = 'none'; 134 } 135 136} 137 138function features_disable(features, bool) { 139 for(var i=0; i < features.length; i++) { 140 document.getElementById(features[i]).disabled = bool; 141 } 142 143} 144 145 146function switchIntro(id) { 147 148 checkForReload(); 149 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], false); 150 howToCloseAll(); 151 var display_div = document.getElementById('tfrm'); 152 display_div.style.display = 'none'; 153 154 display_el(id); 155 currentHelp = id; 156} 157 158 159function switchTable(id) { 160 161 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], false); 162 if(!firstTableDone) { 163 showFirstTable(id) ; 164 firstTableDone=true; 165 } 166 else { 167 168 checkForReload(); 169 var save_table = document.getElementById(visibleTable); 170 var display_div = document.getElementById('tfrm'); 171 172 display_el('tfrm'); 173 save_table.innerHTML = display_div.innerHTML; 174 display_div.innerHTML = document.getElementById(id).innerHTML; 175 document.getElementById(id).innerHTML = ""; // empty visible tables div 176 visibleTable = id; // save visible id so it can be returned to its div 177 } 178 howToCloseAll(); 179 180 id = id.replace(/_table/,""); 181 var table_id = "tableT_" + id; 182 id = 'howto_' + id; 183 display_el(id); 184 currentHelp = id; 185 186} 187 188function getNodeList(parent, elName) { 189 if(parent && parent.getElementsByTagName(elName)) 190 return parent.getElementsByTagName(elName); 191 192 return null; 193} 194 195 196 197function setColBackground(color) { 198 199 if(!colParentNode) return; 200 201 var column = colParentNode.col; 202 var id = colParentNode.row_id; 203 var colnum = colParentNode.colnum; 204 205 colParentNode = null; 206 207 208 if(!column) return null; 209 for(var i=0; i < column.length; i++) { 210 if(!column[i] || isTableHeader(column[i])) continue; 211 lastSelectedEl = column[i]; 212 color_name_id = "td" + id + i + "_" + colnum; 213 SelectBackColor(color); 214 } 215 216} 217 218 219 220function setRowBackground(color) { 221 222 if(!rowParentNode) return; 223 224 var parent = rowParentNode.node; 225 var id = rowParentNode.row_id; // used to create color_name_id for writing text name of color 226 227 rowParentNode = null; 228 229 var cols = getNodeList(parent, 'td'); 230 if(cols == null) return null; 231 for(var i=0; i < cols.length; i++) { 232 var name = cols[i].nodeName.toUpperCase(); 233 if(name == 'TH') { 234 alert('th'); 235 continue; 236 } 237 lastSelectedEl = cols[i]; 238 color_name_id = "td" + id + "_" + i; 239 SelectBackColor(color); 240 } 241 242} 243 244// function name created in macroSettings() 245function colColor(textbox,tablenum) { 246 var colnum = textbox.value-1; 247 var id = "c" + tablenum + "_"; 248 249 var column = getColumnArray(tablenum, colnum); 250 251 colParentNode = { col: column, row_id: id, colnum: colnum }; 252 253 oEditor.FCKDialog.OpenDialog( 'FCKDialog_Color', oEditor.FCKLang.DlgColorTitle, 254 'dialog/fck_colorselector.html', 400, 330, setColBackground, window ) ; 255 256} 257 258// function name created in macroSettings() 259function rowColor(textbox, tablenum) { 260 var rownum = textbox.value-1; 261 var id = "c" + tablenum + "_" + rownum; 262 263 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 264 rowParentNode = { node: rows[rownum], row_id: id }; 265 266 oEditor.FCKDialog.OpenDialog( 'FCKDialog_Color', oEditor.FCKLang.DlgColorTitle, 267 'dialog/fck_colorselector.html', 400, 330, setRowBackground, window ) ; 268 269} 270 271 272 /** 273 checks radio buttons to see which one has been set 274 then returns its value 275*/ 276function getAlignPosition(n) { 277 278 for(i=0; i < n.length; i++) { 279 if(n[i].type == 'radio' && n[i].checked) { 280 return n[i].value; 281 } 282 } 283 284 return null; 285} 286 287 288// function name created in macroSettings() 289function rowAlign(textbox,tablenum) { 290 var id = 'ent' + 'align' + '_' + tablenum; 291 var m_id = id + 'macro'; 292 var tableT = 'T' + 'align' + '_'; 293 var formName = tableT + 'F' 294 295 var rownum = textbox.value-1; 296 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 297 var row = rows[rownum]; 298 299 var n = document.forms[formName][m_id]; 300 var position = getAlignPosition(n); 301 302 if(!row || !position) return null; 303 304 var indexes = new Array(); 305 indexes['left'] = 0; 306 indexes['center'] = 1; 307 indexes['right'] = 2; 308 309 var index = indexes[position]; 310 311 var cells = getCellArray_r(row); 312 313 for(var i=0; i < cells.length; i++) { 314 if(cells[i]) { 315 var id = setAlign(tablenum, rownum, i, position); 316 document.forms[formName][id][index].checked = true; 317 } 318 } 319} 320 321 322// function name created in macroSettings() 323 324function colAlign(textbox, tablenum) { 325 var id = 'ent' + 'align' + '_' + tablenum; 326 var m_id = id + 'macro'; 327 var tableT = 'T' + 'align' + '_'; 328 var formName = tableT + 'F' 329 330 var colnum = textbox.value-1; 331 var column = getColumnArray(tablenum, colnum); 332 333 var n = document.forms[formName][m_id]; 334 var position = getAlignPosition(n); 335 336 if(!column || !position) return null; 337 338 var indexes = new Array(); 339 indexes['left'] = 0; 340 indexes['center'] = 1; 341 indexes['right'] = 2; 342 343 var index = indexes[position]; 344 345 for(var i=0; i < column.length; i++) { // i = row number 346 if(!column[i]) continue; 347 var id = setAlign(tablenum, i, colnum, position); 348 document.forms[formName][id][index].checked = true; 349 } 350 351} 352 353function insDelNodesReset(tablenum, row, col) { 354 355 if(row !== null) { 356 var t = insDelNodes[tablenum]['row']; 357 for(var i=0; i < t.length; i++) { 358 if(t[i].num == col) { 359 insDelNodes[tablenum]['row'][i] = null; 360 } 361 } 362 } 363 else { 364 var t = insDelNodes[tablenum]['col']; 365 for(var i=0; i < t.length; i++) { 366 if(t[i].num == col) { 367 insDelNodes[tablenum]['col'][i] = null; 368 } 369 } 370 } 371 372} 373 374 375function reinsertCol(tablenum,text_box) { 376 var colnum = document.getElementById(text_box).value -1; 377 378 var t = insDelNodes[tablenum]['col']; 379 var insertNode = null; 380 for(var i=0; i < t.length; i++) { 381 if(t[i].num == colnum && t[i].deleted) { 382 insertNode = t[i].node; 383 if(insertNode) { 384 insDelNodesReset(tablenum, colnum, null); 385 } 386 break; 387 } 388 } 389 390 if(!insertNode) return; 391 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], true); 392 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 393 394 var maxcells = getMaxCells(tablenum, rows.length, rows); 395 396 var move_to = checkForMove(tablenum); 397 if(move_to.isNumber) { 398 colnum = move_to.value; 399 } 400 for(var i=0; i < rows.length; i++) { 401 if(!insertNode[i]) continue; 402 if(colnum >= maxcells) { 403 rows[i].appendChild(insertNode[i]); 404 } 405 else { 406 var cells = getCellArray_r(rows[i]); 407 if(cells[colnum]) { 408 rows[i].insertBefore(insertNode[i],cells[colnum]); 409 } 410 } 411 } 412 413} 414 415 /** 416 Used by reinsertRow/Col functions 417 Evaluates Move To text box to determine whether value is 418 a number, returns number, and resets the text box to a null string 419 */ 420function checkForMove(tablenum) { 421 422 var id = 'ent' + 'size' + '_' + tablenum 423 var mv_id = id + '_mov'; 424 var mv_to_node = document.getElementById(mv_id); 425 426 var mv_to_pos; 427 if(mv_to_node) { 428 mv_to_pos = parseInt(mv_to_node.value) 429 } 430 431 var isNum = isNaN(mv_to_pos) ? false : true; 432 433 if(isNum && mv_to_pos > 0) { 434 mv_to_pos--; 435 } 436 mv_to_node.value = ""; 437 return { isNumber: isNum, value: mv_to_pos}; 438} 439 440function reinsertRow(tablenum, text_box) { 441 var rownum = document.getElementById(text_box).value -1; 442 443 444 var t = insDelNodes[tablenum]['row']; 445 var insertNode = null; 446 for(var i=0; i < t.length; i++) { 447 if(t[i].num == rownum && t[i].deleted) { 448 insertNode = t[i].node; 449 if(insertNode) { 450 insDelNodesReset(tablenum, rownum, null); 451 } 452 break; 453 } 454 } 455 456 if(!insertNode) return; 457 var move_to = checkForMove(tablenum); 458 459 if(move_to.isNumber) { 460 rownum = move_to.value; 461 } 462 463 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], true); 464 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 465 if(rows[rownum]) { 466 var parent = rows[rownum].parentNode; 467 parent.insertBefore(insertNode,rows[rownum]); 468 } 469 else { 470 appendRow(tablenum, insertNode); 471 } 472} 473 474 475 // function name created in macroSettings() 476function rowInsDel(row, tablenum, del) { 477 var rownum = row.value-1; 478 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 479 480 if(!rows) return; 481 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], true); 482 483 if(del) { 484 if(rows[rownum]) { 485 var parent = rows[rownum].parentNode; 486 insDelNodes[tablenum]['row'].push({ num: rownum, node: rows[rownum], deleted: del }); 487 parent.removeChild(rows[rownum]); 488 } 489 } 490 else 491 { 492 try { 493 494 var maxcells = getMaxCells(tablenum, rows.length, rows); 495 var d = oEditor.FCK.EditorDocument; 496 var tr = d.createElement('tr'); 497 for(var i=0; i < maxcells; i++) { 498 var td = d.createElement('td'); 499 var t = "\u00A0\u00A0"; 500 var text = d.createTextNode(t); 501 td.appendChild(text); 502 tr.appendChild(td); 503 } 504 505 // in theory insertBefore should append when rows[rownum] == null 506 // but doesn't, hence the else {} clause 507 if(rows[rownum]) { 508 var parent = rows[rownum].parentNode; 509 parent.insertBefore(tr,rows[rownum]); 510 } 511 else { // rownum exceeds number of rows in table 512 appendRow(tablenum, tr) 513 } 514 insDelNodes[tablenum]['row'].push({ num: rownum, node: tr, deleted: del }); 515 } catch(e) { alert(e.message); } 516 517 } 518 519} 520 521function appendRow(tablenum, tr) { 522 523 var tbody = getNodeList(oEditorTables[tablenum], 'tbody'); 524 var tbody_len = tbody.length; 525 if(tbody_len > 0) { 526 tbody[tbody_len-1].appendChild(tr); 527 } 528 else { //last ditch fallback -- doesn't work in IE 6 529 oEditorTables[tablenum].appendChild(tr); 530 } 531 532} 533 534 // function name created in macroSettings() 535function colInsDel(col, tablenum, del) { 536 537 var colnum = col.value-1; 538 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], true); 539 if(colnum < 0) return; 540 insDelNodesReset(tablenum, null, col); 541 if(del) { 542 var column = getColumnArray(tablenum, colnum); 543 544 for(var i=0; i < column.length; i++) { 545 if(column[i]) { 546 var parent = column[i].parentNode; 547 parent.removeChild(column[i]); 548 } 549 } 550 insDelNodes[tablenum]['col'].push({ num: colnum, node: column, deleted: del }); 551 } 552 553 else { 554 555 var d = oEditor.FCK.EditorDocument; 556 var column = getColumnArray(tablenum, colnum); 557 var rows = getNodeList(oEditorTables[tablenum], 'tr') 558 559 var maxcells = getMaxCells(tablenum, rows.length, rows); 560 var append = (colnum >= maxcells) ? true: false; 561 562 for(var i=0; i < column.length; i++) { 563 564 if(!column[i] && ! append) continue; 565 566 var td = d.createElement('td'); 567 var t = "\u00A0\u00A0"; 568 var text = d.createTextNode(t); 569 td.appendChild(text); 570 if(append) { 571 rows[i].appendChild(td); 572 } 573 else { 574 var parent = column[i].parentNode; 575 parent.insertBefore(td,column[i]); 576 } 577 } 578 insDelNodes[tablenum]['col'].push({num: colnum, node: null, deleted: del }); 579 } 580 581} 582 583 584// sets cell background color using style.cssText and forwards to setColorName 585// to place color value in span to left of checkbox 586function SelectBackColor( color ) 587{ 588 if ( color && color.length > 0 && lastSelectedEl) { 589 var rgb = color.match(/rgb/) ? color : hexToRGB(color); 590 try { 591 lastSelectedEl.style.cssText = "background-color: " + rgb; 592 } 593 catch (e) { 594 // alert("Unable to reset color to: " + rgb + "; " + e.message); 595 } 596 597 setColorName(rgb); 598 } 599 lastSelectedEl = ""; 600} 601 602 603 // puts hex color value in span to left of col checkbox 604function setColorName(rgb) { 605 606 if(!color_name_id) return; 607 608 var color = rgbToHex(rgb); 609 if(!color) return; 610 611 var dom = document.getElementById(color_name_id); 612 if(dom) { 613 dom.innerHTML = color; 614 } 615 616 color_name_id = ""; 617} 618 619function hexToRGB(color) { 620 var result = color.match(/#(\w\w)(\w\w)(\w\w)/); 621 return "rgb(" + parseInt(result[1],16) + ", " + parseInt(result[2],16) + ", " + parseInt(result[3],16) + ")"; 622 623} 624 625function rgbToHex(style) { 626 627 var result = style.match(/rgb\((\d+),\s*(\d+),\s*(\d+)/); 628 if(result) { 629 var n1 = new Number(result[1]); 630 var n2 = new Number(result[2]); 631 var n3 = new Number(result[3]); 632 return "#" + n1.toString(16) + "" + n2.toString(16) + "" + n3.toString(16); 633 } 634 return ""; 635} 636 637 638function SelectColor(tablenum, rownum, cellnum) 639{ 640 var id = "c" + tablenum + "_" + rownum + "_" + cellnum; 641 color_name_id = "td"+ id // sets span id for later text color value insertion 642 var selected = document.getElementById(id).checked; 643 644 var rows = getNodeList(oEditorTables[tablenum],'tr'); 645 if(rows == null) return; 646 var cells = getNodeList(rows[rownum],'td'); 647 if(cells == null) return; 648 lastSelectedEl = cells[cellnum]; 649 650 if(!selected) { 651 if(!prevColors[tablenum][rownum][cellnum]) { 652 prevColors[tablenum][rownum][cellnum] = 'rgb(255, 255, 255)'; 653 } 654 SelectBackColor(prevColors[tablenum][rownum][cellnum]); 655 return; 656 } 657 658 if(lastSelectedEl.getAttribute('style')) { 659 var bgcolor = lastSelectedEl.style.cssText; 660 bgcolor = bgcolor.replace(/\s*background-color:\s*/i,""); 661 prevColors[tablenum][rownum][cellnum] = bgcolor; 662 } 663 else { 664 prevColors[tablenum][rownum][cellnum] = 'rgb(255, 255, 255)'; 665 } 666 667 oEditor.FCKDialog.OpenDialog( 'FCKDialog_Color', oEditor.FCKLang.DlgColorTitle, 668 'dialog/fck_colorselector.html', 400, 330, SelectBackColor, window ) ; 669 670} 671 672/** 673 returns all cells, th or td, ina row, based on table number and row number 674*/ 675function getCellArray_t(tablenum, rownum) { 676 var d = oEditor.FCK.EditorDocument.body; 677 var tables = d.getElementsByTagName('table'); 678 679 var rows = getNodeList(tables[tablenum],'tr'); 680 var node = rows[rownum]; 681 return getCellArray_r(node); 682 683} 684 685 686/** 687 returns all cells in a row, either th or td 688 param node: row node 689*/ 690function getCellArray_r(node) { 691 692 var cells = new Array(); 693 for(var c = node.firstChild; c != null; c = c.nextSibling) { 694 if(c.nodeType == 1 && c.nodeName.match(/(th)|(td)/i)) { 695 cells.push(c); 696 } 697 698 } 699 700 return cells; 701} 702 703 704/** 705 return td's if found, else return th's 706 See getCellArray_t() for function that returns all cells in a row 707*/ 708 709function getCellArray(tablenum, rownum) { 710 711 var rows = getNodeList(oEditorTables[tablenum],'tr'); 712 var cells = getNodeList(rows[rownum],'td'); 713 if(cells == null) return; 714 if(cells.length == 0) { 715 cells = getNodeList(rows[rownum],'th'); 716 if(cells.length == 0) return null; 717 } 718 719 return cells; 720} 721 722function isTableHeader(n) { 723 724 var name = n.nodeName.toUpperCase(); 725 if(name == 'TH') { 726 return true; 727 } 728 729 return false; 730} 731 732function getColumnArray(tablenum, colnum) { 733 var rows = getNodeList(oEditorTables[tablenum], 'tr'); 734 var len = rows.length; 735 736 var column = new Array(); 737 738 for(var i=0; i < len; i++) { 739 cells = getCellArray_t(tablenum, i); 740 if(cells && cells[colnum]) { 741 column[i] = cells[colnum]; 742 } 743 else { 744 column[i] = null; 745 } 746 } 747 748 return column; 749} 750 751function checkForReload() { 752 var re_load = false; 753 754 for(var i=0; i < removedNodes.length; i++) { 755 for(var j = 0; j < removedNodes[i].length; j++) { 756 if(removedNodes[i][j]) { 757 re_load = true; 758 break; 759 } 760 } 761 } 762 763 for(var i=0; i < insDelNodes.length; i++) { 764 if(insDelNodes[i]['col'].length || insDelNodes[i]['row'].length) { 765 re_load = true; 766 break; 767 } 768 } 769 770 if(re_load) { // the first one that works gets the job 771 location.reload(true); 772 location.replace(location.href); 773 location = location.href; 774 } 775} 776 777 778 779function IEAppendAlert() { 780 var browser = BrowserIsIE ? 'IE' : 'this browser'; 781 782 alert("Option not supported by " + browser + ".\n" + 783 "Try Firefox, Safari or newer version of " + browser + " ."); 784 785} 786 787 788 789function setSize(tablenum, rownum, cellnum, type) { 790 791 var cells = getCellArray_t(tablenum, rownum); 792 var node = cells ? cells[cellnum] :null; 793 var id = "sz" + tablenum + "_" + rownum + "_" + cellnum; 794 795 switch(type) { 796 case 'delete': 797 798 // 'delete' is checked on a deleted node, so reinsert 799 if(removedNodes[tablenum][rownum]) { 800 if(removedNodes[tablenum][rownum][cellnum]) { 801 var td = removedNodes[tablenum][rownum][cellnum]; 802 if(node) { 803 try { 804 node.parentNode.insertBefore(td,node); 805 } catch(e) { 806 IEAppendAlert(); 807 } 808 } 809 else { 810 var rows = getNodeList(oEditorTables[tablenum],'tr'); 811 try { 812 rows[rownum].appendChild(td); 813 } catch(e) { 814 IEAppendAlert(); 815 } 816 } 817 removedNodes[tablenum][rownum][cellnum] = null; 818 return; 819 } 820 } 821 822 if(!node) return; 823 824 var p = node.parentNode; 825 if(p) { 826 827 if(!removedNodes[tablenum][rownum]) { 828 removedNodes[tablenum][rownum] = new Array(); 829 } 830 var text = node.innerHTML; 831 text = text.replace(/<\/span>/i) 832 text = text.replace(/<span.*?>/i); 833 834 removedNodes[tablenum][rownum][cellnum] = node; 835 p.removeChild(node); 836 features_disable(['b_al','b_c', 'b_sz', 'b_insdel'], true); 837 } 838 break; 839 840 case 'colspan': 841 id = id+'c'; 842 node.colSpan = document.getElementById(id).value; 843 break; 844 case 'width': 845 id = id+'w'; 846 node.style.width = document.getElementById(id).value + "px"; 847 848 break; 849 default: 850 851 } 852 853} 854 855function setAlign(tablenum, rownum, cellnum, position) { 856 var id = "al" + tablenum + "_" + rownum + "_" + cellnum; 857 var td_id = "td"+ id; 858 859 var cells = getCellArray_t(tablenum, rownum); 860 if(cells == null) return; 861 862 cells[cellnum].align = position; 863 864 865 var dom = document.getElementById(td_id); 866 dom.innerHTML = position; 867 return id; 868} 869 870function output_form(table) { 871 var tables = { align:window.rowToHTMLAlign, color:window.rowToHTMLColor, size: rowToHTMLSize}; 872 var fn = tables[table]; 873 var tableT = 'T' + table + '_'; 874 var formName = tableT + 'F'; 875 876 var d = oEditor.FCK.EditorDocument.body; 877 var tables = d.getElementsByTagName('table'); 878 document.write("\n<form name = '" + formName + "'>"); 879 for(var j=0; j < tables.length; j++) { 880 var tableT_id = tableT + j; 881 document.writeln("<br><b>Table " + (j + 1) + "</b><br>") 882 883 document.writeln("<Button style='font-size: 9pt;' onclick = \"hide_el('" + tableT_id + "');return false;\" >hide table</button> "); 884 document.writeln("<Button style='font-size: 9pt;' onclick = \"display_el('" + tableT_id + "');return false;\" >show table</button>") 885 886 document.writeln("<br><br><table border=0 id= '" + tableT_id + "' >"); 887 888 var rows = tables[j].getElementsByTagName('tr'); 889 var maxCells = getMaxCells(j, rows.length, rows); 890 if(table != 'size') { 891 macroSettings(maxCells, j,table); 892 } 893 if(maxCells > 4) document.writeln(writeColumnHeaders(maxCells)); 894 for(var i=0; i < rows.length; i++) { 895 document.writeln (fn(rows[i], j, i)); 896 } 897 document.writeln("</table>"); 898 899 document.writeln("<p>") 900 } 901 902 document.write("\n</form>"); 903 904 tfrm_ini_done = true; 905} 906 907 908 909function macroSettings(maxCells,tablenum, type) { 910 var width = (maxCells*2) + 2; 911 var id = 'ent' + type + '_' + tablenum; 912 var row_id = id + 'r'; 913 var col_id = id + 'c'; 914 915 var fns = { align:'Align', color:'Color', size: 'InsDel'}; 916 var row_fn = 'row'+ fns[type]; 917 var col_fn = 'col'+ fns[type]; 918 var prefix = (type == 'size') ? 'Insert: ' : "Reset: "; 919 var bool = (type == 'size') ? ',' + false : ""; 920 921 922 923 document.write('<tr><td style="font-size:9pt;" colspan ="' + width + '">'); 924 document.write(prefix + ' <input type="text" size="2" id="' + col_id + '">'); 925 document.write(' <input type = "button" value="column" onclick="' + col_fn + '('+ col_id + ',' + tablenum + bool + ');">'); 926 document.write(' <input type="text" size="2" id="' + row_id + '">'); 927 document.write(' <input type = "button" value="row" onclick="' + row_fn + '(' + row_id + ',' + tablenum + bool + ');">'); 928 if(type == 'align') { 929 var m_id = id + 'macro'; 930 931 document.write( 932 " alignment: " 933 + "<input type='radio'checked value='left' id='" + m_id +"' name='" + m_id + "'>" 934 + "<input type='radio' value='center' id='" + m_id +"' name='" + m_id + "'>" 935 + "<input type='radio' value='right' id='" + m_id +"' name='" + m_id + "'>"); 936 } 937 938 939 940 document.write("</td></tr>"); 941 942 943 944 if (type == 'size') { 945 col_id += 'd'; 946 row_id += 'd' 947 document.write('<tr><td style="font-size:9pt;" colspan ="' + width + '">'); 948 document.write('Delete: <input type="text" size="2" id="' + col_id + '">'); 949 document.write(' <input type = "button" value="column" onclick="' + col_fn + '(this.form.'+ col_id + ',' + tablenum + ',' + true + ');">'); 950 document.write(' <input type="text" size="2" id="' + row_id + '">'); 951 document.write(' <input type = "button" value="row" onclick="' + row_fn + '(this.form.' + row_id + ',' + tablenum + ',' + true + ');">'); 952 document.write("</td></tr>"); 953 954 document.write('<tr><td style="font-size:9pt;" colspan ="' + width + '">'); 955 col_id += 're'; 956 row_id += 're' 957 document.write('Reinsert: <input type="text" size="2" id="' + col_id + '">'); 958 document.write(' <input type = "button" value="column" onclick="reinsertCol(' + tablenum + ",'" + col_id +'\');">'); 959 960 document.write(' <input type="text" size="2" id="' + row_id + '">'); 961 document.write(' <input type = "button" value="row" onclick="reinsertRow(' + tablenum + ",'" + row_id +'\');">'); 962 var mv_id = id + '_mov'; 963 document.write(' Move To (optional): <input type="text" size="2" value = "" id="' + mv_id + '">'); 964 document.write("</td></tr>"); 965 966 } 967} 968 969function getMaxCells(tablenum, rownum, rows) { 970 var max=0; 971 972 for(var i=0; i < rownum; i++) { 973 var num = getNodeList(rows[i], 'td').length; 974 if(num > max) max = num; 975 } 976 977 return max; 978} 979 980function writeColumnHeaders(cells) { 981 982 var columns = "<tr><th> </th><th> </th>"; 983 for(var cols = 0; cols < cells; cols++) { 984 columns +="<td align = 'center'>" + (cols + 1) + "</td><td> </td>"; 985 } 986 return columns; 987 document.writeln(columns); 988 989} 990 991function rowToHTMLColor(row, tablenum, rownum) { 992 993 var cells = getCellArray_t(tablenum, rownum); 994 995 996 if(cells == null || cells.length == 0) { 997 return; 998 } 999 1000 var row_text = ""; 1001 1002 var row_id = "rowc_" + tablenum + "_" + rownum; 1003 row_text += "<tr id='" + row_id + "'>"; 1004 row_text += "<td>" + (rownum + 1) + "</td>"; 1005 for(var i=0; i< cells.length; i++) { 1006 var id = "c" + tablenum + "_" + rownum + "_" + i; 1007 var td_id = "td"+ id; 1008 var bgcolor = ""; 1009 if(cells[i].style && cells[i].style.cssText) { 1010 bgcolor = rgbToHex(cells[i].style.cssText); 1011 } 1012 var disabled = isTableHeader(cells[i]) ? " disabled " : ""; 1013 row_text += "<td align='right' style='width:80px; font-size:9pt;'> <span id='" + td_id + "'>"; 1014 if(bgcolor) row_text += bgcolor; 1015 else row_text += " "; 1016 row_text += "</span><td><input type='checkbox' onclick='SelectColor("+ tablenum +"," + rownum +"," + i + ");'" + disabled + " id=" + id + " > "; 1017 } 1018 1019 row_text += "</tr>"; 1020 return row_text; 1021 1022} 1023 1024function rowToHTMLAlign(row, tablenum, rownum) { 1025 1026 var cells = getCellArray_t(tablenum, rownum); 1027 1028 if(cells == null || cells.length == 0) { 1029 return; 1030 } 1031 1032 var row_text = ""; 1033 1034 var row_id = "rowal_" + tablenum + "_" + rownum; 1035 1036 row_text += "<tr id='" + row_id + "'>"; 1037 row_text += "<td>" + (rownum + 1) + "</td>"; 1038 for(var i=0; i< cells.length; i++) { 1039 var id = "al" + tablenum + "_" + rownum + "_" + i; 1040 var td_id = "td"+ id; 1041 var align = cells[i].align; 1042 1043 row_text += "<td align='right' style='width:80px; font-size:9pt;'> <span id='" + td_id + "'>"; 1044 var checked = { left: "", center: "", right: "" }; 1045 1046 if(cells[i].nodeName.match(/TH/i) && align.match(/left/i) && !align) { 1047 row_text += "TH"; 1048 } 1049 else if(align){ 1050 row_text += align; 1051 checked[align] = 'checked'; 1052 } 1053 else { 1054 1055 row_text += " " 1056 } 1057 1058 row_text += '</span> '; 1059 1060 row_text += "\n<td nowrap style='border: 1px solid;'><input type='radio' value='left' " + checked['left'] + " onclick='setAlign("+ tablenum +"," + rownum +"," + i + ", \"left\");' id='" + id + "' name='" + id + "'> "; ; 1061 row_text += "\n<input type='radio' value='center' " + checked['center'] + " onclick='setAlign("+ tablenum +"," + rownum +"," + i + ", \"center\");' id='" + id + "' name='" + id + "'> "; 1062 row_text += "\n<input type='radio' value='right' " + checked['right'] + " onclick='setAlign("+ tablenum +"," + rownum +"," + i + ", \"right\");' id='" + id + "' name='" + id + "'>"; 1063 1064 } 1065 row_text += "</tr>"; 1066 return row_text; 1067 1068} 1069 1070function rowToHTMLSize(row, tablenum, rownum) { 1071 1072 var cells = getCellArray_t(tablenum, rownum); 1073 1074 if(cells == null || cells.length == 0) { 1075 return; 1076 } 1077 1078var row_text = ""; 1079 1080 1081 var row_id = "rowsz_" + tablenum + "_" + rownum; 1082 1083 row_text += "<tr id='" + row_id + "'>"; 1084 row_text += "<td>" + (rownum + 1) + "</td>"; 1085 1086 for(var i=0; i< cells.length; i++) { 1087 var id = "sz" + tablenum + "_" + rownum + "_" + i; 1088 var td_id = "td"+ id; 1089 1090 row_text += "<td align='right' style='width:80px; font-size:9pt;'> <span id='" + td_id + "'>"; 1091 1092 row_text +='</span> '; 1093 1094 row_text += "<td nowrap style='border: 1px solid;'><input type='checkbox' onclick='setSize("+ tablenum +"," + rownum +"," + i + ", \"delete\");' id='" + id + "' name='" + id + "'> "; 1095 1096 var width = cells[i].width ? cells[i].width : ""; 1097 row_text += " <input type='text' size='3' value='" + width + "' id='" + id + 'w' + "' >"; 1098 row_text += "<input type='button' onclick ='setSize("+ tablenum +"," + rownum +"," + i + ", \"width\");' value = \"width\" > "; 1099 1100 var colspan = cells[i].colSpan ? cells[i].colSpan : ""; 1101 row_text +=" <input type='text' size = '1' value='" + colspan + "' id='" + id + 'c' + "' >"; 1102 row_text +="<input type='button' onclick='setSize("+ tablenum +"," + rownum +"," + i + ", \"colspan\");' value = \"cols\" >"; 1103 } 1104 1105 row_text +="</tr>"; 1106 1107 return row_text; 1108 1109} 1110 1111function outputInsertDelete() { 1112 1113 var d = oEditor.FCK.EditorDocument.body; 1114 var tables = d.getElementsByTagName('table'); 1115 for(var j=0; j < tables.length; j++) { 1116 var tno = j+1; 1117 document.write("<tr><th>Table " + tno ); 1118 macroSettings(1,j,'size'); 1119 document.write("<tr><td> "); 1120 } 1121 1122 1123} 1124 </script> 1125 1126 <style type="text/css"> 1127 body { overflow:scroll; } 1128 a:link, a:visited { color: #737357; font-weight:bold; font-size: 9pt; } 1129 li { font-size: 9pt; font-weight: normal; } 1130 </style> 1131 1132 </head> 1133 <body onload="OnLoad()"> 1134 1135 <button id="b_c" onclick="switchTable('color_table');">color</button> 1136 <button id="b_al" onclick="switchTable('align_table');">align</button> 1137 <button id="b_sz" onclick="switchTable('size_table');">resize</button> 1138 <button id="b_insdel" onclick="switchTable('insdel_table');">ins/del</button> 1139 <button id="b_intro" onclick="switchIntro('howto_intro');">intro</button> 1140 <button id="b_help" onclick="getHelp();"> ? </button> 1141 1142 <ul id = 'howto_intro' style="font-size: 9pt;"> 1143 <b style="font-size: 10pt;">Table Format Utility</b> 1144 <li> This utility supports the following table formatting features: 1145 <ol> 1146 <li> <b>[ color ]:</b> background colors for cells, rows, and columns 1147 <li> <b>[ align ]:</b> horizontal text alignment for 1148 cells, rows, and columns 1149 <li> <b>[ resize ]:</b> cell width and column spans, cell deletion 1150 <li> <b>[ ins/del ]:</b> inserting, deleting and moving columns and rows 1151 1152 </ol> 1153 1154 <li>At the top of each page, you will find the basic instructions for the features 1155 supported by that page. You can hide the instructions by clicking <b>hide</b> 1156 at the bottom right of the instructions. To re-display the instructions click <b>[ ? ]</b>. 1157 <li>After making structural changes to a table, the table will have to be re-read. 1158 Consequently, all the top row buttons will be disabled, except for 1159 <b>[ Intro ]</b> and <b>[ ? ].</b> In order to continue, click <b>Intro</b>. It will do 1160 the re-read and return you to this page. 1161 <li>This page can be re-displayed by clicking the <b>[ Intro ]</b> button. 1162 </ul> 1163 1164 <ul id = 'howto_color' style="font-size: 9pt; display:none;"> 1165 <b style="font-size: 10pt;">Setting Background Colors</b> 1166 <li>Each checkbox represents a cell. To set a background color, select the cell 1167 and a pop-up will appear from which you can select a background color. 1168 <li>To revert to the previous color, uncheck the checkbox. 1169 <li>You can also enter a color in the pop-up text box, using the form <b>#nnnnnn</b>. 1170 <li>To set the background color for a DokuWiki Table header, you must first remove 1171 the <TH> tag using the <b>Styles</b> menu. 1172 <li>To set the background color for an entire row or column use the <b>Reset</b> 1173 feature. Enter the row or column number and click the button. The color 1174 dialog will pop up. 1175 <table width="80%"><tr><td align ="right"> 1176 <a href = "javascript:hide_el('howto_color');">hide</a> 1177 </td></tr></table> 1178 </ul> 1179 1180 <ul id = "howto_align" style="font-size: 9pt; display:none"> 1181 <b style="font-size: 10pt;">Setting Alignment</b> 1182 <li> Alignment positions are controlled by radio buttons: <input type="radio"> 1183 <li> The buttons, in order, are left, center, and right. 1184 <li> Clicking on a button will immediately re-align a cell's text. 1185 <li> To set alignment to another position, simply select another button. 1186 <li>To align an entire row or column use the <b>Reset</b> 1187 feature. Select the required radio button and enter the row or column number. 1188 Click the button. The entire row or column will be re-aligned. 1189 1190 <table width="80%"><tr><td align ="right"> 1191 <a href = "javascript:hide_el('howto_align');">hide</a> 1192 </td></tr></table> 1193 </ul> 1194 1195 <ul id = "howto_size" style="font-size: 9pt; display:none"> 1196 <b style="font-size: 10pt;">Setting Column Sizes</b> 1197 <li> To change width of cell enter the width in pixels and click the <b>width</b> button 1198 <li> To change the number of columns a cell spans enter the number in the <b>cols</b> box and click 1199the <b>cols</b> button 1200 <li> When extending a cell over more than one column it may be necessary to remove adjacent 1201cells. You do this by checking off the checkboxes of the relevant cells. Unchecking a cell 1202will restore its content but the formatting will be lost. 1203 <table width="80%"><tr><td align ="right"> 1204 <a href = "javascript:hide_el('howto_size');">hide</a> 1205 </td></tr></table> 1206 </ul> 1207 1208 1209 <ul id = "howto_insdel" style="font-size: 9pt; display:none"> 1210 <b style="font-size: 10pt;">Inserting and Deleting Columns and Rows</b> 1211 <li><b>Insert:</b> To insert a new column or row, enter its position number and click the relevant 1212 button. A new column or row will be inserted at that position. 1213 <li><b>Delete:</b> To delete a column or row, enter its position number and click the 1214 relevant button. The deleted column or row will be saved for possible re-insertion. 1215 <li><b>Reinsert:</b> To return a column or row that has been deleted to its original position, 1216 use the Reinsert facility. Enter the number of the deleted row or column in the 1217 row or column box; this number must be the 1218 same as the number of the deletion. Click the button. The deleted row or column 1219 will be reinserted. 1220 <li><b>Move To: </b>To move a deleted row or column to a new position in the table, enter the 1221 new position in the <b>Move To</b> box; then follow the procedure for <b>Reinsert</b>. The 1222 column or row will be inserted at the new position instead of at its original position. 1223 <table width="80%"><tr><td align ="right"> 1224 <a href = "javascript:hide_el('howto_insdel');">hide</a> 1225 </td></tr></table> 1226 1227 </ul> 1228 1229 <div id = 'tfrm' style="font-size: 10pt; display: none;"> 1230 <script type="text/javascript"> 1231 output_form('color'); 1232 </script> 1233 </div> 1234 1235 <div id = 'align_table' style="font-size: 10pt; display: none; "> 1236 <script type="text/javascript"> 1237 output_form('align'); 1238 </script> 1239 </div> 1240 1241 <div id = 'size_table' style="font-size: 10pt; top: 0px; left: 0px; display: none;"> 1242 <script type="text/javascript"> 1243 output_form('size'); 1244 </script> 1245 </div> 1246 1247 <div id = 'insdel_table' style="font-size: 10pt; top: 0px; left: 0px; display: none;"> 1248 <FORM> 1249 <TABLE> 1250 <script type="text/javascript"> 1251 outputInsertDelete(); 1252 </script> 1253 </TABLE> 1254 </FORM> 1255 </div> 1256 1257 <div id = 'color_table' style="font-size: 10pt; top 0px; left: 0px; display: none;"> 1258 </div> 1259 1260 </body> 1261</html> 1262