Annotation of kupuMPIWG/common/kupucnftable.js, revision 1.1
1.1 ! dwinter 1: /*****************************************************************************
! 2: *
! 3: * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
! 4: *
! 5: * This software is distributed under the terms of the Kupu
! 6: * License. See LICENSE.txt for license text. For a list of Kupu
! 7: * Contributors see CREDITS.txt.
! 8: *
! 9: *****************************************************************************/
! 10:
! 11: // $Id: kupubasetools.js 6120 2004-08-22 23:23:42Z roku $
! 12:
! 13: TableTool.prototype.setTableRowRepeat = function() {
! 14: var selNode = this.editor.getSelectedNode();
! 15: var row = this.editor.getNearestParentOfType(selNode, 'tr');
! 16: if (!row) {
! 17: this.editor.logMessage(_('Not inside a row!'), 1);
! 18: return;
! 19: };
! 20: row.setAttribute('repeatable', 'repeatable');
! 21: row.className = 'repeatable';
! 22: this.editor.logMessage(_('Row repeated'));
! 23: this.updateState(selNode);
! 24: };
! 25:
! 26: TableTool.prototype.delTableRowRepeat = function() {
! 27: var selNode = this.editor.getSelectedNode();
! 28: var row = this.editor.getNearestParentOfType(selNode, 'tr');
! 29: if (!row) {
! 30: this.editor.logMessage(_('Not inside a row!'), 1);
! 31: return;
! 32: };
! 33: row.removeAttribute('repeatable');
! 34: row.className = '';
! 35: row.removeAttribute('class');
! 36: this.editor.logMessage(_('Row repeat turned off'));
! 37: this.updateState(selNode);
! 38: };
! 39:
! 40: function CNFTableToolBox(addtabledivid, edittabledivid, newrowsinputid,
! 41: newcolsinputid, makeheaderinputid, classselectid, alignselectid, addtablebuttonid,
! 42: addrowbuttonid, delrowbuttonid, setrowrepeatbuttonid, delrowrepeatbuttonid,
! 43: addcolbuttonid, delcolbuttonid, fixbuttonid,
! 44: fixallbuttonid, toolboxid, plainclass, activeclass) {
! 45:
! 46: this.addtablediv = getFromSelector(addtabledivid);
! 47: this.edittablediv = getFromSelector(edittabledivid);
! 48: this.newrowsinput = getFromSelector(newrowsinputid);
! 49: this.newcolsinput = getFromSelector(newcolsinputid);
! 50: this.makeheaderinput = getFromSelector(makeheaderinputid);
! 51: this.classselect = getFromSelector(classselectid);
! 52: this.alignselect = getFromSelector(alignselectid);
! 53: this.addtablebutton = getFromSelector(addtablebuttonid);
! 54: this.addrowbutton = getFromSelector(addrowbuttonid);
! 55: this.delrowbutton = getFromSelector(delrowbuttonid);
! 56: this.setrowrepeatbutton = getFromSelector(setrowrepeatbuttonid);
! 57: this.delrowrepeatbutton = getFromSelector(delrowrepeatbuttonid);
! 58: this.addcolbutton = getFromSelector(addcolbuttonid);
! 59: this.delcolbutton = getFromSelector(delcolbuttonid);
! 60: this.fixbutton = getFromSelector(fixbuttonid);
! 61: this.fixallbutton = getFromSelector(fixallbuttonid);
! 62: this.toolboxel = getFromSelector(toolboxid);
! 63: this.plainclass = plainclass;
! 64: this.activeclass = activeclass;
! 65:
! 66: this.initialize = function(tool, editor) {
! 67: /* attach the event handlers */
! 68: this.tool = tool;
! 69: this.editor = editor;
! 70: // build the select list of table classes if configured
! 71: if (this.editor.config.table_classes) {
! 72: var classes = this.editor.config.table_classes['class'];
! 73: while (this.classselect.hasChildNodes()) {
! 74: this.classselect.removeChild(this.classselect.firstChild);
! 75: };
! 76: for (var i=0; i < classes.length; i++) {
! 77: var classname = classes[i];
! 78: var option = document.createElement('option');
! 79: var content = document.createTextNode(classname);
! 80: option.appendChild(content);
! 81: option.setAttribute('value', classname);
! 82: this.classselect.appendChild(option);
! 83: };
! 84: };
! 85: addEventHandler(this.addtablebutton, "click", this.addTable, this);
! 86: addEventHandler(this.addrowbutton, "click", this.tool.addTableRow, this.tool);
! 87: addEventHandler(this.delrowbutton, "click", this.tool.delTableRow, this.tool);
! 88: addEventHandler(this.setrowrepeatbutton, "click", this.tool.setTableRowRepeat, this.tool);
! 89: addEventHandler(this.delrowrepeatbutton, "click", this.tool.delTableRowRepeat, this.tool);
! 90: addEventHandler(this.addcolbutton, "click", this.tool.addTableColumn, this.tool);
! 91: addEventHandler(this.delcolbutton, "click", this.tool.delTableColumn, this.tool);
! 92: addEventHandler(this.alignselect, "change", this.setColumnAlign, this);
! 93: addEventHandler(this.classselect, "change", this.setTableClass, this);
! 94: addEventHandler(this.fixbutton, "click", this.tool.fixTable, this.tool);
! 95: addEventHandler(this.fixallbutton, "click", this.tool.fixAllTables, this.tool);
! 96: this.addtablediv.style.display = "block";
! 97: this.edittablediv.style.display = "none";
! 98: this.editor.logMessage(_('Table tool initialized'));
! 99: };
! 100:
! 101: this.updateState = function(selNode) {
! 102: /* update the state (add/edit) and update the pulldowns (if required) */
! 103: var table = this.editor.getNearestParentOfType(selNode, 'table');
! 104: if (table) {
! 105: this.addtablediv.style.display = "none";
! 106: this.edittablediv.style.display = "block";
! 107:
! 108: var align = this.tool._getColumnAlign(selNode);
! 109: selectSelectItem(this.alignselect, align);
! 110: selectSelectItem(this.classselect, table.className);
! 111: if (this.toolboxel) {
! 112: this.toolboxel.className = this.activeclass;
! 113: };
! 114: var row = this.editor.getNearestParentOfType(selNode, 'tr');
! 115: var isRepeatable = row.getAttribute('repeatable');
! 116: if (isRepeatable) {
! 117: this.setrowrepeatbutton.style.display = 'none';
! 118: this.delrowrepeatbutton.style.display = 'inline';
! 119: } else {
! 120: this.setrowrepeatbutton.style.display = 'inline';
! 121: this.delrowrepeatbutton.style.display = 'none';
! 122: };
! 123: } else {
! 124: this.edittablediv.style.display = "none";
! 125: this.addtablediv.style.display = "block";
! 126: this.alignselect.selectedIndex = 0;
! 127: this.classselect.selectedIndex = 0;
! 128: if (this.toolboxel) {
! 129: this.toolboxel.className = this.plainclass;
! 130: };
! 131: };
! 132: };
! 133: };
! 134:
! 135: CNFTableToolBox.prototype = new TableToolBox;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>