_ComboBoxMenu.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. define("dijit/form/_ComboBoxMenu", [
  2. "dojo/_base/declare", // declare
  3. "dojo/dom-class", // domClass.add domClass.remove
  4. "dojo/dom-construct", // domConstruct.create
  5. "dojo/dom-style", // domStyle.get
  6. "dojo/keys", // keys.DOWN_ARROW keys.PAGE_DOWN keys.PAGE_UP keys.UP_ARROW
  7. "../_WidgetBase",
  8. "../_TemplatedMixin",
  9. "./_ComboBoxMenuMixin",
  10. "./_ListMouseMixin"
  11. ], function(declare, domClass, domConstruct, domStyle, keys,
  12. _WidgetBase, _TemplatedMixin, _ComboBoxMenuMixin, _ListMouseMixin){
  13. /*=====
  14. var _WidgetBase = dijit._WidgetBase;
  15. var _TemplatedMixin = dijit._TemplatedMixin;
  16. var _ComboBoxMenuMixin = dijit.form._ComboBoxMenuMixin;
  17. var _ListMouseMixin = dijit.form._ListMouseMixin;
  18. =====*/
  19. // module:
  20. // dijit/form/_ComboBoxMenu
  21. // summary:
  22. // Focus-less menu for internal use in `dijit.form.ComboBox`
  23. return declare("dijit.form._ComboBoxMenu",[_WidgetBase, _TemplatedMixin, _ListMouseMixin, _ComboBoxMenuMixin], {
  24. // summary:
  25. // Focus-less menu for internal use in `dijit.form.ComboBox`
  26. // Abstract methods that must be defined externally:
  27. // onChange: item was explicitly chosen (mousedown somewhere on the menu and mouseup somewhere on the menu)
  28. // onPage: next(1) or previous(-1) button pressed
  29. // tags:
  30. // private
  31. templateString: "<div class='dijitReset dijitMenu' data-dojo-attach-point='containerNode' style='overflow: auto; overflow-x: hidden;'>"
  32. +"<div class='dijitMenuItem dijitMenuPreviousButton' data-dojo-attach-point='previousButton' role='option'></div>"
  33. +"<div class='dijitMenuItem dijitMenuNextButton' data-dojo-attach-point='nextButton' role='option'></div>"
  34. +"</div>",
  35. baseClass: "dijitComboBoxMenu",
  36. postCreate: function(){
  37. this.inherited(arguments);
  38. if(!this.isLeftToRight()){
  39. domClass.add(this.previousButton, "dijitMenuItemRtl");
  40. domClass.add(this.nextButton, "dijitMenuItemRtl");
  41. }
  42. },
  43. _createMenuItem: function(){
  44. return domConstruct.create("div", {
  45. "class": "dijitReset dijitMenuItem" +(this.isLeftToRight() ? "" : " dijitMenuItemRtl"),
  46. role: "option"
  47. });
  48. },
  49. onHover: function(/*DomNode*/ node){
  50. // summary:
  51. // Add hover CSS
  52. domClass.add(node, "dijitMenuItemHover");
  53. },
  54. onUnhover: function(/*DomNode*/ node){
  55. // summary:
  56. // Remove hover CSS
  57. domClass.remove(node, "dijitMenuItemHover");
  58. },
  59. onSelect: function(/*DomNode*/ node){
  60. // summary:
  61. // Add selected CSS
  62. domClass.add(node, "dijitMenuItemSelected");
  63. },
  64. onDeselect: function(/*DomNode*/ node){
  65. // summary:
  66. // Remove selected CSS
  67. domClass.remove(node, "dijitMenuItemSelected");
  68. },
  69. _page: function(/*Boolean*/ up){
  70. // summary:
  71. // Handles page-up and page-down keypresses
  72. var scrollamount = 0;
  73. var oldscroll = this.domNode.scrollTop;
  74. var height = domStyle.get(this.domNode, "height");
  75. // if no item is highlighted, highlight the first option
  76. if(!this.getHighlightedOption()){
  77. this.selectNextNode();
  78. }
  79. while(scrollamount<height){
  80. var highlighted_option = this.getHighlightedOption();
  81. if(up){
  82. // stop at option 1
  83. if(!highlighted_option.previousSibling ||
  84. highlighted_option.previousSibling.style.display == "none"){
  85. break;
  86. }
  87. this.selectPreviousNode();
  88. }else{
  89. // stop at last option
  90. if(!highlighted_option.nextSibling ||
  91. highlighted_option.nextSibling.style.display == "none"){
  92. break;
  93. }
  94. this.selectNextNode();
  95. }
  96. // going backwards
  97. var newscroll = this.domNode.scrollTop;
  98. scrollamount += (newscroll-oldscroll)*(up ? -1:1);
  99. oldscroll = newscroll;
  100. }
  101. },
  102. handleKey: function(evt){
  103. // summary:
  104. // Handle keystroke event forwarded from ComboBox, returning false if it's
  105. // a keystroke I recognize and process, true otherwise.
  106. switch(evt.keyCode){
  107. case keys.DOWN_ARROW:
  108. this.selectNextNode();
  109. return false;
  110. case keys.PAGE_DOWN:
  111. this._page(false);
  112. return false;
  113. case keys.UP_ARROW:
  114. this.selectPreviousNode();
  115. return false;
  116. case keys.PAGE_UP:
  117. this._page(true);
  118. return false;
  119. default:
  120. return true;
  121. }
  122. }
  123. });
  124. });