上次我添加keybord快捷方式时,它使用的是jQuery。看看jquery.hotkeys 使用简单的一行代码启用键盘快捷键的插件:
$(document).bind(\'keydown\', \'ctrl+a\', fn);
update
如果要检查TinyMCE编辑器是否处于活动状态,并且它是否具有选定的文本,则需要以下功能:
function isTinyMCEactive(){ //check if editor is active
is_tinyMCE_active = false;
if (typeof(tinyMCE) != "undefined") {
if (tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() != false) {
is_tinyMCE_active = true;
}
}
return is_tinyMCE_active;
}
function tinyMCEhotkeys(tag){
if (isTinyMCEactive()){
var selected_content = \'\';
selected_content = tinyMCE.activeEditor.selection.getContent();
if (selected_content != \'\' || selected_content != null){ //check if editor has selection
tinyMCE.activeEditor.execCommand("mceInsertContent", 0, \'<\' + tag + \'>\' + selected_content + \'</\' + tag + \'>\');
}
}
}
现在,一旦具备了这些功能,剩下的就很容易了:
$(document).bind(\'keydown\', \'ctrl+1\', tinyMCEhotkeys(\'h1\'));
$(document).bind(\'keydown\', \'ctrl+2\', tinyMCEhotkeys(\'h2\'));
$(document).bind(\'keydown\', \'ctrl+3\', tinyMCEhotkeys(\'h3\'));
$(document).bind(\'keydown\', \'ctrl+4\', tinyMCEhotkeys(\'h4\'));