_DisplayMixin.js 2.5 KB

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