TinyMCE: update to 4.0.18, see #24067

git-svn-id: https://develop.svn.wordpress.org/trunk@27387 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2014-03-04 01:56:57 +00:00
parent 4c10cb2ec5
commit e5bed6707f
38 changed files with 1730 additions and 1200 deletions
@@ -198,7 +198,7 @@ define("tinymce/tableplugin/TableGrid", [
each(table.rows, function(row) {
each(row.cells, function(cell) {
if (dom.hasClass(cell, 'mce-item-selected') || cell == selectedCell.elm) {
if (dom.hasClass(cell, 'mce-item-selected') || (selectedCell && cell == selectedCell.elm)) {
rows.push(row);
return false;
}
@@ -303,11 +303,14 @@ define("tinymce/tableplugin/TableGrid", [
// Restore selection to start position if it still exists
buildGrid();
// Restore the selection to the closest table position
row = grid[Math.min(grid.length - 1, startPos.y)];
if (row) {
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
selection.collapse(true);
// If we have a valid startPos object
if (startPos) {
// Restore the selection to the closest table position
row = grid[Math.min(grid.length - 1, startPos.y)];
if (row) {
selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
selection.collapse(true);
}
}
}
@@ -395,11 +398,13 @@ define("tinymce/tableplugin/TableGrid", [
});
});
// Use selection
startX = startPos.x;
startY = startPos.y;
endX = endPos.x;
endY = endPos.y;
// Use selection, but make sure startPos is valid before accessing
if (startPos) {
startX = startPos.x;
startY = startPos.y;
endX = endPos.x;
endY = endPos.y;
}
}
// Find start/end cells
@@ -478,6 +483,11 @@ define("tinymce/tableplugin/TableGrid", [
}
});
// If posY is undefined there is nothing for us to do here...just return to avoid crashing below
if (posY === undefined) {
return;
}
for (x = 0; x < grid[0].length; x++) {
// Cell not found could be because of an invalid table structure
if (!grid[posY][x]) {
@@ -1622,6 +1632,11 @@ define("tinymce/tableplugin/Plugin", [
cellElm = cellElm || cells[0];
if (!cellElm) {
// If this element is null, return now to avoid crashing.
return;
}
data = {
width: removePxSuffix(dom.getStyle(cellElm, 'width') || dom.getAttrib(cellElm, 'width')),
height: removePxSuffix(dom.getStyle(cellElm, 'height') || dom.getAttrib(cellElm, 'height')),
@@ -1740,6 +1755,10 @@ define("tinymce/tableplugin/Plugin", [
});
rowElm = rows[0];
if (!rowElm) {
// If this element is null, return now to avoid crashing.
return;
}
data = {
height: removePxSuffix(dom.getStyle(rowElm, 'height') || dom.getAttrib(rowElm, 'height')),
@@ -1895,13 +1914,15 @@ define("tinymce/tableplugin/Plugin", [
function generateTableGrid() {
var html = '';
html = '<table role="presentation" class="mce-grid mce-grid-border">';
html = '<table role="grid" class="mce-grid mce-grid-border" aria-readonly="true">';
for (var y = 0; y < 10; y++) {
html += '<tr>';
for (var x = 0; x < 10; x++) {
html += '<td><a href="#" data-mce-index="' + x + ',' + y + '"></a></td>';
html += '<td role="gridcell" tabindex="-1"><a id="mcegrid' + (y * 10 + x) + '" href="#" ' +
'data-mce-x="' + x + '" data-mce-y="' + y + '" ' +
'' + (x + y === 0 ? ' class="mce-active"' : '') + '></a></td>';
}
html += '</tr>';
@@ -1909,77 +1930,145 @@ define("tinymce/tableplugin/Plugin", [
html += '</table>';
html += '<div class="mce-text-center">0 x 0</div>';
html += '<div class="mce-text-center" role="presentation">1 x 1</div>';
return html;
}
function selectGrid(tx, ty, control) {
var table = control.getEl().getElementsByTagName('table')[0];
var rel = control.parent().rel, x, y, focusCell, cell;
if (control.isRtl() || rel == 'tl-tr') {
for (y = 9; y >= 0; y--) {
for (x = 0; x < 10; x++) {
cell = table.rows[y].childNodes[x].firstChild;
editor.dom.toggleClass(
cell,
'mce-active',
x >= tx && y <= ty
);
if (x >= tx && y <= ty) {
focusCell = cell;
}
}
}
tx = 9 - tx;
table.nextSibling.innerHTML = tx + ' x '+ (ty + 1);
} else {
for (y = 0; y < 10; y++) {
for (x = 0; x < 10; x++) {
cell = table.rows[y].childNodes[x].firstChild;
editor.dom.toggleClass(
cell,
'mce-active',
x <= tx && y <= ty
);
if (x <= tx && y <= ty) {
focusCell = cell;
}
}
}
table.nextSibling.innerHTML = (tx + 1) + ' x '+ (ty + 1);
}
return focusCell.parentNode;
}
editor.addMenuItem('inserttable', {
text: 'Insert table',
icon: 'table',
context: 'table',
onhide: function() {
editor.dom.removeClass(this.menu.items()[0].getEl().getElementsByTagName('a'), 'mce-active');
var elements = this.menu.items()[0].getEl().getElementsByTagName('a');
editor.dom.removeClass(elements, 'mce-active');
editor.dom.addClass(elements[0], 'mce-active');
},
menu: [
{
type: 'container',
html: generateTableGrid(),
onPostRender: function() {
this.lastX = this.lastY = 0;
},
onmousemove: function(e) {
var x, y, target = e.target;
var target = e.target, x, y;
if (target.nodeName == 'A') {
var table = editor.dom.getParent(target, 'table');
var pos = target.getAttribute('data-mce-index');
var rel = e.control.parent().rel;
x = parseInt(target.getAttribute('data-mce-x'), 10);
y = parseInt(target.getAttribute('data-mce-y'), 10);
if (pos != this.lastPos) {
pos = pos.split(',');
if (x !== this.lastX || y !== this.lastY) {
selectGrid(x, y, e.control);
pos[0] = parseInt(pos[0], 10);
pos[1] = parseInt(pos[1], 10);
if (e.control.isRtl() || rel == 'tl-tr') {
for (y = 9; y >= 0; y--) {
for (x = 0; x < 10; x++) {
editor.dom.toggleClass(
table.rows[y].childNodes[x].firstChild,
'mce-active',
x >= pos[0] && y <= pos[1]
);
}
}
pos[0] = 9 - pos[0];
table.nextSibling.innerHTML = pos[0] + ' x '+ (pos[1] + 1);
} else {
for (y = 0; y < 10; y++) {
for (x = 0; x < 10; x++) {
editor.dom.toggleClass(
table.rows[y].childNodes[x].firstChild,
'mce-active',
x <= pos[0] && y <= pos[1]
);
}
}
table.nextSibling.innerHTML = (pos[0] + 1) + ' x '+ (pos[1] + 1);
}
this.lastPos = pos;
this.lastX = x;
this.lastY = y;
}
}
},
onclick: function(e) {
if (e.target.nodeName == 'A' && this.lastPos) {
onkeydown: function(e) {
var x = this.lastX, y = this.lastY, isHandled;
switch (e.keyCode) {
case 37: // DOM_VK_LEFT
if (x > 0) {
x--;
isHandled = true;
}
break;
case 39: // DOM_VK_RIGHT
isHandled = true;
if (x < 9) {
x++;
}
break;
case 38: // DOM_VK_UP
isHandled = true;
if (y > 0) {
y--;
}
break;
case 40: // DOM_VK_DOWN
isHandled = true;
if (y < 9) {
y++;
}
break;
}
if (isHandled) {
e.preventDefault();
e.stopPropagation();
insertTable(this.lastPos[0] + 1, this.lastPos[1] + 1);
selectGrid(x, y, e.control).focus();
// TODO: Maybe rework this?
this.parent().cancel(); // Close parent menu as if it was a click
this.lastX = x;
this.lastY = y;
}
},
onclick: function(e) {
if (e.target.nodeName == 'A') {
e.preventDefault();
e.stopPropagation();
this.parent().cancel();
insertTable(this.lastX + 1, this.lastY + 1);
}
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -55,7 +55,7 @@ test("Does not count asterisks, non-word characters", function() {
test("Does not count htmlentities", function() {
expect(1);
editor.setContent('<p>It&rsquo;s my life &ndash; don\'t you forget.</p>');
editor.setContent('<p>It&rsquo;s my life &ndash; &#8211; &#x2013; don\'t you forget.</p>');
var result = editor.plugins.wordcount.getCount();
equal(result, 6);
});
@@ -715,7 +715,7 @@ test('indent/outdent', function() {
test('RemoveFormat', function() {
var t = this;
expect(3);
expect(4);
editor.setContent('<p><em>test</em> <strong>123</strong> <a href="123">123</a> 123</p>');
editor.execCommand('SelectAll');
@@ -731,6 +731,11 @@ test('RemoveFormat', function() {
editor.selection.select(editor.dom.get('x'));
editor.execCommand('RemoveFormat');
equal(editor.getContent(), '<p><em>test</em><span id="x">test 123</span><em><a href="123">123</a> 123</em></p>');
editor.setContent('<p><dfn>dfn tag </dfn> <code>code tag </code> <samp>samp tag</samp> <kbd> kbd tag</kbd> <var> var tag</var> <cite> cite tag</cite> <mark> mark tag</mark> <q> q tag</q></p>');
editor.execCommand('SelectAll');
editor.execCommand('RemoveFormat');
equal(editor.getContent(), '<p>dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag</p>');
});
tinymce.init({
@@ -951,6 +951,14 @@ test('Caret format inside single inline wrapped word', function() {
equal(editor.getContent(), '<p>abc <b><em>123</em></b> 456</p>');
});
test('Caret format inside word before similar format', function() {
editor.setContent('<p>abc 123 <b>456</b></p>');
editor.formatter.register('format', {inline: 'b'});
setSelection('p', 1, 'p', 1);
editor.formatter.apply('format');
equal(editor.getContent(), '<p><b>abc</b> 123 <b>456</b></p>');
});
test('Caret format inside last inline wrapped word', function() {
editor.setContent('<p>abc <em>abc 123</em> 456</p>');
editor.formatter.register('format', {inline: 'b'});
@@ -1112,6 +1120,20 @@ test('Align specified table element with collapsed: false and selection collapse
equal(getContent(), '<table style="float: right;"><tbody><tr><td>a</td></tr></tbody></table>');
});
test('Apply ID format to around existing bookmark node', function() {
editor.getBody().innerHTML = '<p>a<span id="b" data-mce-type="bookmark"></span>b</p>';
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 0);
rng.setEnd(editor.dom.select('p')[0].lastChild, 1);
editor.selection.setRng(rng);
editor.formatter.register('format', {inline: 'span', attributes: {id: 'id'}});
editor.formatter.apply('format');
equal(normalizeHtml(editor.getBody().innerHTML), '<p><span id="id">a<span data-mce-type="bookmark" id="b"></span>b</span></p>');
});
test('Bug #5134 - TinyMCE removes formatting tags in the getContent', function() {
editor.setContent('');
editor.formatter.register('format', {inline : 'strong', toggle: false});
@@ -1159,13 +1181,16 @@ test('Bug #6518 - Apply div blocks to inline editor paragraph', function() {
equal(inlineEditor.getContent(), '<div>a</div><p>b</p>');
});
// WP
var url = document.location.href.substring( 0, document.location.href.lastIndexOf('tinymce/') );
tinymce.init({
selector: "#elm1",
// WP
external_plugins: {
noneditable: url + 'external-plugins/noneditable/plugin.js'
},
// WP end
add_unload_trigger: false,
indent: false,
theme_advanced_styles: 'test1=test1;test2=test2',
@@ -1189,9 +1214,11 @@ tinymce.init({
tinymce.init({
selector: "#elm2",
inline: true,
// WP
external_plugins: {
noneditable: url + 'external-plugins/noneditable/plugin.js'
},
// WP end
add_unload_trigger: false,
indent: false,
theme_advanced_styles: 'test1=test1;test2=test2',
@@ -227,14 +227,17 @@ tinymce.init({
}
});
// WP
var url = document.location.href.substring( 0, document.location.href.lastIndexOf('tinymce/') );
tinymce.init({
selector: "#elm2",
inline: true,
// WP
external_plugins: {
noneditable: url + 'external-plugins/noneditable/plugin.js'
},
// WP end
add_unload_trigger: false,
indent: false,
theme_advanced_styles: 'test1=test1;test2=test2',
@@ -360,14 +360,17 @@ test('Remove format bug 1', function() {
});
*/
// WP
var url = document.location.href.substring( 0, document.location.href.lastIndexOf('tinymce/') );
tinymce.init({
mode : "exact",
elements : "elm1",
// WP
external_plugins: {
noneditable: url + 'external-plugins/noneditable/plugin.js'
},
// WP end
indent : false,
add_unload_trigger : false,
theme_advanced_styles : 'test1=test1;test2=test2',
+7 -2
View File
@@ -159,8 +159,13 @@ test('Undo added when typing and losing focus', function() {
editor.setContent("<p>some text</p>");
setSelection('p', 4, 'p', 9);
type('\b');
window.focus();
editor.dom.fire(editor.getBody(), 'focusout');
// Move focus to an input element
var input = document.createElement('input');
document.body.appendChild(input);
input.focus();
input.parentNode.removeChild(input);
editor.execCommand('FormatBlock', false, 'h1');
editor.undoManager.undo();
equal(editor.getContent(), "<p>some</p>");
@@ -803,6 +803,76 @@ if (!tinymce.isIE) {
equal(rng.endContainer.nodeName, '#text');
equal(rng.endOffset, 1);
});
test('normalize caret after trailing BR', function() {
var rng;
editor.setContent('<p>a<br /></p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild, 2);
rng.setEnd(editor.getBody().firstChild, 2);
editor.selection.setRng(rng);
editor.selection.normalize();
rng = editor.selection.getRng(true);
equal(rng.startContainer.nodeName, '#text', 'startContainer node name');
equal(rng.startOffset, 1, 'startContainer offset');
equal(rng.endContainer.nodeName, '#text', 'endContainer node name');
equal(rng.endOffset, 1, 'endOffset offset');
});
test('normalize caret after bogus block BR', function() {
var rng;
editor.setContent('<p><br /></p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild, 1);
rng.setEnd(editor.getBody().firstChild, 1);
editor.selection.setRng(rng);
editor.selection.normalize();
rng = editor.selection.getRng(true);
equal(rng.startContainer.nodeName, 'P', 'startContainer node name');
equal(rng.startOffset, 0, 'startContainer offset');
equal(rng.endContainer.nodeName, 'P', 'endContainer node name');
equal(rng.endOffset, 0, 'endOffset offset');
});
/*
test('normalize caret after last BR in block', function() {
var rng;
editor.setContent('<p><br /><br /></p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild, 2);
rng.setEnd(editor.getBody().firstChild, 2);
editor.selection.setRng(rng);
editor.selection.normalize();
rng = editor.selection.getRng(true);
equal(rng.startContainer.nodeName, 'P', 'startContainer node name');
equal(rng.startOffset, 1, 'startContainer offset');
equal(rng.endContainer.nodeName, 'P', 'endContainer node name');
equal(rng.endOffset, 1, 'endOffset offset');
});
*/
test('normalize caret after double BR', function() {
var rng;
editor.setContent('<p>a<br /><br /></p>');
rng = editor.dom.createRng();
rng.setStart(editor.getBody().firstChild, 3);
rng.setEnd(editor.getBody().firstChild, 3);
editor.selection.setRng(rng);
editor.selection.normalize();
rng = editor.selection.getRng(true);
equal(rng.startContainer.nodeName, 'P', 'startContainer node name');
equal(rng.startOffset, 3, 'startContainer offset');
equal(rng.endContainer.nodeName, 'P', 'endContainer node name');
equal(rng.endOffset, 3, 'endOffset offset');
});
}
test('custom elements', function() {
+2 -2
View File
@@ -166,13 +166,13 @@ test('getBlockElements', function() {
var schema = new tinymce.html.Schema();
deepEqual(schema.getBlockElements(), {
ASIDE: {}, HGROUP: {}, SECTION: {}, ARTICLE: {}, FOOTER: {}, HEADER: {}, SAMP: {},
ASIDE: {}, HGROUP: {}, SECTION: {}, ARTICLE: {}, FOOTER: {}, HEADER: {},
ISINDEX: {}, MENU: {}, NOSCRIPT: {}, FIELDSET: {}, DIR: {}, DD: {}, DT: {},
DL: {}, CENTER: {}, BLOCKQUOTE: {}, CAPTION: {}, UL: {}, OL: {}, LI: {},
TD: {}, TR: {}, TH: {}, TFOOT: {}, THEAD: {}, TBODY: {}, TABLE: {}, FORM: {},
PRE: {}, ADDRESS: {}, DIV: {}, P: {}, HR: {}, H6: {}, H5: {}, H4: {}, H3: {},
H2: {}, H1: {}, NAV: {}, FIGURE: {}, DATALIST: {}, OPTGROUP: {}, OPTION: {}, SELECT: {},
aside: {}, hgroup: {}, section: {}, article: {}, footer: {}, header: {}, samp: {},
aside: {}, hgroup: {}, section: {}, article: {}, footer: {}, header: {},
isindex: {}, menu: {}, noscript: {}, fieldset: {}, dir: {}, dd: {}, dt: {}, dl: {}, center: {},
blockquote: {}, caption: {}, ul: {}, ol: {}, li: {}, td: {}, tr: {}, th: {}, tfoot: {}, thead: {},
tbody: {}, table: {}, form: {}, pre: {}, address: {}, div: {}, p: {}, hr: {}, h6: {},
@@ -8,7 +8,7 @@
<script src="../../js/utils.js"></script>
<script src="../../js/tinymce_loader.js"></script>
<script src="../../js/jsrobot/robot.js"></script>
<script src="../../plugins/js/dsl.js"></script>
<script src="../../js/dsl/dsl.js"></script>
<script>
var editor;
@@ -98,13 +98,16 @@
});
}
// WP
var url = document.location.href.substring( 0, document.location.href.lastIndexOf('tinymce/') );
tinymce.init({
mode : "exact",
// WP
external_plugins: {
noneditable: url + 'external-plugins/table/plugin.js'
table: url + 'external-plugins/table/plugin.js'
},
// WP end
elements : "elm1",
indent: false,
init_instance_callback : function(ed) {