_ClassMixin.js 2.5 KB

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