_ClassMixin.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. define("dojox/form/manager/_ClassMixin", [
  2. "dojo/_base/lang",
  3. "dojo/_base/kernel",
  4. "dojo/dom-class",
  5. "./_Mixin",
  6. "dojo/_base/declare"
  7. ], function(lang, dojo, domClass, _Mixin, declare){
  8. var fm = lang.getObject("dojox.form.manager", true),
  9. aa = fm.actionAdapter,
  10. ia = fm.inspectorAdapter;
  11. return declare("dojox.form.manager._ClassMixin", null, {
  12. // summary:
  13. // Form manager's mixin for testing/assigning/removing
  14. // classes of controlled elements.
  15. // description:
  16. // This mixin provides unified way to check/add/remove a class
  17. // of controlled elements.
  18. // It should be used together with dojox.form.manager.Mixin.
  19. gatherClassState: function(className, names){
  20. // summary:
  21. // Gather the presence of a certain class in all controlled elements.
  22. // className: String:
  23. // The class name to test for.
  24. // names: Object?:
  25. // If it is an array, it is a list of names to be processed.
  26. // If it is an object, dictionary keys are names to be processed.
  27. // If it is omitted, all known form elements are to be processed.
  28. var result = this.inspect(ia(function(name, node){
  29. return domClass.contains(node, className);
  30. }), names);
  31. return result; // Object
  32. },
  33. addClass: function(className, names){
  34. // summary:
  35. // Add a class to nodes according to the supplied set of names
  36. // className: String:
  37. // Class name to add.
  38. // names: Object?:
  39. // If it is an array, it is a list of names to be processed.
  40. // If it is an object, dictionary keys are names to be processed.
  41. // If it is omitted, all known form elements are to be processed.
  42. this.inspect(aa(function(name, node){
  43. domClass.add(node, className);
  44. }), names);
  45. return this; // self
  46. },
  47. removeClass: function(className, names){
  48. // summary:
  49. // Remove a class from nodes according to the supplied set of names
  50. // className: String:
  51. // Class name to remove.
  52. // names: Object?:
  53. // If it is an array, it is a list of names to be processed.
  54. // If it is an object, dictionary keys are names to be processed.
  55. // If it is omitted, all known form elements are to be processed.
  56. this.inspect(aa(function(name, node){
  57. domClass.remove(node, className);
  58. }), names);
  59. return this; // self
  60. }
  61. });
  62. });