A guide to YUI Config utility


/ Published in: JavaScript
Save to your folder(s)

Config is a utility used within an Object to allow the implementer to maintain a list of local configuration properties and listen for changes to those properties dynamically using CustomEvent. The initial values are also maintained so that the configuration can be reset at any given point to its initial state.

Dependencies:
* yahoo.js
* event.js


Copy this code and paste it in your HTML
  1. // JScript source code
  2. var Object = function(){
  3. var cfg = new YAHOO.util.Config(this);
  4. element;
  5.  
  6. initDefaultConfig: function() {
  7.  
  8. this.cfg.addProperty(
  9. "color",
  10. {
  11. value: "#000000",
  12. handler: setColor
  13. }
  14. );
  15.  
  16. this.cfg.addProperty(
  17. "width",
  18. {
  19. value: null,
  20. handler: setWidth
  21. }
  22. );
  23.  
  24. this.cfg.fireQueue();
  25. }
  26.  
  27. var setColor = function(type, args, obj){
  28. var color = args[0];
  29. YAHOO.util.Dom.setStyle(element, "color", color);
  30. }
  31.  
  32. var setWidth = function(type, args, obj){
  33. var width = args[0] + "px";
  34. YAHOO.util.Dom.setStyle(element, "width", width);
  35. }
  36.  
  37. this.init = function(elementId){
  38. element = YAHOO.util.Dom.get(elementId);
  39. initDefaultConfig();
  40. }
  41. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.