bgneal@45: /** bgneal@45: * $Id: editor_plugin_src.js 953 2008-11-04 10:16:50Z spocke $ bgneal@45: * bgneal@45: * @author Moxiecode bgneal@45: * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: var each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.plugins.TablePlugin', { bgneal@45: init : function(ed, url) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: t.url = url; bgneal@45: bgneal@45: // Register buttons bgneal@45: each([ bgneal@45: ['table', 'table.desc', 'mceInsertTable', true], bgneal@45: ['delete_table', 'table.del', 'mceTableDelete'], bgneal@45: ['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'], bgneal@45: ['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'], bgneal@45: ['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'], bgneal@45: ['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'], bgneal@45: ['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'], bgneal@45: ['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'], bgneal@45: ['row_props', 'table.row_desc', 'mceTableRowProps', true], bgneal@45: ['cell_props', 'table.cell_desc', 'mceTableCellProps', true], bgneal@45: ['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true], bgneal@45: ['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true] bgneal@45: ], function(c) { bgneal@45: ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]}); bgneal@45: }); bgneal@45: bgneal@45: if (ed.getParam('inline_styles')) { bgneal@45: // Force move of attribs to styles in strict mode bgneal@45: ed.onPreProcess.add(function(ed, o) { bgneal@45: var dom = ed.dom; bgneal@45: bgneal@45: each(dom.select('table', o.node), function(n) { bgneal@45: var v; bgneal@45: bgneal@45: if (v = dom.getAttrib(n, 'width')) { bgneal@45: dom.setStyle(n, 'width', v); bgneal@45: dom.setAttrib(n, 'width'); bgneal@45: } bgneal@45: bgneal@45: if (v = dom.getAttrib(n, 'height')) { bgneal@45: dom.setStyle(n, 'height', v); bgneal@45: dom.setAttrib(n, 'height'); bgneal@45: } bgneal@45: }); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: ed.onInit.add(function() { bgneal@45: if (ed && ed.plugins.contextmenu) { bgneal@45: ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) { bgneal@45: var sm, se = ed.selection, el = se.getNode() || ed.getBody(); bgneal@45: bgneal@45: if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) { bgneal@45: m.removeAll(); bgneal@45: bgneal@45: if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) { bgneal@45: m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true}); bgneal@45: m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); bgneal@45: m.addSeparator(); bgneal@45: } bgneal@45: bgneal@45: if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) { bgneal@45: m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); bgneal@45: m.addSeparator(); bgneal@45: } bgneal@45: bgneal@45: m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true, value : {action : 'insert'}}); bgneal@45: m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable', ui : true}); bgneal@45: m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete', ui : true}); bgneal@45: m.addSeparator(); bgneal@45: bgneal@45: // Cell menu bgneal@45: sm = m.addMenu({title : 'table.cell'}); bgneal@45: sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps', ui : true}); bgneal@45: sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells', ui : true}); bgneal@45: sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells', ui : true}); bgneal@45: bgneal@45: // Row menu bgneal@45: sm = m.addMenu({title : 'table.row'}); bgneal@45: sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps', ui : true}); bgneal@45: sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'}); bgneal@45: sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'}); bgneal@45: sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'}); bgneal@45: sm.addSeparator(); bgneal@45: sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'}); bgneal@45: sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'}); bgneal@45: sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}); bgneal@45: sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}); bgneal@45: bgneal@45: // Column menu bgneal@45: sm = m.addMenu({title : 'table.col'}); bgneal@45: sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'}); bgneal@45: sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'}); bgneal@45: sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'}); bgneal@45: } else bgneal@45: m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true}); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Add undo level when new rows are created using the tab key bgneal@45: ed.onKeyDown.add(function(ed, e) { bgneal@45: if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE')) { bgneal@45: if (!tinymce.isGecko && !tinymce.isOpera) { bgneal@45: tinyMCE.execInstanceCommand(ed.editorId, "mceTableMoveToNextRow", true); bgneal@45: return tinymce.dom.Event.cancel(e); bgneal@45: } bgneal@45: bgneal@45: ed.undoManager.add(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Select whole table is a table border is clicked bgneal@45: if (!tinymce.isIE) { bgneal@45: if (ed.getParam('table_selection', true)) { bgneal@45: ed.onClick.add(function(ed, e) { bgneal@45: e = e.target; bgneal@45: bgneal@45: if (e.nodeName === 'TABLE') bgneal@45: ed.selection.select(e); bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: ed.onNodeChange.add(function(ed, cm, n) { bgneal@45: var p = ed.dom.getParent(n, 'td,th,caption'); bgneal@45: bgneal@45: cm.setActive('table', n.nodeName === 'TABLE' || !!p); bgneal@45: if (p && p.nodeName === 'CAPTION') bgneal@45: p = null; bgneal@45: bgneal@45: cm.setDisabled('delete_table', !p); bgneal@45: cm.setDisabled('delete_col', !p); bgneal@45: cm.setDisabled('delete_table', !p); bgneal@45: cm.setDisabled('delete_row', !p); bgneal@45: cm.setDisabled('col_after', !p); bgneal@45: cm.setDisabled('col_before', !p); bgneal@45: cm.setDisabled('row_after', !p); bgneal@45: cm.setDisabled('row_before', !p); bgneal@45: cm.setDisabled('row_props', !p); bgneal@45: cm.setDisabled('cell_props', !p); bgneal@45: cm.setDisabled('split_cells', !p || (parseInt(ed.dom.getAttrib(p, 'colspan', '1')) < 2 && parseInt(ed.dom.getAttrib(p, 'rowspan', '1')) < 2)); bgneal@45: cm.setDisabled('merge_cells', !p); bgneal@45: }); bgneal@45: bgneal@45: // Padd empty table cells bgneal@45: if (!tinymce.isIE) { bgneal@45: ed.onBeforeSetContent.add(function(ed, o) { bgneal@45: if (o.initial) bgneal@45: o.content = o.content.replace(/<(td|th)([^>]+|)>\s*<\/(td|th)>/g, tinymce.isOpera ? '<$1$2> ' : '<$1$2>
'); bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(cmd, ui, val) { bgneal@45: var ed = this.editor, b; bgneal@45: bgneal@45: // Is table command bgneal@45: switch (cmd) { bgneal@45: case "mceTableMoveToNextRow": bgneal@45: case "mceInsertTable": bgneal@45: case "mceTableRowProps": bgneal@45: case "mceTableCellProps": bgneal@45: case "mceTableSplitCells": bgneal@45: case "mceTableMergeCells": bgneal@45: case "mceTableInsertRowBefore": bgneal@45: case "mceTableInsertRowAfter": bgneal@45: case "mceTableDeleteRow": bgneal@45: case "mceTableInsertColBefore": bgneal@45: case "mceTableInsertColAfter": bgneal@45: case "mceTableDeleteCol": bgneal@45: case "mceTableCutRow": bgneal@45: case "mceTableCopyRow": bgneal@45: case "mceTablePasteRowBefore": bgneal@45: case "mceTablePasteRowAfter": bgneal@45: case "mceTableDelete": bgneal@45: ed.execCommand('mceBeginUndoLevel'); bgneal@45: this._doExecCommand(cmd, ui, val); bgneal@45: ed.execCommand('mceEndUndoLevel'); bgneal@45: bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Pass to next handler in chain bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'Tables', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: // Private plugin internal methods bgneal@45: bgneal@45: /** bgneal@45: * Executes the table commands. bgneal@45: */ bgneal@45: _doExecCommand : function(command, user_interface, value) { bgneal@45: var inst = this.editor, ed = inst, url = this.url; bgneal@45: var focusElm = inst.selection.getNode(); bgneal@45: var trElm = inst.dom.getParent(focusElm, "tr"); bgneal@45: var tdElm = inst.dom.getParent(focusElm, "td,th"); bgneal@45: var tableElm = inst.dom.getParent(focusElm, "table"); bgneal@45: var doc = inst.contentWindow.document; bgneal@45: var tableBorder = tableElm ? tableElm.getAttribute("border") : ""; bgneal@45: bgneal@45: // Get first TD if no TD found bgneal@45: if (trElm && tdElm == null) bgneal@45: tdElm = trElm.cells[0]; bgneal@45: bgneal@45: function inArray(ar, v) { bgneal@45: for (var i=0; i 0 && inArray(ar[i], v)) bgneal@45: return true; bgneal@45: bgneal@45: // Found value bgneal@45: if (ar[i] == v) bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: function select(dx, dy) { bgneal@45: var td; bgneal@45: bgneal@45: grid = getTableGrid(tableElm); bgneal@45: dx = dx || 0; bgneal@45: dy = dy || 0; bgneal@45: dx = Math.max(cpos.cellindex + dx, 0); bgneal@45: dy = Math.max(cpos.rowindex + dy, 0); bgneal@45: bgneal@45: // Recalculate grid and select bgneal@45: inst.execCommand('mceRepaint'); bgneal@45: td = getCell(grid, dy, dx); bgneal@45: bgneal@45: if (td) { bgneal@45: inst.selection.select(td.firstChild || td); bgneal@45: inst.selection.collapse(1); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function makeTD() { bgneal@45: var newTD = doc.createElement("td"); bgneal@45: bgneal@45: if (!tinymce.isIE) bgneal@45: newTD.innerHTML = '
'; bgneal@45: } bgneal@45: bgneal@45: function getColRowSpan(td) { bgneal@45: var colspan = inst.dom.getAttrib(td, "colspan"); bgneal@45: var rowspan = inst.dom.getAttrib(td, "rowspan"); bgneal@45: bgneal@45: colspan = colspan == "" ? 1 : parseInt(colspan); bgneal@45: rowspan = rowspan == "" ? 1 : parseInt(rowspan); bgneal@45: bgneal@45: return {colspan : colspan, rowspan : rowspan}; bgneal@45: } bgneal@45: bgneal@45: function getCellPos(grid, td) { bgneal@45: var x, y; bgneal@45: bgneal@45: for (y=0; y 1) { // Remove due to colspan bgneal@45: for (var i=x; i 1) bgneal@45: td.rowSpan = sd.rowspan + 1; bgneal@45: bgneal@45: lastElm = td; bgneal@45: } bgneal@45: bgneal@45: deleteMarked(tableElm); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: function prevElm(node, name) { bgneal@45: while ((node = node.previousSibling) != null) { bgneal@45: if (node.nodeName == name) bgneal@45: return node; bgneal@45: } bgneal@45: bgneal@45: return null; bgneal@45: } bgneal@45: bgneal@45: function nextElm(node, names) { bgneal@45: var namesAr = names.split(','); bgneal@45: bgneal@45: while ((node = node.nextSibling) != null) { bgneal@45: for (var i=0; i 1) { bgneal@45: do { bgneal@45: var nexttd = nextElm(td, "TD,TH"); bgneal@45: bgneal@45: if (td._delete) bgneal@45: td.parentNode.removeChild(td); bgneal@45: } while ((td = nexttd) != null); bgneal@45: } bgneal@45: } while ((tr = next) != null); bgneal@45: } bgneal@45: bgneal@45: function addRows(td_elm, tr_elm, rowspan) { bgneal@45: // Add rows bgneal@45: td_elm.rowSpan = 1; bgneal@45: var trNext = nextElm(tr_elm, "TR"); bgneal@45: for (var i=1; i 1) { bgneal@45: var newTD = cells[x].cloneNode(true); bgneal@45: var sd = getColRowSpan(cells[x]); bgneal@45: bgneal@45: newTD.rowSpan = sd.rowspan - 1; bgneal@45: bgneal@45: var nextTD = nextTR.cells[x]; bgneal@45: bgneal@45: if (nextTD == null) bgneal@45: nextTR.appendChild(newTD); bgneal@45: else bgneal@45: nextTR.insertBefore(newTD, nextTD); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Delete cells bgneal@45: var lastTDElm = null; bgneal@45: for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) { bgneal@45: if (tdElm != lastTDElm) { bgneal@45: var sd = getColRowSpan(tdElm); bgneal@45: bgneal@45: if (sd.rowspan > 1) { bgneal@45: tdElm.rowSpan = sd.rowspan - 1; bgneal@45: } else { bgneal@45: trElm = tdElm.parentNode; bgneal@45: bgneal@45: if (trElm.parentNode) bgneal@45: trElm._delete = true; bgneal@45: } bgneal@45: bgneal@45: lastTDElm = tdElm; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: deleteMarked(tableElm); bgneal@45: bgneal@45: select(0, -1); bgneal@45: break; bgneal@45: bgneal@45: case "mceTableInsertColBefore": bgneal@45: if (!trElm || !tdElm) bgneal@45: return true; bgneal@45: bgneal@45: var grid = getTableGrid(inst.dom.getParent(tableElm, "table")); bgneal@45: var cpos = getCellPos(grid, tdElm); bgneal@45: var lastTDElm = null; bgneal@45: bgneal@45: for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { bgneal@45: if (tdElm != lastTDElm) { bgneal@45: var sd = getColRowSpan(tdElm); bgneal@45: bgneal@45: if (sd['colspan'] == 1) { bgneal@45: var newTD = doc.createElement(tdElm.nodeName); bgneal@45: bgneal@45: if (!tinymce.isIE) bgneal@45: newTD.innerHTML = '
'; bgneal@45: bgneal@45: newTD.rowSpan = tdElm.rowSpan; bgneal@45: bgneal@45: tdElm.parentNode.insertBefore(newTD, tdElm); bgneal@45: } else bgneal@45: tdElm.colSpan++; bgneal@45: bgneal@45: lastTDElm = tdElm; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: select(); bgneal@45: break; bgneal@45: bgneal@45: case "mceTableInsertColAfter": bgneal@45: if (!trElm || !tdElm) bgneal@45: return true; bgneal@45: bgneal@45: var grid = getTableGrid(inst.dom.getParent(tableElm, "table")); bgneal@45: var cpos = getCellPos(grid, tdElm); bgneal@45: var lastTDElm = null; bgneal@45: bgneal@45: for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { bgneal@45: if (tdElm != lastTDElm) { bgneal@45: var sd = getColRowSpan(tdElm); bgneal@45: bgneal@45: if (sd['colspan'] == 1) { bgneal@45: var newTD = doc.createElement(tdElm.nodeName); bgneal@45: bgneal@45: if (!tinymce.isIE) bgneal@45: newTD.innerHTML = '
'; bgneal@45: bgneal@45: newTD.rowSpan = tdElm.rowSpan; bgneal@45: bgneal@45: var nextTD = nextElm(tdElm, "TD,TH"); bgneal@45: if (nextTD == null) bgneal@45: tdElm.parentNode.appendChild(newTD); bgneal@45: else bgneal@45: nextTD.parentNode.insertBefore(newTD, nextTD); bgneal@45: } else bgneal@45: tdElm.colSpan++; bgneal@45: bgneal@45: lastTDElm = tdElm; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: select(1); bgneal@45: break; bgneal@45: bgneal@45: case "mceTableDeleteCol": bgneal@45: if (!trElm || !tdElm) bgneal@45: return true; bgneal@45: bgneal@45: var grid = getTableGrid(tableElm); bgneal@45: var cpos = getCellPos(grid, tdElm); bgneal@45: var lastTDElm = null; bgneal@45: bgneal@45: // Only one col, remove whole table bgneal@45: if ((grid.length > 1 && grid[0].length <= 1) && tableElm.nodeName == 'TBODY') { bgneal@45: inst.dom.remove(inst.dom.getParent(tableElm, "table")); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Delete cells bgneal@45: for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) { bgneal@45: if (tdElm != lastTDElm) { bgneal@45: var sd = getColRowSpan(tdElm); bgneal@45: bgneal@45: if (sd['colspan'] > 1) bgneal@45: tdElm.colSpan = sd['colspan'] - 1; bgneal@45: else { bgneal@45: if (tdElm.parentNode) bgneal@45: tdElm.parentNode.removeChild(tdElm); bgneal@45: } bgneal@45: bgneal@45: lastTDElm = tdElm; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: select(-1); bgneal@45: break; bgneal@45: bgneal@45: case "mceTableSplitCells": bgneal@45: if (!trElm || !tdElm) bgneal@45: return true; bgneal@45: bgneal@45: var spandata = getColRowSpan(tdElm); bgneal@45: bgneal@45: var colspan = spandata["colspan"]; bgneal@45: var rowspan = spandata["rowspan"]; bgneal@45: bgneal@45: // Needs splitting bgneal@45: if (colspan > 1 || rowspan > 1) { bgneal@45: // Generate cols bgneal@45: tdElm.colSpan = 1; bgneal@45: for (var i=1; i 1) bgneal@45: addRows(newTD, trElm, rowspan); bgneal@45: } bgneal@45: bgneal@45: addRows(tdElm, trElm, rowspan); bgneal@45: } bgneal@45: bgneal@45: // Apply visual aids bgneal@45: tableElm = inst.dom.getParent(inst.selection.getNode(), "table"); bgneal@45: break; bgneal@45: bgneal@45: case "mceTableMergeCells": bgneal@45: var rows = []; bgneal@45: var sel = inst.selection.getSel(); bgneal@45: var grid = getTableGrid(tableElm); bgneal@45: bgneal@45: if (tinymce.isIE || sel.rangeCount == 1) { bgneal@45: if (user_interface) { bgneal@45: // Setup template bgneal@45: var sp = getColRowSpan(tdElm); bgneal@45: bgneal@45: inst.windowManager.open({ bgneal@45: url : url + '/merge_cells.htm', bgneal@45: width : 240 + parseInt(inst.getLang('table.merge_cells_delta_width', 0)), bgneal@45: height : 110 + parseInt(inst.getLang('table.merge_cells_delta_height', 0)), bgneal@45: inline : 1 bgneal@45: }, { bgneal@45: action : "update", bgneal@45: numcols : sp.colspan, bgneal@45: numrows : sp.rowspan, bgneal@45: plugin_url : url bgneal@45: }); bgneal@45: bgneal@45: return true; bgneal@45: } else { bgneal@45: var numRows = parseInt(value['numrows']); bgneal@45: var numCols = parseInt(value['numcols']); bgneal@45: var cpos = getCellPos(grid, tdElm); bgneal@45: bgneal@45: if (("" + numRows) == "NaN") bgneal@45: numRows = 1; bgneal@45: bgneal@45: if (("" + numCols) == "NaN") bgneal@45: numCols = 1; bgneal@45: bgneal@45: // Get rows and cells bgneal@45: var tRows = tableElm.rows; bgneal@45: for (var y=cpos.rowindex; y 0) bgneal@45: rows[rows.length] = rowCells; bgneal@45: bgneal@45: var td = getCell(grid, cpos.rowindex, cpos.cellindex); bgneal@45: each(ed.dom.select('br', td), function(e, i) { bgneal@45: if (i > 0 && ed.dom.getAttrib('mce_bogus')) bgneal@45: ed.dom.remove(e); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: //return true; bgneal@45: } bgneal@45: } else { bgneal@45: var cells = []; bgneal@45: var sel = inst.selection.getSel(); bgneal@45: var lastTR = null; bgneal@45: var curRow = null; bgneal@45: var x1 = -1, y1 = -1, x2, y2; bgneal@45: bgneal@45: // Only one cell selected, whats the point? bgneal@45: if (sel.rangeCount < 2) bgneal@45: return true; bgneal@45: bgneal@45: // Get all selected cells bgneal@45: for (var i=0; i 0) bgneal@45: rows[rows.length] = rowCells; bgneal@45: } bgneal@45: bgneal@45: // Find selected cells in grid and box bgneal@45: var curRow = []; bgneal@45: var lastTR = null; bgneal@45: for (var y=0; y colSpan) bgneal@45: colSpan = rowColSpan; bgneal@45: bgneal@45: lastRowSpan = -1; bgneal@45: } bgneal@45: bgneal@45: // Validate vertical and get total rowspan bgneal@45: var lastColSpan = -1; bgneal@45: for (var x=0; x rowSpan) bgneal@45: rowSpan = colRowSpan; bgneal@45: bgneal@45: lastColSpan = -1; bgneal@45: } bgneal@45: bgneal@45: // Setup td bgneal@45: tdElm = rows[0][0]; bgneal@45: tdElm.rowSpan = rowSpan; bgneal@45: tdElm.colSpan = colSpan; bgneal@45: bgneal@45: // Merge cells bgneal@45: for (var y=0; y 0)) bgneal@45: tdElm.innerHTML += html; bgneal@45: bgneal@45: // Not current cell bgneal@45: if (rows[y][x] != tdElm && !rows[y][x]._deleted) { bgneal@45: var cpos = getCellPos(grid, rows[y][x]); bgneal@45: var tr = rows[y][x].parentNode; bgneal@45: bgneal@45: tr.removeChild(rows[y][x]); bgneal@45: rows[y][x]._deleted = true; bgneal@45: bgneal@45: // Empty TR, remove it bgneal@45: if (!tr.hasChildNodes()) { bgneal@45: tr.parentNode.removeChild(tr); bgneal@45: bgneal@45: var lastCell = null; bgneal@45: for (var x=0; cellElm = getCell(grid, cpos.rowindex, x); x++) { bgneal@45: if (cellElm != lastCell && cellElm.rowSpan > 1) bgneal@45: cellElm.rowSpan--; bgneal@45: bgneal@45: lastCell = cellElm; bgneal@45: } bgneal@45: bgneal@45: if (tdElm.rowSpan > 1) bgneal@45: tdElm.rowSpan--; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Remove all but one bogus br bgneal@45: each(ed.dom.select('br', tdElm), function(e, i) { bgneal@45: if (i > 0 && ed.dom.getAttrib(e, 'mce_bogus')) bgneal@45: ed.dom.remove(e); bgneal@45: }); bgneal@45: bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: tableElm = inst.dom.getParent(inst.selection.getNode(), "table"); bgneal@45: inst.addVisual(tableElm); bgneal@45: inst.nodeChanged(); bgneal@45: } bgneal@45: bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Pass to next handler in chain bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin); bgneal@45: })();