1

Ctrl+S 和 Ctrl+Q 键包含在 jqgrid 编辑中,并使用 Oleg 很好的答案添加表单:

beforeShowForm: function ($form) {
  var gridIdEncoded = $.jgrid.jqID($form[0].id.substring(8));
  $("#editmod" + gridIdEncoded).bind('keydown.formEvent', function (e) {
    if (e.ctrlKey && e.which === 83) {
      $("#TblGrid_" + gridIdEncoded + "_2 #sData").trigger("click");
      return false;
      }
    if (e.ctrlKey && e.which === 81) {  // ctrl-q
                   $("#TblGrid_" + gridIdEncoded + "_2 #cData").trigger("click");
                   return false;
                   }
}

TinyMCE html 编辑器使用 afterShowForm 事件附加到 jqgrid 表单中的 textarea 元素

    $('.htmleditor', formSelector).attr('cols', '50').attr('rows', '15').tinymce({
        theme: "advanced",
        language: "et",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter," +
"justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,cut ,copy,paste,undo,redo" +
"link,unlink,image,cleanup,code,hr,|,removeformat,formatselect,|,fontselect,fontsizeselect," +
"sub,sup,|,forecolor,backcolor,forecolorpicker,backcolorpicker,charmap,visualaid," +
"anchor,blockquote"
    });
}

之后在 textarea 中按 Ctrl+S 会出现 IE9 标准保存对话框。如何允许 Ctrl+S 在 tinyMCE 中保存 jqgrid 表单?

更新

我尝试使用下面的代码从答案中推荐。未捕获 Keydown 事件。

afterShowForm: function (formSelector) {
        $('.htmleditor', formSelector).attr('cols', '50').attr('rows', '15').tinymce({
            setup: function (ed) {
                ed.onKeyDown.add(function (ed, e) {
                    // this box happens: alert('setup binding');
                    var gridIdEncoded = $.jgrid.jqID(formSelector[0].id.substring(8));
                    $("#editmod" + gridIdEncoded).bind('keydown.formEvent', function (e) {
                        alert('in keydown'); // this does not happen
                        if (e.ctrlKey && e.which === 83) {
                            $("#TblGrid_" + gridIdEncoded + "_2 #sData").trigger("click");
                            return false;
                        }
                        if (e.ctrlKey && e.which === 81) {  // ctrl-q
                            $("#TblGrid_" + gridIdEncoded + "_2 #cData").trigger("click");
                            return false;
                        }
                    });
                });
            },

            theme: "advanced",
            language: "et",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons1: "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter," +
    "justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,cut ,copy,paste,undo,redo" +
    "link,unlink,image,cleanup,code,hr,|,removeformat,formatselect,|,fontselect,fontsizeselect," +
    "sub,sup,|,forecolor,backcolor,forecolorpicker,backcolorpicker,charmap,visualaid," +
    "anchor,blockquote"
        });
    };

更新2

e.未定义。代码

$('.htmleditor', formSelector).attr('cols', '50').attr('rows', '15').tinymce({
    setup: function (ed) {
        ed.onKeyDown.add(function (ed, e) {
            var gridIdEncoded = $.jgrid.jqID(formSelector[0].id.substring(8));
            if (e.ctrlKey && e.keyCode === 83) {
                $("#TblGrid_" + gridIdEncoded + "_2 #sData").trigger("click");
                return false;
            }
            if (e.ctrlKey && e.keyCode === 81) {
                $("#TblGrid_" + gridIdEncoded + "_2 #cData").trigger("click");
                return false;
            }
        });
    },

捕获 ctrl+s 和 ctrl+q。使用下面的代码在 html keydown 事件中定义了许多全局快捷键。如果 tinymce 有焦点,这些将被忽略。如何使它们也起作用。如何在主窗口或其他想法中调用 html.keydown?

$(function () {
    $("html").keydown(function (evt) {
        var elem = evt.target || evt.srcElement;
        if (evt.ctrlKey) {
            switch (evt.keyCode) {
                case 68: openWindow('ToodeL'); return false;
                case 69: openWindow('DoklstlG'); return false;
... lot of openWindow calls
4

1 回答 1

2

我自己不使用tinyMCE ,但对演示的简短检查表明 tinyMCE 使用<iframe>. 如果你需要在keydown里面捕获事件,<iframe>你应该设置额外的keydown事件处理程序。对于演示有

<textarea name="content" style="width:100%"></textarea> 

<iframe>将使用的 id content_ifr。因此,您可以尝试查找<iframe>方式中构造的 by id,或者只是iframe尝试<span><textarea>. 然后你可以.contentWindow.document<iframe>元素中获取并keydown.contentWindow.document. 有关更多信息,请参阅答案这个。可能像这里这样的其他更面向tinyMCE的解决方案会更好。因为我自己不使用tinyMCE(见我回答的第一句话),所以我不能推荐你一些具体的方法。

更新:在我看来,现在有更直接的方法可以提供 tinyMCE: onKeyDown

于 2012-04-06T21:14:38.283 回答