From e0eae18f29095b05153721a0755a75f90422acc2 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 10 Feb 2012 19:51:10 +0100 Subject: [PATCH] JS views save keyboard shortcut Signed-off-by: bachy --- guibik.info | 7 +++++ js/guibik.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 js/guibik.js diff --git a/guibik.info b/guibik.info index 25fd5951..1dd5c133 100644 --- a/guibik.info +++ b/guibik.info @@ -9,6 +9,13 @@ ;----------// Stylesheets stylesheets[screen][] = css/guibik.css +;----------// Scripts +scripts[] = "js/guibik.js" + + + + + ;----------// Regions regions[content] = Content regions[help] = Help diff --git a/js/guibik.js b/js/guibik.js new file mode 100644 index 00000000..6259f86e --- /dev/null +++ b/js/guibik.js @@ -0,0 +1,81 @@ +/** + * Implementation of Drupal behavior. + */ +(function($) { + +Drupal.behaviors.guibik = {}; +Drupal.behaviors.guibik.attach = function(context) { + + $('form.form-edit', '.views-edit-view').each(function(index) { + var $this = $(this), + _alt = false, + _submit = function(event){ + // console.log('_submit'); + event.preventDefault(); + $('input[type=submit]#edit-actions-save', $this).focus(); + $this.submit(); + return false; + }; + + $(document).bind({ + keydown: function(event) { + // console.log('keydown', event); + switch(event.keyCode){ + case 18: + _alt = true; + break; + case 83: // s + if(_alt) + return _submit(event); + } + }, + keyup: function(event) { + // console.log('keyup', event); + switch(event.keyCode){ + case 18: + _alt = false; + break; + } + + } + }); + + // $(document).keydown(function(event){ + // console.log(event); + // }); + + + + }); + + +}; + +Drupal.behaviors.init_theme = {}; +Drupal.behaviors.init_theme.attach = function (context) { + + // Growl-style system messages + $('#messages-and-help > div.messages:not(.processed)') + .addClass('processed') + .each(function() { + // If a message meets these criteria, we don't autoclose + // - contains a link + // - is an error or warning + // - contains a lenghthy amount of text + if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) { + $(this).prepend("X"); + $('span.close', this).click(function() { + $(this).parent().slideUp('fast'); + }); + } + else { + // This essentially adds a 3 second pause before hiding the message. + $(this).animate({opacity:1}, 5000, 'linear', function() { + $(this).slideUp('fast'); + }); + } + }); +}; + + +})(jQuery);