Upgrade TinyMCE to 3.2.7. Fixes bug #10993.

This commit is contained in:
Colin Kuskie 2009-10-16 13:50:14 -07:00
parent dae7215922
commit a2a2bac440
140 changed files with 8023 additions and 3591 deletions

View file

@ -5,9 +5,9 @@
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script type="text/javascript" src="../../utils/mctabs.js"></script>
<script type="text/javascript" src="../../utils/form_utils.js"></script>
<script type="text/javascript" src="../../utils/editable_selects.js"></script>
<script type="text/javascript" src="js/cell.js"></script>
<link href="css/cell.css" rel="stylesheet" type="text/css" />
<base target="_self" />
</head>
<body id="tablecell" style="display: none">
<form onsubmit="updateAction();return false;" action="#">
@ -79,7 +79,7 @@
<tr id="styleSelectRow">
<td><label for="class">{#class_name}</label></td>
<td colspan="3">
<select id="class" name="class">
<select id="class" name="class" class="mceEditableSelect">
<option value="" selected="selected">{#not_set}</option>
</select>
</td>

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
/**
* $Id: editor_plugin_src.js 691 2008-03-09 19:58:20Z spocke $
* $Id: editor_plugin_src.js 1209 2009-08-20 12:35:10Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
@ -8,6 +8,20 @@
(function() {
var each = tinymce.each;
// Checks if the selection/caret is at the start of the specified block element
function isAtStart(rng, par) {
var doc = par.ownerDocument, rng2 = doc.createRange(), elm;
rng2.setStartBefore(par);
rng2.setEnd(rng.endContainer, rng.endOffset);
elm = doc.createElement('body');
elm.appendChild(rng2.cloneContents());
// Check for text characters of other elements that should be treated as content
return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0;
};
tinymce.create('tinymce.plugins.TablePlugin', {
init : function(ed, url) {
var t = this;
@ -33,13 +47,98 @@
ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
});
if (ed.getParam('inline_styles')) {
// Force move of attribs to styles in strict mode
ed.onPreProcess.add(function(ed, o) {
var dom = ed.dom;
each(dom.select('table', o.node), function(n) {
var v;
if (v = dom.getAttrib(n, 'width')) {
dom.setStyle(n, 'width', v);
dom.setAttrib(n, 'width');
}
if (v = dom.getAttrib(n, 'height')) {
dom.setStyle(n, 'height', v);
dom.setAttrib(n, 'height');
}
});
});
}
ed.onInit.add(function() {
// Fixes an issue on Gecko where it's impossible to place the caret behind a table
// This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
if (!tinymce.isIE && ed.getParam('forced_root_block')) {
function fixTableCaretPos() {
var last = ed.getBody().lastChild;
if (last && last.nodeName == 'TABLE')
ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
};
// Fixes an bug where it's impossible to place the caret before a table in Gecko
// this fix solves it by detecting when the caret is at the beginning of such a table
// and then manually moves the caret infront of the table
if (tinymce.isGecko) {
ed.onKeyDown.add(function(ed, e) {
var rng, table, dom = ed.dom;
// On gecko it's not possible to place the caret before a table
if (e.keyCode == 37 || e.keyCode == 38) {
rng = ed.selection.getRng();
table = dom.getParent(rng.startContainer, 'table');
if (table && ed.getBody().firstChild == table) {
if (isAtStart(rng, table)) {
rng = dom.createRng();
rng.setStartBefore(table);
rng.setEndBefore(table);
ed.selection.setRng(rng);
e.preventDefault();
}
}
}
});
}
ed.onKeyUp.add(fixTableCaretPos);
ed.onSetContent.add(fixTableCaretPos);
ed.onVisualAid.add(fixTableCaretPos);
ed.onPreProcess.add(function(ed, o) {
var last = o.node.lastChild;
if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
ed.dom.remove(last);
});
fixTableCaretPos();
}
if (ed && ed.plugins.contextmenu) {
ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
var sm;
var sm, se = ed.selection, el = se.getNode() || ed.getBody();
if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) {
m.removeAll();
if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
m.addSeparator();
}
if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
m.addSeparator();
}
m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true, value : {action : 'insert'}});
m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable', ui : true});
m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete', ui : true});
@ -74,30 +173,34 @@
}
});
// Block delete on gecko inside TD:s. Gecko is removing table elements and then produces incorrect tables
// The backspace key also removed TD:s but this one can not be blocked
if (tinymce.isGecko) {
ed.onKeyPress.add(function(ed, e) {
var n;
if (e.keyCode == 46) {
n = ed.dom.getParent(ed.selection.getNode(), 'TD,TH');
if (n && (!n.hasChildNodes() || (n.childNodes.length == 1 && n.firstChild.nodeName == 'BR')))
tinymce.dom.Event.cancel(e);
}
});
}
// Add undo level when new rows are created using the tab key
ed.onKeyDown.add(function(ed, e) {
if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE'))
if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE')) {
if (!tinymce.isGecko && !tinymce.isOpera) {
tinyMCE.execInstanceCommand(ed.editorId, "mceTableMoveToNextRow", true);
return tinymce.dom.Event.cancel(e);
}
ed.undoManager.add();
}
});
// Select whole table is a table border is clicked
if (!tinymce.isIE) {
if (ed.getParam('table_selection', true)) {
ed.onClick.add(function(ed, e) {
e = e.target;
if (e.nodeName === 'TABLE')
ed.selection.select(e);
});
}
}
ed.onNodeChange.add(function(ed, cm, n) {
var p = ed.dom.getParent(n, 'td,th,caption');
cm.setActive('table', !!p);
cm.setActive('table', n.nodeName === 'TABLE' || !!p);
if (p && p.nodeName === 'CAPTION')
p = null;
@ -114,6 +217,14 @@
cm.setDisabled('split_cells', !p || (parseInt(ed.dom.getAttrib(p, 'colspan', '1')) < 2 && parseInt(ed.dom.getAttrib(p, 'rowspan', '1')) < 2));
cm.setDisabled('merge_cells', !p);
});
// Padd empty table cells
if (!tinymce.isIE) {
ed.onBeforeSetContent.add(function(ed, o) {
if (o.initial)
o.content = o.content.replace(/<(td|th)([^>]+|)>\s*<\/(td|th)>/g, tinymce.isOpera ? '<$1$2>&nbsp;</$1>' : '<$1$2><br mce_bogus="1" /></$1>');
});
}
},
execCommand : function(cmd, ui, val) {
@ -121,6 +232,7 @@
// Is table command
switch (cmd) {
case "mceTableMoveToNextRow":
case "mceInsertTable":
case "mceTableRowProps":
case "mceTableCellProps":
@ -246,6 +358,19 @@
return null;
}
function getNextCell(table, cell) {
var cells = [], x = 0, i, j, cell, nextCell;
for (i = 0; i < table.rows.length; i++)
for (j = 0; j < table.rows[i].cells.length; j++, x++)
cells[x] = table.rows[i].cells[j];
for (i = 0; i < cells.length; i++)
if (cells[i] == cell)
if (nextCell = cells[i+1])
return nextCell;
}
function getTableGrid(table) {
var grid = [], rows = table.rows, x, y, td, sd, xstart, x2, y2;
@ -413,6 +538,19 @@
// Handle commands
switch (command) {
case "mceTableMoveToNextRow":
var nextCell = getNextCell(tableElm, tdElm);
if (!nextCell) {
inst.execCommand("mceTableInsertRowAfter", tdElm);
nextCell = getNextCell(tableElm, tdElm);
}
inst.selection.select(nextCell);
inst.selection.collapse(true);
return true;
case "mceTableRowProps":
if (trElm == null)
return true;
@ -625,7 +763,7 @@
var cpos = getCellPos(grid, tdElm);
// Only one row, remove whole table
if (grid.length == 1) {
if (grid.length == 1 && tableElm.nodeName == 'TBODY') {
inst.dom.remove(inst.dom.getParent(tableElm, "table"));
return true;
}
@ -677,7 +815,7 @@
if (!trElm || !tdElm)
return true;
var grid = getTableGrid(tableElm);
var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
var cpos = getCellPos(grid, tdElm);
var lastTDElm = null;
@ -708,7 +846,7 @@
if (!trElm || !tdElm)
return true;
var grid = getTableGrid(tableElm);
var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
var cpos = getCellPos(grid, tdElm);
var lastTDElm = null;
@ -748,7 +886,7 @@
var lastTDElm = null;
// Only one col, remove whole table
if (grid.length > 1 && grid[0].length <= 1) {
if ((grid.length > 1 && grid[0].length <= 1) && tableElm.nodeName == 'TBODY') {
inst.dom.remove(inst.dom.getParent(tableElm, "table"));
return true;
}
@ -886,7 +1024,7 @@
if (!tdElm)
break;
if (tdElm.nodeName == "TD")
if (tdElm.nodeName == "TD" || tdElm.nodeName == "TH")
cells[cells.length] = tdElm;
}

View file

@ -32,6 +32,8 @@ function init() {
// Setup form
addClassesToList('class', 'table_cell_styles');
TinyMCE_EditableSelects.init();
formObj.bordercolor.value = bordercolor;
formObj.bgcolor.value = bgcolor;
formObj.backgroundimage.value = backgroundimage;
@ -42,7 +44,7 @@ function init() {
formObj.style.value = ed.dom.serializeStyle(st);
selectByValue(formObj, 'align', align);
selectByValue(formObj, 'valign', valign);
selectByValue(formObj, 'class', className);
selectByValue(formObj, 'class', className, true, true);
selectByValue(formObj, 'celltype', celltype);
selectByValue(formObj, 'dir', dir);
selectByValue(formObj, 'scope', scope);
@ -56,12 +58,13 @@ function init() {
}
function updateAction() {
var el = ed.selection.getNode();
var inst = ed;
var tdElm = ed.dom.getParent(el, "td,th");
var trElm = ed.dom.getParent(el, "tr");
var tableElm = ed.dom.getParent(el, "table");
var formObj = document.forms[0];
var el, inst = ed, tdElm, trElm, tableElm, formObj = document.forms[0];
tinyMCEPopup.restoreSelection();
el = ed.selection.getNode();
tdElm = ed.dom.getParent(el, "td,th");
trElm = ed.dom.getParent(el, "tr");
tableElm = ed.dom.getParent(el, "table");
ed.execCommand('mceBeginUndoLevel');
@ -70,14 +73,24 @@ function updateAction() {
var celltype = getSelectValue(formObj, 'celltype');
var scope = getSelectValue(formObj, 'scope');
if (ed.getParam("accessibility_warnings")) {
if (celltype == "th" && scope == "")
var answer = confirm(ed.getLang('table_dlg.missing_scope', '', true));
else
var answer = true;
function doUpdate(s) {
if (s) {
updateCell(tdElm);
if (!answer)
return;
ed.addVisual();
ed.nodeChanged();
inst.execCommand('mceEndUndoLevel');
tinyMCEPopup.close();
}
};
if (ed.getParam("accessibility_warnings", 1)) {
if (celltype == "th" && scope == "")
tinyMCEPopup.confirm(ed.getLang('table_dlg.missing_scope', '', true), doUpdate);
else
doUpdate(1);
return;
}
updateCell(tdElm);

View file

@ -6,14 +6,16 @@ function init() {
tinyMCEPopup.resizeToInnerSize();
f.numcols.value = tinyMCEPopup.getWindowArg('numcols', 1);
f.numrows.value = tinyMCEPopup.getWindowArg('numcols', 1);
f.numrows.value = tinyMCEPopup.getWindowArg('numrows', 1);
}
function mergeCells() {
var args = [], f = document.forms[0];
tinyMCEPopup.restoreSelection();
if (!AutoValidator.validate(f)) {
alert(tinyMCEPopup.getLang('invalid_data'));
tinyMCEPopup.alert(tinyMCEPopup.getLang('invalid_data'));
return false;
}

View file

@ -26,6 +26,8 @@ function init() {
// Setup form
addClassesToList('class', 'table_row_styles');
TinyMCE_EditableSelects.init();
formObj.bgcolor.value = bgcolor;
formObj.backgroundimage.value = backgroundimage;
formObj.height.value = height;
@ -34,7 +36,7 @@ function init() {
formObj.style.value = dom.serializeStyle(st);
selectByValue(formObj, 'align', align);
selectByValue(formObj, 'valign', valign);
selectByValue(formObj, 'class', className);
selectByValue(formObj, 'class', className, true, true);
selectByValue(formObj, 'rowtype', rowtype);
selectByValue(formObj, 'dir', dir);
@ -46,13 +48,13 @@ function init() {
}
function updateAction() {
var inst = tinyMCEPopup.editor;
var dom = inst.dom;
var trElm = dom.getParent(inst.selection.getNode(), "tr");
var tableElm = dom.getParent(inst.selection.getNode(), "table");
var formObj = document.forms[0];
var inst = tinyMCEPopup.editor, dom = inst.dom, trElm, tableElm, formObj = document.forms[0];
var action = getSelectValue(formObj, 'action');
tinyMCEPopup.restoreSelection();
trElm = dom.getParent(inst.selection.getNode(), "tr");
tableElm = dom.getParent(inst.selection.getNode(), "table");
inst.execCommand('mceBeginUndoLevel');
switch (action) {

View file

@ -9,8 +9,10 @@ function insertTable() {
var html = '', capEl, elm;
var cellLimit, rowLimit, colLimit;
tinyMCEPopup.restoreSelection();
if (!AutoValidator.validate(formObj)) {
alert(inst.getLang('invalid_data'));
tinyMCEPopup.alert(inst.getLang('invalid_data'));
return false;
}
@ -22,14 +24,14 @@ function insertTable() {
border = formObj.elements['border'].value != "" ? formObj.elements['border'].value : 0;
cellpadding = formObj.elements['cellpadding'].value != "" ? formObj.elements['cellpadding'].value : "";
cellspacing = formObj.elements['cellspacing'].value != "" ? formObj.elements['cellspacing'].value : "";
align = formObj.elements['align'].options[formObj.elements['align'].selectedIndex].value;
frame = formObj.elements['frame'].options[formObj.elements['frame'].selectedIndex].value;
rules = formObj.elements['rules'].options[formObj.elements['rules'].selectedIndex].value;
align = getSelectValue(formObj, "align");
frame = getSelectValue(formObj, "tframe");
rules = getSelectValue(formObj, "rules");
width = formObj.elements['width'].value;
height = formObj.elements['height'].value;
bordercolor = formObj.elements['bordercolor'].value;
bgcolor = formObj.elements['bgcolor'].value;
className = formObj.elements['class'].options[formObj.elements['class'].selectedIndex].value;
className = getSelectValue(formObj, "class");
id = formObj.elements['id'].value;
summary = formObj.elements['summary'].value;
style = formObj.elements['style'].value;
@ -44,13 +46,13 @@ function insertTable() {
// Validate table size
if (colLimit && cols > colLimit) {
alert(inst.getLang('table_col_limit', '', true, {cols : colLimit}));
tinyMCEPopup.alert(inst.getLang('table_dlg.col_limit').replace(/\{\$cols\}/g, colLimit));
return false;
} else if (rowLimit && rows > rowLimit) {
alert(inst.getLang('table_row_limit', '', true, {rows : rowLimit}));
tinyMCEPopup.alert(inst.getLang('table_dlg.row_limit').replace(/\{\$rows\}/g, rowLimit));
return false;
} else if (cellLimit && cols * rows > cellLimit) {
alert(inst.getLang('table_cell_limit', '', true, {cells : cellLimit}));
tinyMCEPopup.alert(inst.getLang('table_dlg.cell_limit').replace(/\{\$cells\}/g, cellLimit));
return false;
}
@ -85,7 +87,7 @@ function insertTable() {
elm.insertBefore(capEl, elm.firstChild);
}
if (width && /(pt|em|cm)$/.test(width)) {
if (width && inst.settings.inline_styles) {
dom.setStyle(elm, 'width', width);
dom.setAttrib(elm, 'width', '');
} else {
@ -98,10 +100,13 @@ function insertTable() {
dom.setAttrib(elm, 'bgColor', '');
dom.setAttrib(elm, 'background', '');
if (height) {
if (height && inst.settings.inline_styles) {
dom.setStyle(elm, 'height', height);
dom.setAttrib(elm, 'height', '');
}
} else {
dom.setAttrib(elm, 'height', height, true);
dom.setStyle(elm, 'height', '');
}
if (background != '')
elm.style.backgroundImage = "url('" + background + "')";
@ -147,10 +152,14 @@ function insertTable() {
html += makeAttrib('cellpadding', cellpadding);
html += makeAttrib('cellspacing', cellspacing);
if (width && /(pt|em|cm)$/.test(width)) {
if (width && inst.settings.inline_styles) {
if (style)
style += '; ';
// Force px
if (/^[0-9\.]+$/.test(width))
width += 'px';
style += 'width: ' + width;
} else
html += makeAttrib('width', width);
@ -198,7 +207,30 @@ function insertTable() {
html += "</table>";
inst.execCommand('mceBeginUndoLevel');
inst.execCommand('mceInsertContent', false, html);
// Move table
if (inst.settings.fix_table_elements) {
var bm = inst.selection.getBookmark(), patt = '';
inst.execCommand('mceInsertContent', false, '<br class="_mce_marker" />');
tinymce.each('h1,h2,h3,h4,h5,h6,p'.split(','), function(n) {
if (patt)
patt += ',';
patt += n + ' ._mce_marker';
});
tinymce.each(inst.dom.select(patt), function(n) {
inst.dom.split(inst.dom.getParent(n, 'h1,h2,h3,h4,h5,h6,p'), n);
});
dom.setOuterHTML(dom.select('._mce_marker')[0], html);
inst.selection.moveToBookmark(bm);
} else
inst.execCommand('mceInsertContent', false, html);
inst.addVisual();
inst.execCommand('mceEndUndoLevel');
@ -286,12 +318,13 @@ function init() {
}
addClassesToList('class', "table_styles");
TinyMCE_EditableSelects.init();
// Update form
selectByValue(formObj, 'align', align);
selectByValue(formObj, 'frame', frame);
selectByValue(formObj, 'tframe', frame);
selectByValue(formObj, 'rules', rules);
selectByValue(formObj, 'class', className);
selectByValue(formObj, 'class', className, true, true);
formObj.cols.value = cols;
formObj.rows.value = rows;
formObj.border.value = border;

View file

@ -6,9 +6,8 @@
<script type="text/javascript" src="../../utils/mctabs.js"></script>
<script type="text/javascript" src="../../utils/validate.js"></script>
<script type="text/javascript" src="js/merge_cells.js"></script>
<base target="_self" />
</head>
<body style="margin: 8px" style="display: none">
<body style="margin: 8px">
<form onsubmit="mergeCells();return false;" action="#">
<fieldset>
<legend>{#table_dlg.merge_cells_title}</legend>

View file

@ -5,12 +5,12 @@
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script type="text/javascript" src="../../utils/mctabs.js"></script>
<script type="text/javascript" src="../../utils/form_utils.js"></script>
<script type="text/javascript" src="../../utils/editable_selects.js"></script>
<script type="text/javascript" src="js/row.js"></script>
<link href="css/row.css" rel="stylesheet" type="text/css" />
<base target="_self" />
</head>
<body id="tablerow" style="display: none">
<form onsubmit="updateAction();return false;">
<form onsubmit="updateAction();return false;" action="#">
<div class="tabs">
<ul>
<li id="general_tab" class="current"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#table_dlg.general_tab}</a></span></li>
@ -62,7 +62,7 @@
<tr id="styleSelectRow">
<td><label for="class">{#class_name}</label></td>
<td class="col2">
<select id="class" name="class">
<select id="class" name="class" class="mceEditableSelect">
<option value="" selected="selected">{#not_set}</option>
</select>
</td>

View file

@ -6,9 +6,9 @@
<script type="text/javascript" src="../../utils/mctabs.js"></script>
<script type="text/javascript" src="../../utils/form_utils.js"></script>
<script type="text/javascript" src="../../utils/validate.js"></script>
<script type="text/javascript" src="../../utils/editable_selects.js"></script>
<script type="text/javascript" src="js/table.js"></script>
<link href="css/table.css" rel="stylesheet" type="text/css" />
<base target="_self" />
</head>
<body id="table" style="display: none">
<form onsubmit="insertTable();return false;" action="#">
@ -56,8 +56,8 @@
<tr id="styleSelectRow">
<td><label id="classlabel" for="class">{#class_name}</label></td>
<td colspan="3">
<select id="class" name="class">
<option value="" selected>{#not_set}</option>
<select id="class" name="class" class="mceEditableSelect">
<option value="" selected="selected">{#not_set}</option>
</select></td>
</tr>
<tr>
@ -108,24 +108,10 @@
</tr>
<tr>
<td class="column1"><label for="frame">{#table_dlg.frame}</label></td>
<td class="column1"><label for="tframe">{#table_dlg.frame}</label></td>
<td>
<select id="frame" name="frame" class="advfield">
<option value="">{#not_set}</option>
<option value="none">{#table_dlg.frame_none}</option>
<option value="groups">{#table_dlg.frame_groups}</option>
<option value="rows">{#table_dlg.frame_rows}</option>
<option value="cols">{#table_dlg.frame_cols}</option>
<option value="all">{#table_dlg.frame_all}</option>
</select>
</td>
</tr>
<tr>
<td class="column1"><label for="rules">{#table_dlg.rules}</label></td>
<td>
<select id="rules" name="rules" class="advfield">
<option value="">{#not_set}</option>
<select id="tframe" name="tframe" class="advfield">
<option value="">{#not_set}</option>
<option value="void">{#table_dlg.rules_void}</option>
<option value="above">{#table_dlg.rules_above}</option>
<option value="below">{#table_dlg.rules_below}</option>
@ -135,6 +121,20 @@
<option value="vsides">{#table_dlg.rules_vsides}</option>
<option value="box">{#table_dlg.rules_box}</option>
<option value="border">{#table_dlg.rules_border}</option>
</select>
</td>
</tr>
<tr>
<td class="column1"><label for="rules">{#table_dlg.rules}</label></td>
<td>
<select id="rules" name="rules" class="advfield">
<option value="">{#not_set}</option>
<option value="none">{#table_dlg.frame_none}</option>
<option value="groups">{#table_dlg.frame_groups}</option>
<option value="rows">{#table_dlg.frame_rows}</option>
<option value="cols">{#table_dlg.frame_cols}</option>
<option value="all">{#table_dlg.frame_all}</option>
</select>
</td>
</tr>