/branches/jsdoc_tk_gui/setup/workingDirectory/Webeo/gui/menu/Menu.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 128 lines · 103 code · 22 blank · 3 comment · 16 complexity · f95da80a14dfbe77b53762800f01c8f9 MD5 · raw file

  1. ek.require("gui.layout.ToolBar");
  2. ek.register("gui.menu.Menu");
  3. ek.requireCSS("css.gui.menu.Menu", "menu.Menu");
  4. /**
  5. *
  6. */
  7. function Link (id, text, image){
  8. this.id = id;
  9. this.text = text;
  10. this.image = image;
  11. this.children = new Array();
  12. }
  13. function Menu (divName){
  14. this.mainUL = document.getElementById(divName);
  15. this.links = new Array();
  16. }
  17. Menu.prototype.read = function (){
  18. this.readULNode(this.mainUL, null);
  19. }
  20. Menu.prototype.readULNode = function (ulNode, parentLink){
  21. var liNodes = ulNode.childNodes;
  22. for(var i = 0 ; i < liNodes.length ; i++){
  23. if(liNodes[i] instanceof Text){
  24. continue;
  25. }else if(liNodes[i] instanceof HTMLLIElement){
  26. this.addLink(parentLink, liNodes[i]);
  27. }
  28. }
  29. }
  30. Menu.prototype.addLink = function (parentLink, liNode){
  31. var l ;
  32. if(parentLink == null){
  33. l = new Link("Menu_"+this.links.length, liNode.firstChild.textContent);
  34. this.links.push(l);
  35. }else{
  36. l = new Link(parentLink.id + "_" + parentLink.children.length, liNode.firstChild.textContent);
  37. parentLink.children.push(l);
  38. }
  39. children = liNode.childNodes;
  40. for(var i = 0 ; i < children.length ; i++){
  41. if(children[i] instanceof Text){
  42. continue;
  43. }else if(children[i] instanceof HTMLUListElement){
  44. this.readULNode(children[i], l);
  45. }
  46. }
  47. }
  48. Menu.prototype.draw = function (){
  49. this.mainUL.style.display = 'none';
  50. var menuDiv = document.createElement('div');
  51. menuDiv.setAttribute('id', this.mainUL.id+'_drawed');
  52. this.mainUL.parentNode.appendChild(menuDiv);
  53. this.toolbar = new ToolBar(menuDiv.id, 400, 50, "simpleBar");
  54. for(var i = 0 ; i < this.links.length ; i++){
  55. var bt = new TextButton(this.links[i].id, this.links[i].text, "", true)
  56. bt.initCSS("horizontal", "toggled");
  57. bt.domBT.onmouseover = this.getButtonOver;
  58. bt.domBT.onmouseout = this.getButtonOut;
  59. this.toolbar.addButton(bt);
  60. if(this.links[i].children.length>0){
  61. bt.domBT.sonsDom = this.drawWindow(this.links[i].children, this.links[i].id);
  62. this.toolbar.domBar.appendChild(bt.domBT.sonsDom);
  63. }
  64. }
  65. }
  66. Menu.prototype.drawWindow = function (children, idParent){
  67. var windowDiv = document.createElement('div');
  68. windowDiv.setAttribute('id', idParent + '_children');
  69. windowDiv.style.position = "absolute";
  70. windowDiv.style.top = "0px";
  71. windowDiv.style.left = "0px";
  72. windowDiv.style.width = "200px";
  73. for(var i = 0 ; i < children.length ; i++){
  74. var a = document.createElement("a");
  75. a.setAttribute("id", children[i].id);
  76. a.innerHTML = children[i].text;
  77. windowDiv.appendChild(a);
  78. a.container = windowDiv;
  79. a.onmouseover = this.getLinkOver;
  80. a.onmouseout = this.getLinkOut;
  81. if(children[i].children.length>0){
  82. a.childrenDom = this.drawWindow(children[i].children, children[i].id);
  83. windowDiv.appendChild(a.childrenDom);
  84. }
  85. }
  86. windowDiv.className = 'hidden';
  87. return windowDiv;
  88. }
  89. Menu.prototype.getButtonOver = function (){
  90. if(this.sonsDom)
  91. this.sonsDom.className = 'showed';
  92. }
  93. Menu.prototype.getButtonOut = function (){
  94. if(this.sonsDom)
  95. this.sonsDom.className = 'hidden';
  96. }
  97. Menu.prototype.getLinkOver = function (){
  98. this.container.className = 'showed';
  99. if(this.childrenDom)
  100. this.childrenDom.className = 'showed';
  101. }
  102. Menu.prototype.getLinkOut = function (){
  103. this.container.className = 'hidden';
  104. if(this.childrenDom)
  105. this.childrenDom.className = 'hidden';
  106. }