קוד:
<script type="text/javascript">
<!--
var topMenu = function(obj)
{
this.tree = new Array();
this.object = document.getElementById(obj);
this.i = '';
var obj = this;
this.cat = document.createElement('<div>');
this.cat.className = 'topnavigation';
this.catUl = document.createElement('ul');
this.subCat = document.createElement('<div>');
this.subCat.className = 'topnavigation';
this.subCatUl = document.createElement('ul');
this.addCat = function(catName, catValue, currect) {
this.tree[catName] = new Array();
this.tree[catName]['value'] = catValue;
this.tree[catName]['currect'] = (currect)?true:false;
}
this.addLink = function(catName, subCatValue, link, currect) {
if(subCatValue == 'value' || subCatValue == 'currect')
return false;
this.tree[catName][subCatValue] = new Array();
this.tree[catName][subCatValue]['value'] = subCatValue;
this.tree[catName][subCatValue]['link'] = link;
this.tree[catName][subCatValue]['currect'] = (currect)?true:false;
}
this.init = function() {
var curCat = new Array();
counter = 1;
for(i in this.tree) {
if(this.tree[i]['currect']) {
curCat[counter] = document.createElement('li');
curCat[counter].onclick = function () {obj.switchCat(i, obj)};
curCat[counter].className = "current";
curCat[counter].innerHTML = '<a href="#">'+this.tree[i]['value']+'</a>';
this.catUl.appendChild(curCat[counter]);
//cat += '<li onclick=\''+obName+'.switchCat("'+i+'", obName)\' class="current"><a href="#">'+this.tree[i]['value']+'</a></li>';
for(i2 in this.tree[i]) {
if(i2 == 'currect' || i2 == 'value')
continue;
if(this.tree[i][i2]['currect'])
this.subCatUl.innerHTML += '<li class="current"><a href="'+this.tree[i][i2]['link']+'">'+this.tree[i][i2]['value']+'</a></li>';
else
this.subCatUl.innerHTML += '<li><a href="'+this.tree[i][i2]['link']+'">'+this.tree[i][i2]['value']+'</a></li>';
}
continue;
}
curCat[counter] = document.createElement('li');
curCat[counter].onclick = function () {obj.switchCat(i, obj)};
curCat[counter].innerHTML = '<a href="#">'+this.tree[i]['value']+'</a>';
this.catUl.appendChild(curCat[counter]);
//cat += '<li onclick=\''+obName+'.switchCat("'+i+'", obName)\'><a href="#">'+this.tree[i]['value']+'</a></li>';
counter++;
}
//cat += '</ul></div>';
//mySubCat += '</ul></div>';
//alert("Cat:\n"+cat+"\nSubCat:\n"+mySubCat);
//this.object.innerHTML = cat+"\n"+mySubCat;
this.cat.appendChild(this.catUl);
this.subCat.appendChild(this.subCatUl);
this.object.appendChild(this.cat);
this.object.appendChild(this.subCat);
}
this.switchCat = function(catName, object) {
alert(object);
alert(catName);
object.object.removeChild(this.cat);
object.object.removeChild(this.subCat);
object.subCatUl.innerHTML = '';
object.cat.removeChild(this.catUl);
object.catUl = document.createElement('ul');
for(i in object.tree)
object.tree[i]['currect'] = false;
object.tree[catName]['currect'] = true;
object.init();
}
}
//-->
</script>
קוד:
var nav = new topMenu('tabs', 'nav')
nav.addCat('cours', 'קורסים', true);
nav.addLink('cours', 'דוגמא 1', '#', true);
nav.addLink('cours', 'דוגמא 2', '#', false);
nav.addLink('cours', 'דוגמא 3', '#', false);
nav.addLink('cours', 'דוגמא 4', '#', false);
nav.addCat('col', 'קואליציות', false);
nav.addLink('col', 'דוגמא 1', '#', false);
nav.addLink('col', 'דוגמא 2', '#', false);
nav.addLink('col', 'דוגמא 3', '#', false);
nav.addLink('col', 'דוגמא 4', '#', false);
nav.addLink('col', 'דוגמא 5', '#', false);
nav.addCat('learn', 'השתלמות', false);
nav.addLink('learn', 'דוגמא 1', '#', false);
nav.addLink('learn', 'דוגמא 2', '#', false);
nav.addLink('learn', 'דוגמא 3', '#', false);
nav.addCat('exsist', 'נוכחות', false);
nav.addLink('exsist', 'דוגמא 1', '#', false);
nav.addLink('exsist', 'דוגמא 2', '#', false);
nav.addCat('forum', 'פורום', false);
nav.addLink('forum', 'דוגמא 1', '#', false);
nav.addLink('forum', 'דוגמא 2', '#', false);
nav.addLink('forum', 'דוגמא 3', '#', false);
nav.addLink('forum', 'דוגמא 4', '#', false);
nav.addLink('forum', 'דוגמא 5', '#', false);
nav.addLink('forum', 'דוגמא 6', '#', false);
nav.init();