Skip to content

Commit

Permalink
Backspacing into a table behaves differently depending upon browser t…
Browse files Browse the repository at this point in the history
…ype.

Therefore, disable Backspace when cursor immediately follows a table.
Reported as Atlassian CONFEXT-43.
  • Loading branch information
Andy Gelme authored and Jason Frame committed Mar 7, 2012
1 parent d3cb891 commit 22ee13b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
21 changes: 21 additions & 0 deletions jscripts/tiny_mce/classes/util/Quirks.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -239,8 +239,29 @@
document.body.setAttribute("role", "application"); document.body.setAttribute("role", "application");
} }


/**
* Backspacing into a table behaves differently depending upon browser type.
* Therefore, disable Backspace when cursor immediately follows a table.
*/

function disableBackspaceIntoATable(ed) {
ed.onKeyDown.add(function(ed, e) {
if (e.keyCode === BACKSPACE) {
if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) {
var previousSibling = ed.selection.getNode().previousSibling;
if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
return tinymce.dom.Event.cancel(e);
}
}
}
})
}

tinymce.create('tinymce.util.Quirks', { tinymce.create('tinymce.util.Quirks', {
Quirks: function(ed) { Quirks: function(ed) {
// All browsers
disableBackspaceIntoATable(ed);

// WebKit // WebKit
if (tinymce.isWebKit) { if (tinymce.isWebKit) {
cleanupStylesWhenDeleting(ed); cleanupStylesWhenDeleting(ed);
Expand Down
70 changes: 70 additions & 0 deletions tests/quirk_all.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>All browser types Quirks</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="qunit/connector.js"></script>
<script type="text/javascript" src="qunit/runner.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/tiny_mce_loader.js"></script>
<script type="text/javascript" src="js/dsl/dsl.js"></script>
<script type="text/javascript" language="JavaScript" src="jsrobot/robot.js"></script>
<script>
var editor;

QUnit.config.reorder = false;
QUnit.config.autostart = false;

var BACKSPACE = 0x08;

module("Quirks Tests", {
autostart: false,
setup: function() {
window.queue = new dsl.Queue();
}
});

asyncTest('Backspace into <table> should be disabled', 1, function() {
var testContent = '<table class="mceItemTable" border="1"><tbody><tr><th><p>Table heading</p></th></tr><tr><td><p>Table contents</p></td></tr></tbody></table><h2 id="a">Paragraph Heading</h2>';
editor.setContent(testContent);
var initialContent = editor.getContent();
setSelection('#a', 0);
editor.focus();
robot.type(BACKSPACE, false, function() {
var expected = initialContent;
var actual = editor.getContent();
equal(actual, expected);
start();
}, editor.getBody());
});

function initTinyFunction() {
tinyMCE.init({
mode : "exact",
elements : "elm1",
init_instance_callback : function(ed) {
editor = ed;
}
});
}
</script>
</head>
<body>
<h1 id="qunit-header">All browser types Quirks</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="content">
<textarea id="elm1" name="elm1"></textarea>
<div>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
</div>
</div>
<script>
initWhenTinyAndRobotAreReady(initTinyFunction);
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion tests/tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ provide([
]}, ]},


{"title": "Quirks", "tests": [ {"title": "Quirks", "tests": [
{"title": "All browser types", "url": "quirk_all.html", "jsrobot": true},
{"title": "Firefox", "url": "quirk_firefox.html", "jsrobot": true}, {"title": "Firefox", "url": "quirk_firefox.html", "jsrobot": true},
{"title": "Internet Explorer 8", "url": "quirk_ie8.html", "jsrobot": true}, {"title": "Internet Explorer 8", "url": "quirk_ie8.html", "jsrobot": true},
{"title": "Webkit", "url": "quirk_webkit.html", "jsrobot": true} {"title": "Webkit", "url": "quirk_webkit.html", "jsrobot": true}
]} ]}
] ]
]); ]);

0 comments on commit 22ee13b

Please sign in to comment.