2014-06-18 01:49:00 +02:00
|
|
|
module("tinymce.Shortcuts", {
|
|
|
|
setupModule: function() {
|
|
|
|
QUnit.stop();
|
|
|
|
|
|
|
|
tinymce.init({
|
|
|
|
selector: "textarea",
|
2014-10-23 04:07:15 +02:00
|
|
|
plugins: wpPlugins,
|
2014-06-18 01:49:00 +02:00
|
|
|
add_unload_trigger: false,
|
|
|
|
disable_nodechange: true,
|
|
|
|
indent: false,
|
|
|
|
skin: false,
|
|
|
|
entities: 'raw',
|
|
|
|
schema: 'html5',
|
|
|
|
init_instance_callback: function(ed) {
|
|
|
|
window.editor = ed;
|
|
|
|
QUnit.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Shortcuts formats', function() {
|
2015-03-10 20:19:56 +01:00
|
|
|
function assertShortcut(shortcut, args, assertState) {
|
|
|
|
var called = false;
|
2014-06-18 01:49:00 +02:00
|
|
|
|
|
|
|
editor.shortcuts.add(shortcut, '', function() {
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
args = tinymce.extend({
|
|
|
|
ctrlKey: false,
|
|
|
|
altKey: false,
|
2015-03-10 20:19:56 +01:00
|
|
|
shiftKey: false,
|
|
|
|
metaKey: false
|
2014-06-18 01:49:00 +02:00
|
|
|
}, args);
|
|
|
|
|
2015-03-10 20:19:56 +01:00
|
|
|
editor.fire('keydown', args);
|
|
|
|
|
|
|
|
if (assertState) {
|
|
|
|
ok(called, 'Shortcut wasn\'t called: ' + shortcut);
|
|
|
|
} else {
|
|
|
|
ok(!called, 'Shortcut was called when it shouldn\'t have been: ' + shortcut);
|
2014-06-18 01:49:00 +02:00
|
|
|
}
|
2015-03-10 20:19:56 +01:00
|
|
|
}
|
2014-06-18 01:49:00 +02:00
|
|
|
|
2015-03-10 20:19:56 +01:00
|
|
|
assertShortcut('ctrl+d', {ctrlKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('ctrl+d', {altKey: true, keyCode: 68}, false);
|
2014-06-18 01:49:00 +02:00
|
|
|
|
2015-03-10 20:19:56 +01:00
|
|
|
if (tinymce.Env.mac) {
|
|
|
|
assertShortcut('meta+d', {metaKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('access+d', {ctrlKey: true, altKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('meta+d', {ctrlKey: true, keyCode: 68}, false);
|
|
|
|
assertShortcut('access+d', {shiftKey: true, altKey: true, keyCode: 68}, false);
|
|
|
|
} else {
|
|
|
|
assertShortcut('meta+d', {ctrlKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('access+d', {shiftKey: true, altKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('meta+d', {metaKey: true, keyCode: 68}, false);
|
|
|
|
assertShortcut('access+d', {ctrlKey: true, altKey: true, keyCode: 68}, false);
|
2014-06-18 01:49:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:19:56 +01:00
|
|
|
assertShortcut('ctrl+shift+d', {ctrlKey: true, shiftKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('ctrl+shift+alt+d', {ctrlKey: true, shiftKey: true, altKey: true, keyCode: 68}, true);
|
|
|
|
assertShortcut('ctrl+221', {ctrlKey: true, keyCode: 221}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Remove', function() {
|
|
|
|
var called = false, eventArgs;
|
|
|
|
|
|
|
|
eventArgs = {
|
|
|
|
ctrlKey: true,
|
|
|
|
keyCode: 68,
|
|
|
|
altKey: false,
|
|
|
|
shiftKey: false,
|
|
|
|
metaKey: false
|
|
|
|
};
|
|
|
|
|
|
|
|
editor.shortcuts.add('ctrl+d', '', function() {
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.fire('keydown', eventArgs);
|
|
|
|
ok(called, 'Shortcut wasn\'t called when it should have been.');
|
|
|
|
|
|
|
|
called = false;
|
|
|
|
editor.shortcuts.remove('ctrl+d');
|
|
|
|
editor.fire('keydown', eventArgs);
|
|
|
|
ok(!called, 'Shortcut was called when it shouldn\'t.');
|
2014-06-18 01:49:00 +02:00
|
|
|
});
|