_DisplayMixin.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. define("dojox/form/manager/_DisplayMixin", [
  2. "dojo/_base/kernel",
  3. "dojo/dom-style",
  4. "dojo/_base/declare"
  5. ], function(dojo, domStyle, declare){
  6. return declare("dojox.form.manager._DisplayMixin", null, {
  7. // summary:
  8. // Form manager's mixin for controlling show/hide state of
  9. // controlled elements (defined by dojoAttachPoint attributes).
  10. // description:
  11. // This mixin provides unified show/hide functionality for
  12. // controlled elements (indicated by dojoAttachPoint attribute).
  13. // Essentially it provides a way to change "style.display"
  14. // parameter of controlled nodes.
  15. // It should be used together with dojox.form.manager.Mixin.
  16. gatherDisplayState: function(names){
  17. // summary:
  18. // Gather display state of all attached elements and return as a dictionary.
  19. // names: Object?:
  20. // If it is an array, it is a list of names to be processed.
  21. // If it is an object, dictionary keys are names to be processed.
  22. // If it is omitted, all known attach point nodes are to be processed.
  23. var result = this.inspectAttachedPoints(function(name, node){
  24. return domStyle.get(node, "display") != "none";
  25. }, names);
  26. return result; // Object
  27. },
  28. show: function(state, defaultState){
  29. // summary:
  30. // Show attached nodes according to the supplied state object.
  31. // state: Object?:
  32. // Optional. If a name-value dictionary, the value is true
  33. // to show and false to hide. If an array, all names in the
  34. // array will be set to defaultState. If omitted, all form
  35. // elements will be set to defaultState.
  36. // defaultState: Boolean?:
  37. // The default state (true, if omitted).
  38. if(arguments.length < 2){
  39. defaultState = true;
  40. }
  41. this.inspectAttachedPoints(function(name, node, value){
  42. domStyle.set(node, "display", value ? "" : "none");
  43. }, state, defaultState);
  44. return this; // self
  45. },
  46. hide: function(state){
  47. // summary:
  48. // Hide attached nodes according to the supplied state object.
  49. // state: Object?:
  50. // Optional. If a name-value dictionary, the value is true
  51. // to show and false to hide. If an array, all names in the
  52. // array will be hidden. If omitted, all form elements
  53. // will be hidden.
  54. return this.show(state, false); // self
  55. }
  56. });
  57. });