/branches/jsdoc_tk_gui/setup/workingDirectory/Webeo/gui/style/CSSLoader.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 121 lines · 55 code · 15 blank · 51 comment · 7 complexity · 5044977e7078bd833b91ca622e4e70f3 MD5 · raw file

  1. ek.require("gui.tools.Dom");
  2. ek.require("gui.layout.ToolBar");//To call only if necessary
  3. ek.register("gui.style.CSSLoader");
  4. /**
  5. * @fileoverview
  6. * The CSSLoader class allow you to change the css source file dynamically
  7. *@author Sebastien Bordes => Sebastien dot Bordes at webeo dot fr
  8. *@version 0.9
  9. */
  10. /**
  11. * Construct a CSSLoader object
  12. * @class
  13. * This class is used to manage easily Cascading Style Sheets
  14. * @constructor
  15. * @param container : The container which will hold the buttons/links/ComboBox
  16. * @param cssId : The id of the link element node
  17. * @param defaultCSS : The default selected CSS
  18. * @return a new CSSLoader Object
  19. */
  20. function CSSLoader (container, cssId, defaultCSS){
  21. this.container = (typeof container == "object")? container : Dom.getElement(container);
  22. this.cssId = (cssId) ? cssId : "default";
  23. this.defaultCSS = (defaultCSS) ? defaultCSS : "index";
  24. this.sheets = new Array();
  25. }
  26. /**
  27. * Add a CSS to the list.
  28. * @param text : Name of the styleSheet , could be displayed
  29. * @param src : url of the style sheet, must be unique
  30. */
  31. CSSLoader.prototype.addCSS = function (text, src){
  32. this.sheets[src] = text;
  33. }
  34. /**
  35. * Remove a CSS
  36. * @param src : url of the style sheet
  37. */
  38. CSSLoader.prototype.removeCSS = function (src){
  39. this.sheets[src] = undefined;
  40. }
  41. /**
  42. * Create and draw some buttons to allow to change the current CSS
  43. * @param loadFirst : boolean => if true the first CSS will be loaded
  44. */
  45. CSSLoader.prototype.drawButtons = function (loadFirst){
  46. tb = new ToolBar(this.container.id, 200, null, "simpleBar");
  47. for(var src in this.sheets){
  48. bt = new TextButton(src, this.sheets[src], null, true, null, null, this.chooseByLink);
  49. bt.getDom().cssL = this;
  50. tb.addButton(bt);
  51. }
  52. if(loadFirst)
  53. ek.requireCSS(this.cssId, this.defaultCSS, true);
  54. }
  55. /**
  56. * Create and draw some links to allow to change the current CSS
  57. * @param loadFirst : boolean => if true the first CSS will be loaded
  58. */
  59. CSSLoader.prototype.drawLinks = function (loadFirst){
  60. for(var src in this.sheets){
  61. var br = Dom.createHTMLBRElement();
  62. var a = Dom.createHTMLAnchorElement(this.sheets[src], null, null, null, this.sheets[src]);
  63. //Attach model
  64. a.cssL = this;
  65. //Attahc onclick action method
  66. a.onclick = this.chooseByLink;
  67. this.container.appendChild(a);
  68. this.container.appendChild(br);
  69. }
  70. if(loadFirst)
  71. ek.requireCSS(this.cssId, this.defaultCSS, true);
  72. }
  73. /**
  74. * Create and draw a combo bow to allow to change the current CSS
  75. * @param loadFirst : boolean => if true the first CSS will be loaded
  76. */
  77. CSSLoader.prototype.drawCombo = function (loadFirst){
  78. var select = Dom.createHTMLSelectElement();
  79. //Attach model
  80. select.cssL = this;
  81. //Attach onchange action method
  82. select.onchange = this.chooseByCombo;
  83. this.container.appendChild(select);
  84. for(var src in this.sheets){
  85. var o = Dom.createHTMLOptionElement(this.sheets[src], src);
  86. select.appendChild(o);
  87. }
  88. if(loadFirst)
  89. ek.requireCSS(this.cssId, this.defaultCSS, true);
  90. }
  91. /**
  92. * Called when a link was clicked to change the current CSS.
  93. * @param e the click event
  94. * @private
  95. */
  96. CSSLoader.prototype.chooseByLink = function (e){
  97. ek.requireCSS(this.cssL.cssId, this.id, true);
  98. }
  99. /**
  100. * Called when the selection of the combo box has changed to change the current CSS.
  101. * @param e the change event
  102. * @private
  103. */
  104. CSSLoader.prototype.chooseByCombo = function (e){
  105. ek.requireCSS(this.cssL.cssId, this.options[this.selectedIndex].value, true);
  106. }