KeyMap-min.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.KeyMap = function(C, B, A) {
  7. this.el = Ext.get(C);
  8. this.eventName = A || "keydown";
  9. this.bindings = [];
  10. if (B) {
  11. this.addBinding(B)
  12. }
  13. this.enable()
  14. };
  15. Ext.KeyMap.prototype = {
  16. stopEvent : false,
  17. addBinding : function(D) {
  18. if (D instanceof Array) {
  19. for (var F = 0, H = D.length; F < H; F++) {
  20. this.addBinding(D[F])
  21. }
  22. return
  23. }
  24. var N = D.key, C = D.shift, A = D.ctrl, G = D.alt, J = D.fn
  25. || D.handler, M = D.scope;
  26. if (typeof N == "string") {
  27. var K = [];
  28. var I = N.toUpperCase();
  29. for (var E = 0, H = I.length; E < H; E++) {
  30. K.push(I.charCodeAt(E))
  31. }
  32. N = K
  33. }
  34. var B = N instanceof Array;
  35. var L = function(R) {
  36. if ((!C || R.shiftKey) && (!A || R.ctrlKey) && (!G || R.altKey)) {
  37. var P = R.getKey();
  38. if (B) {
  39. for (var Q = 0, O = N.length; Q < O; Q++) {
  40. if (N[Q] == P) {
  41. if (this.stopEvent) {
  42. R.stopEvent()
  43. }
  44. J.call(M || window, P, R);
  45. return
  46. }
  47. }
  48. } else {
  49. if (P == N) {
  50. if (this.stopEvent) {
  51. R.stopEvent()
  52. }
  53. J.call(M || window, P, R)
  54. }
  55. }
  56. }
  57. };
  58. this.bindings.push(L)
  59. },
  60. on : function(B, D, C) {
  61. var G, A, E, F;
  62. if (typeof B == "object" && !(B instanceof Array)) {
  63. G = B.key;
  64. A = B.shift;
  65. E = B.ctrl;
  66. F = B.alt
  67. } else {
  68. G = B
  69. }
  70. this.addBinding({
  71. key : G,
  72. shift : A,
  73. ctrl : E,
  74. alt : F,
  75. fn : D,
  76. scope : C
  77. })
  78. },
  79. handleKeyDown : function(D) {
  80. if (this.enabled) {
  81. var B = this.bindings;
  82. for (var C = 0, A = B.length; C < A; C++) {
  83. B[C].call(this, D)
  84. }
  85. }
  86. },
  87. isEnabled : function() {
  88. return this.enabled
  89. },
  90. enable : function() {
  91. if (!this.enabled) {
  92. this.el.on(this.eventName, this.handleKeyDown, this);
  93. this.enabled = true
  94. }
  95. },
  96. disable : function() {
  97. if (this.enabled) {
  98. this.el.removeListener(this.eventName, this.handleKeyDown, this);
  99. this.enabled = false
  100. }
  101. }
  102. };