_ComboBoxMenu.js.uncompressed.js 3.9 KB

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