CheckedMenuItem.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit.CheckedMenuItem"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit.CheckedMenuItem"] = true;
  8. dojo.provide("dijit.CheckedMenuItem");
  9. dojo.require("dijit.MenuItem");
  10. dojo.declare("dijit.CheckedMenuItem",
  11. dijit.MenuItem,
  12. {
  13. // summary:
  14. // A checkbox-like menu item for toggling on and off
  15. templateString: dojo.cache("dijit", "templates/CheckedMenuItem.html", "<tr class=\"dijitReset dijitMenuItem\" dojoAttachPoint=\"focusNode\" role=\"menuitemcheckbox\" tabIndex=\"-1\"\n\t\tdojoAttachEvent=\"onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick\">\n\t<td class=\"dijitReset dijitMenuItemIconCell\" role=\"presentation\">\n\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitMenuItemIcon dijitCheckedMenuItemIcon\" dojoAttachPoint=\"iconNode\"/>\n\t\t<span class=\"dijitCheckedMenuItemIconChar\">&#10003;</span>\n\t</td>\n\t<td class=\"dijitReset dijitMenuItemLabel\" colspan=\"2\" dojoAttachPoint=\"containerNode,labelNode\"></td>\n\t<td class=\"dijitReset dijitMenuItemAccelKey\" style=\"display: none\" dojoAttachPoint=\"accelKeyNode\"></td>\n\t<td class=\"dijitReset dijitMenuArrowCell\" role=\"presentation\">&nbsp;</td>\n</tr>\n"),
  16. // checked: Boolean
  17. // Our checked state
  18. checked: false,
  19. _setCheckedAttr: function(/*Boolean*/ checked){
  20. // summary:
  21. // Hook so attr('checked', bool) works.
  22. // Sets the class and state for the check box.
  23. dojo.toggleClass(this.domNode, "dijitCheckedMenuItemChecked", checked);
  24. dijit.setWaiState(this.domNode, "checked", checked);
  25. this._set("checked", checked);
  26. },
  27. onChange: function(/*Boolean*/ checked){
  28. // summary:
  29. // User defined function to handle check/uncheck events
  30. // tags:
  31. // callback
  32. },
  33. _onClick: function(/*Event*/ e){
  34. // summary:
  35. // Clicking this item just toggles its state
  36. // tags:
  37. // private
  38. if(!this.disabled){
  39. this.set("checked", !this.checked);
  40. this.onChange(this.checked);
  41. }
  42. this.inherited(arguments);
  43. }
  44. });
  45. }