added a $.cmd("key", {}) method, is now used by shortcut.js
This commit is contained in:
parent
8a3151cf58
commit
135f6e54ad
@ -12,6 +12,7 @@ javascripts:
|
||||
- public/javascripts/admin/jquery.ui.js
|
||||
- public/javascripts/admin/rails.js
|
||||
- public/javascripts/admin/utils.js
|
||||
- public/javascripts/admin/plugins/cmd.js
|
||||
- public/javascripts/admin/plugins/subscribe.js
|
||||
- public/javascripts/admin/plugins/shortcut.js
|
||||
- public/javascripts/admin/plugins/toggle.js
|
||||
|
13
public/javascripts/admin/plugins/cmd.js
Normal file
13
public/javascripts/admin/plugins/cmd.js
Normal file
@ -0,0 +1,13 @@
|
||||
$.cmd = function(key, callback, args) {
|
||||
var isCtrl = false;
|
||||
$(document).keydown(function(e) {
|
||||
if(!args) args=[]; // IE barks when args is null
|
||||
if(e.metaKey) isCtrl = true;
|
||||
if(e.keyCode == key.charCodeAt(0) && isCtrl) {
|
||||
callback.apply(this, args);
|
||||
return false;
|
||||
}
|
||||
}).keyup(function(e) {
|
||||
if(e.ctrlKey) isCtrl = false;
|
||||
});
|
||||
};
|
@ -43,8 +43,7 @@ jQuery.fn.saveWithShortcut = function() {
|
||||
return this.each(function() {
|
||||
var form = jQuery(this);
|
||||
|
||||
jQuery(document).bind('keypress.shortcut', function(event) {
|
||||
if (!(event.which == 115 && (event.ctrlKey || event.metaKey))) return true;
|
||||
$.cmd('S', function() {
|
||||
updateFromCodeMirror();
|
||||
save(form);
|
||||
event.preventDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user