Parcourir la source

JS views save keyboard shortcut

Signed-off-by: bachy <git@g-u-i.net>
bachy il y a 13 ans
Parent
commit
e0eae18f29
2 fichiers modifiés avec 88 ajouts et 0 suppressions
  1. 7 0
      guibik.info
  2. 81 0
      js/guibik.js

+ 7 - 0
guibik.info

@@ -9,6 +9,13 @@
 ;----------// Stylesheets
 ;----------// Stylesheets
   stylesheets[screen][] = css/guibik.css
   stylesheets[screen][] = css/guibik.css
 
 
+;----------// Scripts
+scripts[] = "js/guibik.js"
+
+
+
+
+
 ;----------// Regions
 ;----------// Regions
  	regions[content] = Content
  	regions[content] = Content
 	regions[help] = Help
 	regions[help] = Help

+ 81 - 0
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("<span class='close'>X</span>");
+        $('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);