Requires

Provides

Keyboard.js

KeyboardEvents used to intercept events on a class for keyboard and format modifiers in a specific order so as to make alt+shift+c the same as shift+alt+c.

License:
MIT-style license
Authors:
Perrin Westrich, Aaron Newton, Scott Kyle, Arian Stolwijk
  1. 30
  2. 31
  3. 32
  4. 33
  5. 34
  6. 35
  7. 36
  8. 37
  9. 38
  10. 39
  11. 40
  12. 41
  13. 42
  14. 43
  15. 44
  16. 45
  17. 46
  18. 47
  19. 48
  20. 49
  21. 50
  22. 51
  23. 52
  24. 53
  25. 54
  26. 55
  27. 56
  28. 57
  29. 58
  30. 59
  31. 60
  32. 61
  33. 62
  34. 63
  35. 64
  36. 65
  37. 66
  38. 67
  39. 68
  40. 69
  41. 70
  42. 71
  43. 72
  44. 73
  45. 74
  46. 75
  47. 76
  48. 77
  49. 78
  50. 79
(function(){ var active = null, previous = null Keyboard = this.Keyboard = new Class({ Extends: Events, Implements: Options, events: {}, options: {/* onActivate: function(){}, onDeactivate: function(){},*/ active: false, events: {}, parent: null, nonParsedEvents: ['activate', 'deactivate', 'onactivate', 'ondeactivate'] }, initialize: function(options){ this.uid = Keyboard.uniqueID(); this.setOptions(options); this.setParent(this.options.parent); this.addEvents(this.options.events); if (this.options.active) this.activate(); }, addEvent: function(name, fn){ if (this.options.nonParsedEvents.contains(name.toLowerCase())) return this.parent.apply(this, arguments); var event = this.events[name] = function(){ if (this.isActive() || this.inActiveTrace()) fn.apply(this, arguments); }.bind(this); document.body.addEvent('keydown:keys(' + name + ')', event); return this; }, removeEvent: function(name, fn){ if (this.options.nonParsedEvents.contains(name)) return this.parent.apply(this, arguments); var event = this.events[name]; if (event) document.body.removeEvent(this.options.eventType + ':keys(' + name + ')', event); return this; },

Instances management

  1. 83
  2. 84
  3. 85
  4. 86
  5. 87
  6. 88
  7. 89
  8. 90
  9. 91
  10. 92
  11. 93
  12. 94
  13. 95
  14. 96
  15. 97
  16. 98
  17. 99
  18. 100
  19. 101
  20. 102
activate: function(){ Keyboard.activate(this); }, deactivate: function(){ Keyboard.activate(this.parent); this.fireEvent('deactivate'); }, toggleActive: function(){ return this[this.isActive() ? 'deactivate' : 'activate'](); }, isActive: function(){ return active == this; }, setParent: function(parent){ this.parent = parent; },

<1.2compat>

  1. 105
  2. 106
  3. 107
manage: function(child){ child.parent = this; },

</1.2compat>

  1. 110
  2. 111
  3. 112
  4. 113
  5. 114
  6. 115
  7. 116
  8. 117
  9. 118
  10. 119
  11. 120
  12. 121
  13. 122
  14. 123
  15. 124
relinquish: function(){ Keyboard.activate(previous); }, trace: function(){ return Keyboard.trace(this); }, inActiveTrace: function(){ return Keyboard.trace().some(function(instance){ return instance.uid == this.uid; }, this); } });

Instance Activation

  1. 128
  2. 129
  3. 130
  4. 131
  5. 132
  6. 133
  7. 134
  8. 135
  9. 136
  10. 137
  11. 138
  12. 139
  13. 140
  14. 141
  15. 142
  16. 143
  17. 144
  18. 145
  19. 146
  20. 147
  21. 148
  22. 149
  23. 150
  24. 151
  25. 152
  26. 153
  27. 154
  28. 155
  29. 156
  30. 157
  31. 158
  32. 159
  33. 160
  34. 161
  35. 162
  36. 163
  37. 164
  38. 165
  39. 166
  40. 167
  41. 168
  42. 169
  43. 170
  44. 171
  45. 172
  46. 173
  47. 174
  48. 175
  49. 176
  50. 177
  51. 178
  52. 179
Keyboard.activate = function(kb){ previous = active; active = kb; if (kb) kb.fireEvent('activate'); }; Keyboard.trace = function(kb){ if (!kb) kb = active; var trace = [], parent = kb.parent; while (parent){ trace.push(parent); parent = parent.parent; } return trace; }; Keyboard.getActive = function(){ return active; }; Object.append(Event.Keys, { 'shift': 16, 'control': 17, 'alt': 18, 'capslock': 20, 'pageup': 33, 'pagedown': 34, 'end': 35, 'home': 36, 'numlock': 144, 'scrolllock': 145, ';': 186, '=': 187, ',': 188, '-': Browser.firefox ? 109 : 189, '.': 190, '/': 191, '`': 192, '[': 219, '\\': 220, ']': 221, "'": 222 }); var UID = Math.floor(Math.random() * 10e12); Keyboard.uniqueID = function(){ return (UID++).toString(36); }; })();