added a $.cmd("key", {}) method, is now used by shortcut.js

This commit is contained in:
Dirk Kelly 2011-01-11 21:42:47 +08:00
parent 8a3151cf58
commit 135f6e54ad
3 changed files with 15 additions and 2 deletions

View File

@ -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

View 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;
});
};

View File

@ -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();