includes/clientside/tinymce/plugins/table/editor_plugin_src.js
changeset 1344 dc96d6c5cd1e
parent 1343 2a31905a567d
child 1345 1de01205143b
equal deleted inserted replaced
1343:2a31905a567d 1344:dc96d6c5cd1e
     1 /**
       
     2  * $Id: editor_plugin_src.js 1209 2009-08-20 12:35:10Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 (function() {
       
     9 	var each = tinymce.each;
       
    10 
       
    11 	// Checks if the selection/caret is at the start of the specified block element
       
    12 	function isAtStart(rng, par) {
       
    13 		var doc = par.ownerDocument, rng2 = doc.createRange(), elm;
       
    14 
       
    15 		rng2.setStartBefore(par);
       
    16 		rng2.setEnd(rng.endContainer, rng.endOffset);
       
    17 
       
    18 		elm = doc.createElement('body');
       
    19 		elm.appendChild(rng2.cloneContents());
       
    20 
       
    21 		// Check for text characters of other elements that should be treated as content
       
    22 		return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0;
       
    23 	};
       
    24 
       
    25 	tinymce.create('tinymce.plugins.TablePlugin', {
       
    26 		init : function(ed, url) {
       
    27 			var t = this;
       
    28 
       
    29 			t.editor = ed;
       
    30 			t.url = url;
       
    31 
       
    32 			// Register buttons
       
    33 			each([
       
    34 				['table', 'table.desc', 'mceInsertTable', true],
       
    35 				['delete_table', 'table.del', 'mceTableDelete'],
       
    36 				['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
       
    37 				['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
       
    38 				['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
       
    39 				['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
       
    40 				['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
       
    41 				['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
       
    42 				['row_props', 'table.row_desc', 'mceTableRowProps', true],
       
    43 				['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
       
    44 				['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
       
    45 				['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
       
    46 			], function(c) {
       
    47 				ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
       
    48 			});
       
    49 
       
    50 			if (ed.getParam('inline_styles')) {
       
    51 				// Force move of attribs to styles in strict mode
       
    52 				ed.onPreProcess.add(function(ed, o) {
       
    53 					var dom = ed.dom;
       
    54 
       
    55 					each(dom.select('table', o.node), function(n) {
       
    56 						var v;
       
    57 
       
    58 						if (v = dom.getAttrib(n, 'width')) {
       
    59 							dom.setStyle(n, 'width', v);
       
    60 							dom.setAttrib(n, 'width');
       
    61 						}
       
    62 
       
    63 						if (v = dom.getAttrib(n, 'height')) {
       
    64 							dom.setStyle(n, 'height', v);
       
    65 							dom.setAttrib(n, 'height');
       
    66 						}
       
    67 					});
       
    68 				});
       
    69 			}
       
    70 
       
    71 			ed.onInit.add(function() {
       
    72 				// Fixes an issue on Gecko where it's impossible to place the caret behind a table
       
    73 				// This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
       
    74 				if (!tinymce.isIE && ed.getParam('forced_root_block')) {
       
    75 					function fixTableCaretPos() {
       
    76 						var last = ed.getBody().lastChild;
       
    77 
       
    78 						if (last && last.nodeName == 'TABLE')
       
    79 							ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
       
    80 					};
       
    81 
       
    82 					// Fixes an bug where it's impossible to place the caret before a table in Gecko
       
    83 					// this fix solves it by detecting when the caret is at the beginning of such a table
       
    84 					// and then manually moves the caret infront of the table
       
    85 					if (tinymce.isGecko) {
       
    86 						ed.onKeyDown.add(function(ed, e) {
       
    87 							var rng, table, dom = ed.dom;
       
    88 
       
    89 							// On gecko it's not possible to place the caret before a table
       
    90 							if (e.keyCode == 37 || e.keyCode == 38) {
       
    91 								rng = ed.selection.getRng();
       
    92 								table = dom.getParent(rng.startContainer, 'table');
       
    93 
       
    94 								if (table && ed.getBody().firstChild == table) {
       
    95 									if (isAtStart(rng, table)) {
       
    96 										rng = dom.createRng();
       
    97 
       
    98 										rng.setStartBefore(table);
       
    99 										rng.setEndBefore(table);
       
   100 
       
   101 										ed.selection.setRng(rng);
       
   102 
       
   103 										e.preventDefault();
       
   104 									}
       
   105 								}
       
   106 							}
       
   107 						});
       
   108 					}
       
   109 
       
   110 					ed.onKeyUp.add(fixTableCaretPos);
       
   111 					ed.onSetContent.add(fixTableCaretPos);
       
   112 					ed.onVisualAid.add(fixTableCaretPos);
       
   113 
       
   114 					ed.onPreProcess.add(function(ed, o) {
       
   115 						var last = o.node.lastChild;
       
   116 
       
   117 						if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
       
   118 							ed.dom.remove(last);
       
   119 					});
       
   120 
       
   121 					fixTableCaretPos();
       
   122 				}
       
   123 
       
   124 				if (ed && ed.plugins.contextmenu) {
       
   125 					ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
       
   126 						var sm, se = ed.selection, el = se.getNode() || ed.getBody();
       
   127 
       
   128 						if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) {
       
   129 							m.removeAll();
       
   130 
       
   131 							if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
       
   132 								m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
       
   133 								m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
       
   134 								m.addSeparator();
       
   135 							}
       
   136 
       
   137 							if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
       
   138 								m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
       
   139 								m.addSeparator();
       
   140 							}
       
   141 
       
   142 							m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true, value : {action : 'insert'}});
       
   143 							m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable', ui : true});
       
   144 							m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete', ui : true});
       
   145 							m.addSeparator();
       
   146 
       
   147 							// Cell menu
       
   148 							sm = m.addMenu({title : 'table.cell'});
       
   149 							sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps', ui : true});
       
   150 							sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells', ui : true});
       
   151 							sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells', ui : true});
       
   152 
       
   153 							// Row menu
       
   154 							sm = m.addMenu({title : 'table.row'});
       
   155 							sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps', ui : true});
       
   156 							sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
       
   157 							sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
       
   158 							sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
       
   159 							sm.addSeparator();
       
   160 							sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
       
   161 							sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
       
   162 							sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'});
       
   163 							sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'});
       
   164 
       
   165 							// Column menu
       
   166 							sm = m.addMenu({title : 'table.col'});
       
   167 							sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
       
   168 							sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
       
   169 							sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
       
   170 						} else
       
   171 							m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true});
       
   172 					});
       
   173 				}
       
   174 			});
       
   175 
       
   176 			// Add undo level when new rows are created using the tab key
       
   177 			ed.onKeyDown.add(function(ed, e) {
       
   178 				if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE')) {
       
   179 					if (!tinymce.isGecko && !tinymce.isOpera) {
       
   180 						tinyMCE.execInstanceCommand(ed.editorId, "mceTableMoveToNextRow", true);
       
   181 						return tinymce.dom.Event.cancel(e);
       
   182 					}
       
   183 
       
   184 					ed.undoManager.add();
       
   185 				}
       
   186 			});
       
   187 
       
   188 			// Select whole table is a table border is clicked
       
   189 			if (!tinymce.isIE) {
       
   190 				if (ed.getParam('table_selection', true)) {
       
   191 					ed.onClick.add(function(ed, e) {
       
   192 						e = e.target;
       
   193 
       
   194 						if (e.nodeName === 'TABLE')
       
   195 							ed.selection.select(e);
       
   196 					});
       
   197 				}
       
   198 			}
       
   199 
       
   200 			ed.onNodeChange.add(function(ed, cm, n) {
       
   201 				var p = ed.dom.getParent(n, 'td,th,caption');
       
   202 
       
   203 				cm.setActive('table', n.nodeName === 'TABLE' || !!p);
       
   204 				if (p && p.nodeName === 'CAPTION')
       
   205 					p = null;
       
   206 
       
   207 				cm.setDisabled('delete_table', !p);
       
   208 				cm.setDisabled('delete_col', !p);
       
   209 				cm.setDisabled('delete_table', !p);
       
   210 				cm.setDisabled('delete_row', !p);
       
   211 				cm.setDisabled('col_after', !p);
       
   212 				cm.setDisabled('col_before', !p);
       
   213 				cm.setDisabled('row_after', !p);
       
   214 				cm.setDisabled('row_before', !p);
       
   215 				cm.setDisabled('row_props', !p);
       
   216 				cm.setDisabled('cell_props', !p);
       
   217 				cm.setDisabled('split_cells', !p || (parseInt(ed.dom.getAttrib(p, 'colspan', '1')) < 2 && parseInt(ed.dom.getAttrib(p, 'rowspan', '1')) < 2));
       
   218 				cm.setDisabled('merge_cells', !p);
       
   219 			});
       
   220 
       
   221 			// Padd empty table cells
       
   222 			if (!tinymce.isIE) {
       
   223 				ed.onBeforeSetContent.add(function(ed, o) {
       
   224 					if (o.initial)
       
   225 						o.content = o.content.replace(/<(td|th)([^>]+|)>\s*<\/(td|th)>/g, tinymce.isOpera ? '<$1$2>&nbsp;</$1>' : '<$1$2><br mce_bogus="1" /></$1>');
       
   226 				});
       
   227 			}
       
   228 		},
       
   229 
       
   230 		execCommand : function(cmd, ui, val) {
       
   231 			var ed = this.editor, b;
       
   232 
       
   233 			// Is table command
       
   234 			switch (cmd) {
       
   235 				case "mceTableMoveToNextRow":
       
   236 				case "mceInsertTable":
       
   237 				case "mceTableRowProps":
       
   238 				case "mceTableCellProps":
       
   239 				case "mceTableSplitCells":
       
   240 				case "mceTableMergeCells":
       
   241 				case "mceTableInsertRowBefore":
       
   242 				case "mceTableInsertRowAfter":
       
   243 				case "mceTableDeleteRow":
       
   244 				case "mceTableInsertColBefore":
       
   245 				case "mceTableInsertColAfter":
       
   246 				case "mceTableDeleteCol":
       
   247 				case "mceTableCutRow":
       
   248 				case "mceTableCopyRow":
       
   249 				case "mceTablePasteRowBefore":
       
   250 				case "mceTablePasteRowAfter":
       
   251 				case "mceTableDelete":
       
   252 					ed.execCommand('mceBeginUndoLevel');
       
   253 					this._doExecCommand(cmd, ui, val);
       
   254 					ed.execCommand('mceEndUndoLevel');
       
   255 
       
   256 					return true;
       
   257 			}
       
   258 
       
   259 			// Pass to next handler in chain
       
   260 			return false;
       
   261 		},
       
   262 
       
   263 		getInfo : function() {
       
   264 			return {
       
   265 				longname : 'Tables',
       
   266 				author : 'Moxiecode Systems AB',
       
   267 				authorurl : 'http://tinymce.moxiecode.com',
       
   268 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table',
       
   269 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
   270 			};
       
   271 		},
       
   272 
       
   273 		// Private plugin internal methods
       
   274 
       
   275 		/**
       
   276 		 * Executes the table commands.
       
   277 		 */
       
   278 		_doExecCommand : function(command, user_interface, value) {
       
   279 			var inst = this.editor, ed = inst, url = this.url;
       
   280 			var focusElm = inst.selection.getNode();
       
   281 			var trElm = inst.dom.getParent(focusElm, "tr");
       
   282 			var tdElm = inst.dom.getParent(focusElm, "td,th");
       
   283 			var tableElm = inst.dom.getParent(focusElm, "table");
       
   284 			var doc = inst.contentWindow.document;
       
   285 			var tableBorder = tableElm ? tableElm.getAttribute("border") : "";
       
   286 
       
   287 			// Get first TD if no TD found
       
   288 			if (trElm && tdElm == null)
       
   289 				tdElm = trElm.cells[0];
       
   290 
       
   291 			function inArray(ar, v) {
       
   292 				for (var i=0; i<ar.length; i++) {
       
   293 					// Is array
       
   294 					if (ar[i].length > 0 && inArray(ar[i], v))
       
   295 						return true;
       
   296 
       
   297 					// Found value
       
   298 					if (ar[i] == v)
       
   299 						return true;
       
   300 				}
       
   301 
       
   302 				return false;
       
   303 			}
       
   304 
       
   305 			function select(dx, dy) {
       
   306 				var td;
       
   307 
       
   308 				grid = getTableGrid(tableElm);
       
   309 				dx = dx || 0;
       
   310 				dy = dy || 0;
       
   311 				dx = Math.max(cpos.cellindex + dx, 0);
       
   312 				dy = Math.max(cpos.rowindex + dy, 0);
       
   313 
       
   314 				// Recalculate grid and select
       
   315 				inst.execCommand('mceRepaint');
       
   316 				td = getCell(grid, dy, dx);
       
   317 
       
   318 				if (td) {
       
   319 					inst.selection.select(td.firstChild || td);
       
   320 					inst.selection.collapse(1);
       
   321 				}
       
   322 			};
       
   323 
       
   324 			function makeTD() {
       
   325 				var newTD = doc.createElement("td");
       
   326 
       
   327 				if (!tinymce.isIE)
       
   328 					newTD.innerHTML = '<br mce_bogus="1"/>';
       
   329 			}
       
   330 
       
   331 			function getColRowSpan(td) {
       
   332 				var colspan = inst.dom.getAttrib(td, "colspan");
       
   333 				var rowspan = inst.dom.getAttrib(td, "rowspan");
       
   334 
       
   335 				colspan = colspan == "" ? 1 : parseInt(colspan);
       
   336 				rowspan = rowspan == "" ? 1 : parseInt(rowspan);
       
   337 
       
   338 				return {colspan : colspan, rowspan : rowspan};
       
   339 			}
       
   340 
       
   341 			function getCellPos(grid, td) {
       
   342 				var x, y;
       
   343 
       
   344 				for (y=0; y<grid.length; y++) {
       
   345 					for (x=0; x<grid[y].length; x++) {
       
   346 						if (grid[y][x] == td)
       
   347 							return {cellindex : x, rowindex : y};
       
   348 					}
       
   349 				}
       
   350 
       
   351 				return null;
       
   352 			}
       
   353 
       
   354 			function getCell(grid, row, col) {
       
   355 				if (grid[row] && grid[row][col])
       
   356 					return grid[row][col];
       
   357 
       
   358 				return null;
       
   359 			}
       
   360 
       
   361 			function getNextCell(table, cell) {
       
   362 				var cells = [], x = 0, i, j, cell, nextCell;
       
   363 
       
   364 				for (i = 0; i < table.rows.length; i++)
       
   365 					for (j = 0; j < table.rows[i].cells.length; j++, x++)
       
   366 						cells[x] = table.rows[i].cells[j];
       
   367 
       
   368 				for (i = 0; i < cells.length; i++)
       
   369 					if (cells[i] == cell)
       
   370 						if (nextCell = cells[i+1])
       
   371 							return nextCell;
       
   372 			}
       
   373 
       
   374 			function getTableGrid(table) {
       
   375 				var grid = [], rows = table.rows, x, y, td, sd, xstart, x2, y2;
       
   376 
       
   377 				for (y=0; y<rows.length; y++) {
       
   378 					for (x=0; x<rows[y].cells.length; x++) {
       
   379 						td = rows[y].cells[x];
       
   380 						sd = getColRowSpan(td);
       
   381 
       
   382 						// All ready filled
       
   383 						for (xstart = x; grid[y] && grid[y][xstart]; xstart++) ;
       
   384 
       
   385 						// Fill box
       
   386 						for (y2=y; y2<y+sd['rowspan']; y2++) {
       
   387 							if (!grid[y2])
       
   388 								grid[y2] = [];
       
   389 
       
   390 							for (x2=xstart; x2<xstart+sd['colspan']; x2++)
       
   391 								grid[y2][x2] = td;
       
   392 						}
       
   393 					}
       
   394 				}
       
   395 
       
   396 				return grid;
       
   397 			}
       
   398 
       
   399 			function trimRow(table, tr, td, new_tr) {
       
   400 				var grid = getTableGrid(table), cpos = getCellPos(grid, td);
       
   401 				var cells, lastElm;
       
   402 
       
   403 				// Time to crop away some
       
   404 				if (new_tr.cells.length != tr.childNodes.length) {
       
   405 					cells = tr.childNodes;
       
   406 					lastElm = null;
       
   407 
       
   408 					for (var x=0; td = getCell(grid, cpos.rowindex, x); x++) {
       
   409 						var remove = true;
       
   410 						var sd = getColRowSpan(td);
       
   411 
       
   412 						// Remove due to rowspan
       
   413 						if (inArray(cells, td)) {
       
   414 							new_tr.childNodes[x]._delete = true;
       
   415 						} else if ((lastElm == null || td != lastElm) && sd.colspan > 1) { // Remove due to colspan
       
   416 							for (var i=x; i<x+td.colSpan; i++)
       
   417 								new_tr.childNodes[i]._delete = true;
       
   418 						}
       
   419 
       
   420 						if ((lastElm == null || td != lastElm) && sd.rowspan > 1)
       
   421 							td.rowSpan = sd.rowspan + 1;
       
   422 
       
   423 						lastElm = td;
       
   424 					}
       
   425 
       
   426 					deleteMarked(tableElm);
       
   427 				}
       
   428 			}
       
   429 
       
   430 			function prevElm(node, name) {
       
   431 				while ((node = node.previousSibling) != null) {
       
   432 					if (node.nodeName == name)
       
   433 						return node;
       
   434 				}
       
   435 
       
   436 				return null;
       
   437 			}
       
   438 
       
   439 			function nextElm(node, names) {
       
   440 				var namesAr = names.split(',');
       
   441 
       
   442 				while ((node = node.nextSibling) != null) {
       
   443 					for (var i=0; i<namesAr.length; i++) {
       
   444 						if (node.nodeName.toLowerCase() == namesAr[i].toLowerCase() )
       
   445 							return node;
       
   446 					}
       
   447 				}
       
   448 
       
   449 				return null;
       
   450 			}
       
   451 
       
   452 			function deleteMarked(tbl) {
       
   453 				if (tbl.rows == 0)
       
   454 					return;
       
   455 
       
   456 				var tr = tbl.rows[0];
       
   457 				do {
       
   458 					var next = nextElm(tr, "TR");
       
   459 
       
   460 					// Delete row
       
   461 					if (tr._delete) {
       
   462 						tr.parentNode.removeChild(tr);
       
   463 						continue;
       
   464 					}
       
   465 
       
   466 					// Delete cells
       
   467 					var td = tr.cells[0];
       
   468 					if (td.cells > 1) {
       
   469 						do {
       
   470 							var nexttd = nextElm(td, "TD,TH");
       
   471 
       
   472 							if (td._delete)
       
   473 								td.parentNode.removeChild(td);
       
   474 						} while ((td = nexttd) != null);
       
   475 					}
       
   476 				} while ((tr = next) != null);
       
   477 			}
       
   478 
       
   479 			function addRows(td_elm, tr_elm, rowspan) {
       
   480 				// Add rows
       
   481 				td_elm.rowSpan = 1;
       
   482 				var trNext = nextElm(tr_elm, "TR");
       
   483 				for (var i=1; i<rowspan && trNext; i++) {
       
   484 					var newTD = doc.createElement("td");
       
   485 
       
   486 					if (!tinymce.isIE)
       
   487 						newTD.innerHTML = '<br mce_bogus="1"/>';
       
   488 
       
   489 					if (tinymce.isIE)
       
   490 						trNext.insertBefore(newTD, trNext.cells(td_elm.cellIndex));
       
   491 					else
       
   492 						trNext.insertBefore(newTD, trNext.cells[td_elm.cellIndex]);
       
   493 
       
   494 					trNext = nextElm(trNext, "TR");
       
   495 				}
       
   496 			}
       
   497 
       
   498 			function copyRow(doc, table, tr) {
       
   499 				var grid = getTableGrid(table);
       
   500 				var newTR = tr.cloneNode(false);
       
   501 				var cpos = getCellPos(grid, tr.cells[0]);
       
   502 				var lastCell = null;
       
   503 				var tableBorder = inst.dom.getAttrib(table, "border");
       
   504 				var tdElm = null;
       
   505 
       
   506 				for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
       
   507 					var newTD = null;
       
   508 
       
   509 					if (lastCell != tdElm) {
       
   510 						for (var i=0; i<tr.cells.length; i++) {
       
   511 							if (tdElm == tr.cells[i]) {
       
   512 								newTD = tdElm.cloneNode(true);
       
   513 								break;
       
   514 							}
       
   515 						}
       
   516 					}
       
   517 
       
   518 					if (newTD == null) {
       
   519 						newTD = doc.createElement("td");
       
   520 
       
   521 						if (!tinymce.isIE)
       
   522 							newTD.innerHTML = '<br mce_bogus="1"/>';
       
   523 					}
       
   524 
       
   525 					// Reset col/row span
       
   526 					newTD.colSpan = 1;
       
   527 					newTD.rowSpan = 1;
       
   528 
       
   529 					newTR.appendChild(newTD);
       
   530 
       
   531 					lastCell = tdElm;
       
   532 				}
       
   533 
       
   534 				return newTR;
       
   535 			}
       
   536 
       
   537 			// ---- Commands -----
       
   538 
       
   539 			// Handle commands
       
   540 			switch (command) {
       
   541 				case "mceTableMoveToNextRow":
       
   542 					var nextCell = getNextCell(tableElm, tdElm);
       
   543 
       
   544 					if (!nextCell) {
       
   545 						inst.execCommand("mceTableInsertRowAfter", tdElm);
       
   546 						nextCell = getNextCell(tableElm, tdElm);
       
   547 					}
       
   548 
       
   549 					inst.selection.select(nextCell);
       
   550 					inst.selection.collapse(true);
       
   551 
       
   552 					return true;
       
   553 
       
   554 				case "mceTableRowProps":
       
   555 					if (trElm == null)
       
   556 						return true;
       
   557 
       
   558 					if (user_interface) {
       
   559 						inst.windowManager.open({
       
   560 							url : url + '/row.htm',
       
   561 							width : 400 + parseInt(inst.getLang('table.rowprops_delta_width', 0)),
       
   562 							height : 295 + parseInt(inst.getLang('table.rowprops_delta_height', 0)),
       
   563 							inline : 1
       
   564 						}, {
       
   565 							plugin_url : url
       
   566 						});
       
   567 					}
       
   568 
       
   569 					return true;
       
   570 
       
   571 				case "mceTableCellProps":
       
   572 					if (tdElm == null)
       
   573 						return true;
       
   574 
       
   575 					if (user_interface) {
       
   576 						inst.windowManager.open({
       
   577 							url : url + '/cell.htm',
       
   578 							width : 400 + parseInt(inst.getLang('table.cellprops_delta_width', 0)),
       
   579 							height : 295 + parseInt(inst.getLang('table.cellprops_delta_height', 0)),
       
   580 							inline : 1
       
   581 						}, {
       
   582 							plugin_url : url
       
   583 						});
       
   584 					}
       
   585 
       
   586 					return true;
       
   587 
       
   588 				case "mceInsertTable":
       
   589 					if (user_interface) {
       
   590 						inst.windowManager.open({
       
   591 							url : url + '/table.htm',
       
   592 							width : 400 + parseInt(inst.getLang('table.table_delta_width', 0)),
       
   593 							height : 320 + parseInt(inst.getLang('table.table_delta_height', 0)),
       
   594 							inline : 1
       
   595 						}, {
       
   596 							plugin_url : url,
       
   597 							action : value ? value.action : 0
       
   598 						});
       
   599 					}
       
   600 
       
   601 					return true;
       
   602 
       
   603 				case "mceTableDelete":
       
   604 					var table = inst.dom.getParent(inst.selection.getNode(), "table");
       
   605 					if (table) {
       
   606 						table.parentNode.removeChild(table);
       
   607 						inst.execCommand('mceRepaint');
       
   608 					}
       
   609 					return true;
       
   610 
       
   611 				case "mceTableSplitCells":
       
   612 				case "mceTableMergeCells":
       
   613 				case "mceTableInsertRowBefore":
       
   614 				case "mceTableInsertRowAfter":
       
   615 				case "mceTableDeleteRow":
       
   616 				case "mceTableInsertColBefore":
       
   617 				case "mceTableInsertColAfter":
       
   618 				case "mceTableDeleteCol":
       
   619 				case "mceTableCutRow":
       
   620 				case "mceTableCopyRow":
       
   621 				case "mceTablePasteRowBefore":
       
   622 				case "mceTablePasteRowAfter":
       
   623 					// No table just return (invalid command)
       
   624 					if (!tableElm)
       
   625 						return true;
       
   626 
       
   627 					// Table has a tbody use that reference
       
   628 					// Changed logic by ApTest 2005.07.12 (www.aptest.com)
       
   629 					// Now lookk at the focused element and take its parentNode.  That will be a tbody or a table.
       
   630 					if (trElm && tableElm != trElm.parentNode)
       
   631 						tableElm = trElm.parentNode;
       
   632 
       
   633 					if (tableElm && trElm) {
       
   634 						switch (command) {
       
   635 							case "mceTableCutRow":
       
   636 								if (!trElm || !tdElm)
       
   637 									return true;
       
   638 
       
   639 								inst.tableRowClipboard = copyRow(doc, tableElm, trElm);
       
   640 								inst.execCommand("mceTableDeleteRow");
       
   641 								break;
       
   642 
       
   643 							case "mceTableCopyRow":
       
   644 								if (!trElm || !tdElm)
       
   645 									return true;
       
   646 
       
   647 								inst.tableRowClipboard = copyRow(doc, tableElm, trElm);
       
   648 								break;
       
   649 
       
   650 							case "mceTablePasteRowBefore":
       
   651 								if (!trElm || !tdElm)
       
   652 									return true;
       
   653 
       
   654 								var newTR = inst.tableRowClipboard.cloneNode(true);
       
   655 
       
   656 								var prevTR = prevElm(trElm, "TR");
       
   657 								if (prevTR != null)
       
   658 									trimRow(tableElm, prevTR, prevTR.cells[0], newTR);
       
   659 
       
   660 								trElm.parentNode.insertBefore(newTR, trElm);
       
   661 								break;
       
   662 
       
   663 							case "mceTablePasteRowAfter":
       
   664 								if (!trElm || !tdElm)
       
   665 									return true;
       
   666 								
       
   667 								var nextTR = nextElm(trElm, "TR");
       
   668 								var newTR = inst.tableRowClipboard.cloneNode(true);
       
   669 
       
   670 								trimRow(tableElm, trElm, tdElm, newTR);
       
   671 
       
   672 								if (nextTR == null)
       
   673 									trElm.parentNode.appendChild(newTR);
       
   674 								else
       
   675 									nextTR.parentNode.insertBefore(newTR, nextTR);
       
   676 
       
   677 								break;
       
   678 
       
   679 							case "mceTableInsertRowBefore":
       
   680 								if (!trElm || !tdElm)
       
   681 									return true;
       
   682 
       
   683 								var grid = getTableGrid(tableElm);
       
   684 								var cpos = getCellPos(grid, tdElm);
       
   685 								var newTR = doc.createElement("tr");
       
   686 								var lastTDElm = null;
       
   687 
       
   688 								cpos.rowindex--;
       
   689 								if (cpos.rowindex < 0)
       
   690 									cpos.rowindex = 0;
       
   691 
       
   692 								// Create cells
       
   693 								for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
       
   694 									if (tdElm != lastTDElm) {
       
   695 										var sd = getColRowSpan(tdElm);
       
   696 
       
   697 										if (sd['rowspan'] == 1) {
       
   698 											var newTD = doc.createElement("td");
       
   699 
       
   700 											if (!tinymce.isIE)
       
   701 												newTD.innerHTML = '<br mce_bogus="1"/>';
       
   702 
       
   703 											newTD.colSpan = tdElm.colSpan;
       
   704 
       
   705 											newTR.appendChild(newTD);
       
   706 										} else
       
   707 											tdElm.rowSpan = sd['rowspan'] + 1;
       
   708 
       
   709 										lastTDElm = tdElm;
       
   710 									}
       
   711 								}
       
   712 
       
   713 								trElm.parentNode.insertBefore(newTR, trElm);
       
   714 								select(0, 1);
       
   715 							break;
       
   716 
       
   717 							case "mceTableInsertRowAfter":
       
   718 								if (!trElm || !tdElm)
       
   719 									return true;
       
   720 
       
   721 								var grid = getTableGrid(tableElm);
       
   722 								var cpos = getCellPos(grid, tdElm);
       
   723 								var newTR = doc.createElement("tr");
       
   724 								var lastTDElm = null;
       
   725 
       
   726 								// Create cells
       
   727 								for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
       
   728 									if (tdElm != lastTDElm) {
       
   729 										var sd = getColRowSpan(tdElm);
       
   730 
       
   731 										if (sd['rowspan'] == 1) {
       
   732 											var newTD = doc.createElement("td");
       
   733 
       
   734 											if (!tinymce.isIE)
       
   735 												newTD.innerHTML = '<br mce_bogus="1"/>';
       
   736 
       
   737 											newTD.colSpan = tdElm.colSpan;
       
   738 
       
   739 											newTR.appendChild(newTD);
       
   740 										} else
       
   741 											tdElm.rowSpan = sd['rowspan'] + 1;
       
   742 
       
   743 										lastTDElm = tdElm;
       
   744 									}
       
   745 								}
       
   746 
       
   747 								if (newTR.hasChildNodes()) {
       
   748 									var nextTR = nextElm(trElm, "TR");
       
   749 									if (nextTR)
       
   750 										nextTR.parentNode.insertBefore(newTR, nextTR);
       
   751 									else
       
   752 										tableElm.appendChild(newTR);
       
   753 								}
       
   754 
       
   755 								select(0, 1);
       
   756 							break;
       
   757 
       
   758 							case "mceTableDeleteRow":
       
   759 								if (!trElm || !tdElm)
       
   760 									return true;
       
   761 
       
   762 								var grid = getTableGrid(tableElm);
       
   763 								var cpos = getCellPos(grid, tdElm);
       
   764 
       
   765 								// Only one row, remove whole table
       
   766 								if (grid.length == 1 && tableElm.nodeName == 'TBODY') {
       
   767 									inst.dom.remove(inst.dom.getParent(tableElm, "table"));
       
   768 									return true;
       
   769 								}
       
   770 
       
   771 								// Move down row spanned cells
       
   772 								var cells = trElm.cells;
       
   773 								var nextTR = nextElm(trElm, "TR");
       
   774 								for (var x=0; x<cells.length; x++) {
       
   775 									if (cells[x].rowSpan > 1) {
       
   776 										var newTD = cells[x].cloneNode(true);
       
   777 										var sd = getColRowSpan(cells[x]);
       
   778 
       
   779 										newTD.rowSpan = sd.rowspan - 1;
       
   780 
       
   781 										var nextTD = nextTR.cells[x];
       
   782 
       
   783 										if (nextTD == null)
       
   784 											nextTR.appendChild(newTD);
       
   785 										else
       
   786 											nextTR.insertBefore(newTD, nextTD);
       
   787 									}
       
   788 								}
       
   789 
       
   790 								// Delete cells
       
   791 								var lastTDElm = null;
       
   792 								for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
       
   793 									if (tdElm != lastTDElm) {
       
   794 										var sd = getColRowSpan(tdElm);
       
   795 
       
   796 										if (sd.rowspan > 1) {
       
   797 											tdElm.rowSpan = sd.rowspan - 1;
       
   798 										} else {
       
   799 											trElm = tdElm.parentNode;
       
   800 
       
   801 											if (trElm.parentNode)
       
   802 												trElm._delete = true;
       
   803 										}
       
   804 
       
   805 										lastTDElm = tdElm;
       
   806 									}
       
   807 								}
       
   808 
       
   809 								deleteMarked(tableElm);
       
   810 
       
   811 								select(0, -1);
       
   812 							break;
       
   813 
       
   814 							case "mceTableInsertColBefore":
       
   815 								if (!trElm || !tdElm)
       
   816 									return true;
       
   817 
       
   818 								var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
       
   819 								var cpos = getCellPos(grid, tdElm);
       
   820 								var lastTDElm = null;
       
   821 
       
   822 								for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
       
   823 									if (tdElm != lastTDElm) {
       
   824 										var sd = getColRowSpan(tdElm);
       
   825 
       
   826 										if (sd['colspan'] == 1) {
       
   827 											var newTD = doc.createElement(tdElm.nodeName);
       
   828 
       
   829 											if (!tinymce.isIE)
       
   830 												newTD.innerHTML = '<br mce_bogus="1"/>';
       
   831 
       
   832 											newTD.rowSpan = tdElm.rowSpan;
       
   833 
       
   834 											tdElm.parentNode.insertBefore(newTD, tdElm);
       
   835 										} else
       
   836 											tdElm.colSpan++;
       
   837 
       
   838 										lastTDElm = tdElm;
       
   839 									}
       
   840 								}
       
   841 
       
   842 								select();
       
   843 							break;
       
   844 
       
   845 							case "mceTableInsertColAfter":
       
   846 								if (!trElm || !tdElm)
       
   847 									return true;
       
   848 
       
   849 								var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
       
   850 								var cpos = getCellPos(grid, tdElm);
       
   851 								var lastTDElm = null;
       
   852 
       
   853 								for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
       
   854 									if (tdElm != lastTDElm) {
       
   855 										var sd = getColRowSpan(tdElm);
       
   856 
       
   857 										if (sd['colspan'] == 1) {
       
   858 											var newTD = doc.createElement(tdElm.nodeName);
       
   859 
       
   860 											if (!tinymce.isIE)
       
   861 												newTD.innerHTML = '<br mce_bogus="1"/>';
       
   862 
       
   863 											newTD.rowSpan = tdElm.rowSpan;
       
   864 
       
   865 											var nextTD = nextElm(tdElm, "TD,TH");
       
   866 											if (nextTD == null)
       
   867 												tdElm.parentNode.appendChild(newTD);
       
   868 											else
       
   869 												nextTD.parentNode.insertBefore(newTD, nextTD);
       
   870 										} else
       
   871 											tdElm.colSpan++;
       
   872 
       
   873 										lastTDElm = tdElm;
       
   874 									}
       
   875 								}
       
   876 
       
   877 								select(1);
       
   878 							break;
       
   879 
       
   880 							case "mceTableDeleteCol":
       
   881 								if (!trElm || !tdElm)
       
   882 									return true;
       
   883 
       
   884 								var grid = getTableGrid(tableElm);
       
   885 								var cpos = getCellPos(grid, tdElm);
       
   886 								var lastTDElm = null;
       
   887 
       
   888 								// Only one col, remove whole table
       
   889 								if ((grid.length > 1 && grid[0].length <= 1) && tableElm.nodeName == 'TBODY') {
       
   890 									inst.dom.remove(inst.dom.getParent(tableElm, "table"));
       
   891 									return true;
       
   892 								}
       
   893 
       
   894 								// Delete cells
       
   895 								for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
       
   896 									if (tdElm != lastTDElm) {
       
   897 										var sd = getColRowSpan(tdElm);
       
   898 
       
   899 										if (sd['colspan'] > 1)
       
   900 											tdElm.colSpan = sd['colspan'] - 1;
       
   901 										else {
       
   902 											if (tdElm.parentNode)
       
   903 												tdElm.parentNode.removeChild(tdElm);
       
   904 										}
       
   905 
       
   906 										lastTDElm = tdElm;
       
   907 									}
       
   908 								}
       
   909 
       
   910 								select(-1);
       
   911 							break;
       
   912 
       
   913 						case "mceTableSplitCells":
       
   914 							if (!trElm || !tdElm)
       
   915 								return true;
       
   916 
       
   917 							var spandata = getColRowSpan(tdElm);
       
   918 
       
   919 							var colspan = spandata["colspan"];
       
   920 							var rowspan = spandata["rowspan"];
       
   921 
       
   922 							// Needs splitting
       
   923 							if (colspan > 1 || rowspan > 1) {
       
   924 								// Generate cols
       
   925 								tdElm.colSpan = 1;
       
   926 								for (var i=1; i<colspan; i++) {
       
   927 									var newTD = doc.createElement("td");
       
   928 
       
   929 									if (!tinymce.isIE)
       
   930 										newTD.innerHTML = '<br mce_bogus="1"/>';
       
   931 
       
   932 									trElm.insertBefore(newTD, nextElm(tdElm, "TD,TH"));
       
   933 
       
   934 									if (rowspan > 1)
       
   935 										addRows(newTD, trElm, rowspan);
       
   936 								}
       
   937 
       
   938 								addRows(tdElm, trElm, rowspan);
       
   939 							}
       
   940 
       
   941 							// Apply visual aids
       
   942 							tableElm = inst.dom.getParent(inst.selection.getNode(), "table");
       
   943 							break;
       
   944 
       
   945 						case "mceTableMergeCells":
       
   946 							var rows = [];
       
   947 							var sel = inst.selection.getSel();
       
   948 							var grid = getTableGrid(tableElm);
       
   949 
       
   950 							if (tinymce.isIE || sel.rangeCount == 1) {
       
   951 								if (user_interface) {
       
   952 									// Setup template
       
   953 									var sp = getColRowSpan(tdElm);
       
   954 
       
   955 									inst.windowManager.open({
       
   956 										url : url + '/merge_cells.htm',
       
   957 										width : 240 + parseInt(inst.getLang('table.merge_cells_delta_width', 0)),
       
   958 										height : 110 + parseInt(inst.getLang('table.merge_cells_delta_height', 0)),
       
   959 										inline : 1
       
   960 									}, {
       
   961 										action : "update",
       
   962 										numcols : sp.colspan,
       
   963 										numrows : sp.rowspan,
       
   964 										plugin_url : url
       
   965 									});
       
   966 
       
   967 									return true;
       
   968 								} else {
       
   969 									var numRows = parseInt(value['numrows']);
       
   970 									var numCols = parseInt(value['numcols']);
       
   971 									var cpos = getCellPos(grid, tdElm);
       
   972 
       
   973 									if (("" + numRows) == "NaN")
       
   974 										numRows = 1;
       
   975 
       
   976 									if (("" + numCols) == "NaN")
       
   977 										numCols = 1;
       
   978 
       
   979 									// Get rows and cells
       
   980 									var tRows = tableElm.rows;
       
   981 									for (var y=cpos.rowindex; y<grid.length; y++) {
       
   982 										var rowCells = [];
       
   983 
       
   984 										for (var x=cpos.cellindex; x<grid[y].length; x++) {
       
   985 											var td = getCell(grid, y, x);
       
   986 
       
   987 											if (td && !inArray(rows, td) && !inArray(rowCells, td)) {
       
   988 												var cp = getCellPos(grid, td);
       
   989 
       
   990 												// Within range
       
   991 												if (cp.cellindex < cpos.cellindex+numCols && cp.rowindex < cpos.rowindex+numRows)
       
   992 													rowCells[rowCells.length] = td;
       
   993 											}
       
   994 										}
       
   995 
       
   996 										if (rowCells.length > 0)
       
   997 											rows[rows.length] = rowCells;
       
   998 
       
   999 										var td = getCell(grid, cpos.rowindex, cpos.cellindex);
       
  1000 										each(ed.dom.select('br', td), function(e, i) {
       
  1001 											if (i > 0 && ed.dom.getAttrib('mce_bogus'))
       
  1002 												ed.dom.remove(e);
       
  1003 										});
       
  1004 									}
       
  1005 
       
  1006 									//return true;
       
  1007 								}
       
  1008 							} else {
       
  1009 								var cells = [];
       
  1010 								var sel = inst.selection.getSel();
       
  1011 								var lastTR = null;
       
  1012 								var curRow = null;
       
  1013 								var x1 = -1, y1 = -1, x2, y2;
       
  1014 
       
  1015 								// Only one cell selected, whats the point?
       
  1016 								if (sel.rangeCount < 2)
       
  1017 									return true;
       
  1018 
       
  1019 								// Get all selected cells
       
  1020 								for (var i=0; i<sel.rangeCount; i++) {
       
  1021 									var rng = sel.getRangeAt(i);
       
  1022 									var tdElm = rng.startContainer.childNodes[rng.startOffset];
       
  1023 
       
  1024 									if (!tdElm)
       
  1025 										break;
       
  1026 
       
  1027 									if (tdElm.nodeName == "TD" || tdElm.nodeName == "TH")
       
  1028 										cells[cells.length] = tdElm;
       
  1029 								}
       
  1030 
       
  1031 								// Get rows and cells
       
  1032 								var tRows = tableElm.rows;
       
  1033 								for (var y=0; y<tRows.length; y++) {
       
  1034 									var rowCells = [];
       
  1035 
       
  1036 									for (var x=0; x<tRows[y].cells.length; x++) {
       
  1037 										var td = tRows[y].cells[x];
       
  1038 
       
  1039 										for (var i=0; i<cells.length; i++) {
       
  1040 											if (td == cells[i]) {
       
  1041 												rowCells[rowCells.length] = td;
       
  1042 											}
       
  1043 										}
       
  1044 									}
       
  1045 
       
  1046 									if (rowCells.length > 0)
       
  1047 										rows[rows.length] = rowCells;
       
  1048 								}
       
  1049 
       
  1050 								// Find selected cells in grid and box
       
  1051 								var curRow = [];
       
  1052 								var lastTR = null;
       
  1053 								for (var y=0; y<grid.length; y++) {
       
  1054 									for (var x=0; x<grid[y].length; x++) {
       
  1055 										grid[y][x]._selected = false;
       
  1056 
       
  1057 										for (var i=0; i<cells.length; i++) {
       
  1058 											if (grid[y][x] == cells[i]) {
       
  1059 												// Get start pos
       
  1060 												if (x1 == -1) {
       
  1061 													x1 = x;
       
  1062 													y1 = y;
       
  1063 												}
       
  1064 
       
  1065 												// Get end pos
       
  1066 												x2 = x;
       
  1067 												y2 = y;
       
  1068 
       
  1069 												grid[y][x]._selected = true;
       
  1070 											}
       
  1071 										}
       
  1072 									}
       
  1073 								}
       
  1074 
       
  1075 								// Is there gaps, if so deny
       
  1076 								for (var y=y1; y<=y2; y++) {
       
  1077 									for (var x=x1; x<=x2; x++) {
       
  1078 										if (!grid[y][x]._selected) {
       
  1079 											alert("Invalid selection for merge.");
       
  1080 											return true;
       
  1081 										}
       
  1082 									}
       
  1083 								}
       
  1084 							}
       
  1085 
       
  1086 							// Validate selection and get total rowspan and colspan
       
  1087 							var rowSpan = 1, colSpan = 1;
       
  1088 
       
  1089 							// Validate horizontal and get total colspan
       
  1090 							var lastRowSpan = -1;
       
  1091 							for (var y=0; y<rows.length; y++) {
       
  1092 								var rowColSpan = 0;
       
  1093 
       
  1094 								for (var x=0; x<rows[y].length; x++) {
       
  1095 									var sd = getColRowSpan(rows[y][x]);
       
  1096 
       
  1097 									rowColSpan += sd['colspan'];
       
  1098 
       
  1099 									if (lastRowSpan != -1 && sd['rowspan'] != lastRowSpan) {
       
  1100 										alert("Invalid selection for merge.");
       
  1101 										return true;
       
  1102 									}
       
  1103 
       
  1104 									lastRowSpan = sd['rowspan'];
       
  1105 								}
       
  1106 
       
  1107 								if (rowColSpan > colSpan)
       
  1108 									colSpan = rowColSpan;
       
  1109 
       
  1110 								lastRowSpan = -1;
       
  1111 							}
       
  1112 
       
  1113 							// Validate vertical and get total rowspan
       
  1114 							var lastColSpan = -1;
       
  1115 							for (var x=0; x<rows[0].length; x++) {
       
  1116 								var colRowSpan = 0;
       
  1117 
       
  1118 								for (var y=0; y<rows.length; y++) {
       
  1119 									var sd = getColRowSpan(rows[y][x]);
       
  1120 
       
  1121 									colRowSpan += sd['rowspan'];
       
  1122 
       
  1123 									if (lastColSpan != -1 && sd['colspan'] != lastColSpan) {
       
  1124 										alert("Invalid selection for merge.");
       
  1125 										return true;
       
  1126 									}
       
  1127 
       
  1128 									lastColSpan = sd['colspan'];
       
  1129 								}
       
  1130 
       
  1131 								if (colRowSpan > rowSpan)
       
  1132 									rowSpan = colRowSpan;
       
  1133 
       
  1134 								lastColSpan = -1;
       
  1135 							}
       
  1136 
       
  1137 							// Setup td
       
  1138 							tdElm = rows[0][0];
       
  1139 							tdElm.rowSpan = rowSpan;
       
  1140 							tdElm.colSpan = colSpan;
       
  1141 
       
  1142 							// Merge cells
       
  1143 							for (var y=0; y<rows.length; y++) {
       
  1144 								for (var x=0; x<rows[y].length; x++) {
       
  1145 									var html = rows[y][x].innerHTML;
       
  1146 									var chk = html.replace(/[ \t\r\n]/g, "");
       
  1147 
       
  1148 									if (chk != "<br/>" && chk != "<br>" && chk != '<br mce_bogus="1"/>' && (x+y > 0))
       
  1149 										tdElm.innerHTML += html;
       
  1150 
       
  1151 									// Not current cell
       
  1152 									if (rows[y][x] != tdElm && !rows[y][x]._deleted) {
       
  1153 										var cpos = getCellPos(grid, rows[y][x]);
       
  1154 										var tr = rows[y][x].parentNode;
       
  1155 
       
  1156 										tr.removeChild(rows[y][x]);
       
  1157 										rows[y][x]._deleted = true;
       
  1158 
       
  1159 										// Empty TR, remove it
       
  1160 										if (!tr.hasChildNodes()) {
       
  1161 											tr.parentNode.removeChild(tr);
       
  1162 
       
  1163 											var lastCell = null;
       
  1164 											for (var x=0; cellElm = getCell(grid, cpos.rowindex, x); x++) {
       
  1165 												if (cellElm != lastCell && cellElm.rowSpan > 1)
       
  1166 													cellElm.rowSpan--;
       
  1167 
       
  1168 												lastCell = cellElm;
       
  1169 											}
       
  1170 
       
  1171 											if (tdElm.rowSpan > 1)
       
  1172 												tdElm.rowSpan--;
       
  1173 										}
       
  1174 									}
       
  1175 								}
       
  1176 							}
       
  1177 
       
  1178 							// Remove all but one bogus br
       
  1179 							each(ed.dom.select('br', tdElm), function(e, i) {
       
  1180 								if (i > 0 && ed.dom.getAttrib(e, 'mce_bogus'))
       
  1181 									ed.dom.remove(e);
       
  1182 							});
       
  1183 
       
  1184 							break;
       
  1185 						}
       
  1186 
       
  1187 						tableElm = inst.dom.getParent(inst.selection.getNode(), "table");
       
  1188 						inst.addVisual(tableElm);
       
  1189 						inst.nodeChanged();
       
  1190 					}
       
  1191 
       
  1192 				return true;
       
  1193 			}
       
  1194 
       
  1195 			// Pass to next handler in chain
       
  1196 			return false;
       
  1197 		}
       
  1198 	});
       
  1199 
       
  1200 	// Register plugin
       
  1201 	tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
       
  1202 })();