KeyNav-min.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.KeyNav = function(B, A) {
  7. this.el = Ext.get(B);
  8. Ext.apply(this, A);
  9. if (!this.disabled) {
  10. this.disabled = true;
  11. this.enable()
  12. }
  13. };
  14. Ext.KeyNav.prototype = {
  15. disabled : false,
  16. defaultEventAction : "stopEvent",
  17. forceKeyDown : false,
  18. prepareEvent : function(C) {
  19. var A = C.getKey();
  20. var B = this.keyToHandler[A];
  21. if (Ext.isSafari && B && A >= 37 && A <= 40) {
  22. C.stopEvent()
  23. }
  24. },
  25. relay : function(C) {
  26. var A = C.getKey();
  27. var B = this.keyToHandler[A];
  28. if (B && this[B]) {
  29. if (this.doRelay(C, this[B], B) !== true) {
  30. C[this.defaultEventAction]()
  31. }
  32. }
  33. },
  34. doRelay : function(C, B, A) {
  35. return B.call(this.scope || this, C)
  36. },
  37. enter : false,
  38. left : false,
  39. right : false,
  40. up : false,
  41. down : false,
  42. tab : false,
  43. esc : false,
  44. pageUp : false,
  45. pageDown : false,
  46. del : false,
  47. home : false,
  48. end : false,
  49. keyToHandler : {
  50. 37 : "left",
  51. 39 : "right",
  52. 38 : "up",
  53. 40 : "down",
  54. 33 : "pageUp",
  55. 34 : "pageDown",
  56. 46 : "del",
  57. 36 : "home",
  58. 35 : "end",
  59. 13 : "enter",
  60. 27 : "esc",
  61. 9 : "tab"
  62. },
  63. enable : function() {
  64. if (this.disabled) {
  65. if (this.forceKeyDown || Ext.isIE || Ext.isAir) {
  66. this.el.on("keydown", this.relay, this)
  67. } else {
  68. this.el.on("keydown", this.prepareEvent, this);
  69. this.el.on("keypress", this.relay, this)
  70. }
  71. this.disabled = false
  72. }
  73. },
  74. disable : function() {
  75. if (!this.disabled) {
  76. if (this.forceKeyDown || Ext.isIE || Ext.isAir) {
  77. this.el.un("keydown", this.relay)
  78. } else {
  79. this.el.un("keydown", this.prepareEvent);
  80. this.el.un("keypress", this.relay)
  81. }
  82. this.disabled = true
  83. }
  84. }
  85. };