PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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