root / drupal7 / sites / all / modules / sweaver / plugins / sweaver_plugin_kb / sweaver_plugin_kb.js @ 13755f8d
1 | 85ad3d82 | Assos Assos | |
---|---|---|---|
2 | (function ($) { |
||
3 | |||
4 | /**
|
||
5 | * Add key bindings when the Styles plugin is enabled.
|
||
6 | *
|
||
7 | * List of key bindings can be found at
|
||
8 | * http://www.weverwijk.net/wordpress/2010/03/23/key-events-in-javascript/
|
||
9 | * https://github.com/jeresig/jquery.hotkeys
|
||
10 | *
|
||
11 | * More inspiration :
|
||
12 | * - http://rikrikrik.com/jquery/shortkeys/#download
|
||
13 | * - http://code.google.com/p/js-hotkeys/
|
||
14 | * - http://code.google.com/p/js-hotkeys/wiki/about
|
||
15 | */
|
||
16 | |||
17 | var kb_popup = ''; |
||
18 | |||
19 | /**
|
||
20 | * Bind the keys.
|
||
21 | */
|
||
22 | $(document).ready(function() { |
||
23 | $.each(Drupal.settings.sweaver['kb'], function (index, key_binding) { |
||
24 | if (key_binding.element != '' && $(key_binding.element).length == 0) { |
||
25 | return;
|
||
26 | } |
||
27 | $(document).bind('keydown', key_binding.kb_button, function(event) { |
||
28 | Drupal.Sweaver.kbShowPopup(event, key_binding); |
||
29 | }); |
||
30 | }); |
||
31 | }); |
||
32 | |||
33 | /**
|
||
34 | * Show or close the popup.
|
||
35 | */
|
||
36 | Drupal.Sweaver.kbShowPopup = function(event, key_binding) { |
||
37 | if (event.keyCode == parseInt(key_binding.kb_code) && key_binding.element != '') { |
||
38 | if (key_binding.kb_button != kb_popup) {
|
||
39 | kb_popup = key_binding.kb_button; |
||
40 | Drupal.Sweaver.showPopup($(key_binding.element), '400px', '200px'); |
||
41 | } |
||
42 | } |
||
43 | else {
|
||
44 | kb_popup = '';
|
||
45 | Drupal.Sweaver.hidePopup(); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | })(jQuery); |