DropDownButton.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. require({cache:{
  2. 'url:dijit/form/templates/DropDownButton.html':"<span class=\"dijit dijitReset dijitInline\"\n\t><span class='dijitReset dijitInline dijitButtonNode'\n\t\tdata-dojo-attach-event=\"ondijitclick:_onClick\" data-dojo-attach-point=\"_buttonNode\"\n\t\t><span class=\"dijitReset dijitStretch dijitButtonContents\"\n\t\t\tdata-dojo-attach-point=\"focusNode,titleNode,_arrowWrapperNode\"\n\t\t\trole=\"button\" aria-haspopup=\"true\" aria-labelledby=\"${id}_label\"\n\t\t\t><span class=\"dijitReset dijitInline dijitIcon\"\n\t\t\t\tdata-dojo-attach-point=\"iconNode\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\"\n\t\t\t\tdata-dojo-attach-point=\"containerNode,_popupStateNode\"\n\t\t\t\tid=\"${id}_label\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonInner\"></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonChar\">&#9660;</span\n\t\t></span\n\t></span\n\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" class=\"dijitOffScreen\" tabIndex=\"-1\"\n\t\tdata-dojo-attach-point=\"valueNode\" role=\"presentation\"\n/></span>\n"}});
  3. define("dijit/form/DropDownButton", [
  4. "dojo/_base/declare", // declare
  5. "dojo/_base/lang", // hitch
  6. "dojo/query", // query
  7. "../registry", // registry.byNode
  8. "../popup", // dijit.popup2.hide
  9. "./Button",
  10. "../_Container",
  11. "../_HasDropDown",
  12. "dojo/text!./templates/DropDownButton.html"
  13. ], function(declare, lang, query, registry, popup, Button, _Container, _HasDropDown, template){
  14. /*=====
  15. Button = dijit.form.Button;
  16. _Container = dijit._Container;
  17. _HasDropDown = dijit._HasDropDown;
  18. =====*/
  19. // module:
  20. // dijit/form/DropDownButton
  21. // summary:
  22. // A button with a drop down
  23. return declare("dijit.form.DropDownButton", [Button, _Container, _HasDropDown], {
  24. // summary:
  25. // A button with a drop down
  26. //
  27. // example:
  28. // | <button data-dojo-type="dijit.form.DropDownButton">
  29. // | Hello world
  30. // | <div data-dojo-type="dijit.Menu">...</div>
  31. // | </button>
  32. //
  33. // example:
  34. // | var button1 = new dijit.form.DropDownButton({ label: "hi", dropDown: new dijit.Menu(...) });
  35. // | win.body().appendChild(button1);
  36. //
  37. baseClass : "dijitDropDownButton",
  38. templateString: template,
  39. _fillContent: function(){
  40. // Overrides Button._fillContent().
  41. //
  42. // My inner HTML contains both the button contents and a drop down widget, like
  43. // <DropDownButton> <span>push me</span> <Menu> ... </Menu> </DropDownButton>
  44. // The first node is assumed to be the button content. The widget is the popup.
  45. if(this.srcNodeRef){ // programatically created buttons might not define srcNodeRef
  46. //FIXME: figure out how to filter out the widget and use all remaining nodes as button
  47. // content, not just nodes[0]
  48. var nodes = query("*", this.srcNodeRef);
  49. this.inherited(arguments, [nodes[0]]);
  50. // save pointer to srcNode so we can grab the drop down widget after it's instantiated
  51. this.dropDownContainer = this.srcNodeRef;
  52. }
  53. },
  54. startup: function(){
  55. if(this._started){ return; }
  56. // the child widget from srcNodeRef is the dropdown widget. Insert it in the page DOM,
  57. // make it invisible, and store a reference to pass to the popup code.
  58. if(!this.dropDown && this.dropDownContainer){
  59. var dropDownNode = query("[widgetId]", this.dropDownContainer)[0];
  60. this.dropDown = registry.byNode(dropDownNode);
  61. delete this.dropDownContainer;
  62. }
  63. if(this.dropDown){
  64. popup.hide(this.dropDown);
  65. }
  66. this.inherited(arguments);
  67. },
  68. isLoaded: function(){
  69. // Returns whether or not we are loaded - if our dropdown has an href,
  70. // then we want to check that.
  71. var dropDown = this.dropDown;
  72. return (!!dropDown && (!dropDown.href || dropDown.isLoaded));
  73. },
  74. loadDropDown: function(/*Function*/ callback){
  75. // Default implementation assumes that drop down already exists,
  76. // but hasn't loaded it's data (ex: ContentPane w/href).
  77. // App must override if the drop down is lazy-created.
  78. var dropDown = this.dropDown;
  79. var handler = dropDown.on("load", lang.hitch(this, function(){
  80. handler.remove();
  81. callback();
  82. }));
  83. dropDown.refresh(); // tell it to load
  84. },
  85. isFocusable: function(){
  86. // Overridden so that focus is handled by the _HasDropDown mixin, not by
  87. // the _FormWidget mixin.
  88. return this.inherited(arguments) && !this._mouseDown;
  89. }
  90. });
  91. });