Merge branch 'dollar-cmd-s' of https://github.com/dirkkelly/locomotive into dirkkelly-dollar-cmd-s

This commit is contained in:
dinedine 2011-01-12 09:42:35 +01:00
commit b397a34c47
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/jquery.ui.js
- public/javascripts/admin/rails.js - public/javascripts/admin/rails.js
- public/javascripts/admin/utils.js - public/javascripts/admin/utils.js
- public/javascripts/admin/plugins/cmd.js
- public/javascripts/admin/plugins/subscribe.js - public/javascripts/admin/plugins/subscribe.js
- public/javascripts/admin/plugins/shortcut.js - public/javascripts/admin/plugins/shortcut.js
- public/javascripts/admin/plugins/toggle.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() { return this.each(function() {
var form = jQuery(this); var form = jQuery(this);
jQuery(document).bind('keypress.shortcut', function(event) { $.cmd('S', function() {
if (!(event.which == 115 && (event.ctrlKey || event.metaKey))) return true;
updateFromCodeMirror(); updateFromCodeMirror();
save(form); save(form);
event.preventDefault(); event.preventDefault();