Ctrl+S and Ctrl+Q keys are cathed in jqgrid edit and add forms using Oleg great answer:
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 editor is attached to textarea elements in jqgrid form in afterShowForm event using
$('.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"
});
}
After that pressing Ctrl+S in textarea causes IE9 standard save dialog to appear. How to allow Ctrl+S to save jqgrid form in tinyMCE also ?
Update
I tried recommendation from answer using code below. Keydown event is not catched.
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"
});
};
Update2
e.which was undefinded. Code
$('.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;
}
});
},
catches ctrl+s and ctrl+q. There are also lot of global shortcut keys defined in html keydown event using code below. Those are ignored if tinymce has focus. How to make them to work also. How to call html.keydown in main window or other idea ?
$(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