我正在使用TinyMCE4来包装textarea以获得一些基本的文本编辑器功能。但是,TinyMCE4具有默认快捷键。我需要禁用这些快捷键,因为它们会干扰我正在创建的系统上的某些全局热键。
有谁知道如何禁用TinyMCE4中的所有热键?理想情况下,我希望它根本不处理它们,所以我可以让父级别的代码拦截热键。
主要问题是我有ctrl + a被映射以打开一个模态窗口但是TinyMCE强制它被全部选中(是的我知道ctrl + a是标准的,这不是我的选择哈哈)。
对于我的javascript库,我使用KnockoutJS绑定(也是一个要求)加载所有内容。请参阅下面的源代码,了解我当前的尝试,尝试删除它们发生在.on('init')函数中。
感谢。
`//This gets called and works properly. In my code it contains all my custom bindings.
function RegisterBindings() {
ko.bindingHandlers.tinymce = GetTinyMCEBinding();
ko.virtualElements.allowedBindings['tinymce'] = true;
ko.expressionRewriting._twoWayBindings['tinymce'] = true;
}
//Get the binding for the TinyMCE WYSWIG Library
function GetTinyMCEBinding() {
var binding, cache, cacheInstance, configure, writeValueToProperty;
cache = "";
cacheInstance = null;
binding = {
after: ["attr", "value"],
defaults: {},
extensions: {},
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var $element, ext, options, settings;
$element = $(element);
options = (allBindings.has("tinymceConfig") ? allBindings.get("tinymceConfig") : null);
ext = (allBindings.has("tinymceExtensions") ? allBindings.get("tinymceExtensions") : []);
settings = configure(binding["defaults"], ext, options, arguments);
$element[$element.is('input, textarea') ? 'text' : 'html'](ko.unwrap(valueAccessor()));
setTimeout((function () {
$element.tinymce(settings);
}), 0);
ko.utils["domNodeDisposal"].addDisposeCallback(element, function () {
var tinymce;
tinymce = $(element).tinymce();
if (tinymce) {
tinymce.remove();
}
if (tinymce === cacheInstance) {
cacheInstance = null;
}
});
return {
controlsDescendantBindings: true
};
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var tinymce, value;
tinymce = $(element).tinymce();
value = ko.unwrap(valueAccessor());
if (value === null) {
value = "";
}
if (tinymce && !(cacheInstance === tinymce && cache === value)) {
cacheInstance = tinymce;
cache = value;
if (tinymce.getContent() !== value) {
tinymce.setContent(value);
}
}
}
};
writeValueToProperty = function (property, allBindings, key, value, checkIfDifferent) {
var propWriters;
if (!property || !ko.isObservable(property)) {
propWriters = allBindings.get('_ko_property_writers');
if (propWriters && propWriters[key]) {
return propWriters[key](value);
}
} else if (ko.isWriteableObservable(property) && (!checkIfDifferent || property.peek() !== value)) {
return property(value);
}
};
configure = function (defaults, extensions, options, args) {
var applyChange, config, setup, applyShortcuts;
config = $.extend(true, {}, defaults);
if (options) {
ko.utils.objectForEach(options, function (property) {
if (Object.prototype.toString.call(options[property]) === "[object Array]") {
if (!config[property]) {
config[property] = [];
}
options[property] = ko.utils.arrayGetDistinctValues(config[property].concat(options[property]));
}
});
$.extend(true, config, options);
}
if (!config["plugins"]) {
config["plugins"] = ["paste"];
} else {
if ($.inArray("paste", config["plugins"]) === -1) {
config["plugins"].push("paste");
}
}
applyChange = function (editor) {
editor.on("change keyup nodechange", function (e) {
return setTimeout((function () {
var name, value;
value = editor.getContent();
cache = value;
cacheInstance = editor;
writeValueToProperty(args[1](), args[2], "tinymce", value);
for (name in extensions) {
if (extensions.hasOwnProperty(name)) {
binding["extensions"][extensions[name]](editor, e, args[2], args[4]);
}
}
}), 0);
});
editor.on("init", function (e) {
return setTimeout((function () {
//FORCE REMOVAL OF TINYMCE SHORTCUT KEYS TO PREVENT INTERFERENCE WITH OUT HOTKEYS
// Note these lists may not be complete & that other tinymce plugins can add their own shortcuts anyway.
var ctrls = ['a', 'b', 'i', 'u', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'z', 'y,ctrl+shift+z', 's', 'k', 'Alt+F', 'P'];
var modKeys = ['c', 'r', 'l', 'j', 'q', 'u', 'o', 'n', 's', 'm', 'z', 't', 'd', 'h', 'o', 'x', 'a', 'w'];
// Overwrite shortcuts with no-op function. Key sequences will still be captured.
for (var i = 0; i < ctrls.length; i++) {
var sCutMeta = 'meta+' + ctrls[i];
var sCutCtrl = 'ctrl+' + ctrls[i];
editor.addShortcut(sCutMeta, '', function () { });
editor.addShortcut(sCutCtrl, '', function () { });
}
for (var i = 0; i < modKeys.length; i++) {
var sCutAccess = 'access+' + modKeys[i];
var sCutAltShift = 'alt+shift+' + modKeys[i];
editor.addShortcut(sCutAltShift, '', function () { });
editor.addShortcut(sCutAccess, '', function () { });
}
}), 0);
});
};
if (typeof config["setup"] === "function") {
setup = config["setup"];
config["setup"] = function (editor) {
setup(editor);
applyChange(editor);
applyShortcuts(editor);
};
} else {
config["setup"] = applyChange;
}
return config;
};
return binding;
}
`