// menu
function menu() {
this.menuName = new map();
this.menuUrl = new map();
this.className = "";
this.addMenu = function(code, name, url) {
this.menuName.put(code, name);
this.menuUrl.put(code, url);
}
this.getMenu = function(code) {
var res = "";
var codeList = this.menuName.getSub(code);
for(var i=0; i<codeList.length; i++) {
var name = this.menuName.get(codeList[i]);
res += ((res == "") ? "" : " | ") + "<a href=\"javascript:" + this.className + ".goMenu('" + codeList[i] + "')\">" + name + "</a>";
}
return res;
}
this.goMenu = function(code) {
var lastCode = code;
location.href = this.menuUrl.get(code);
}
function map() {
var mapVal = {};
var pos = new Array();
this.get = function(key) {
return mapVal[key];
}
this.getPos = function(n) {
return mapVal[pos[n]];
}
this.getSub = function(code) {
var tmpList = new Array();
for(var i=0; i<pos.length; i++) {
if((pos[i].indexOf(code) == 0) && (pos[i] != code)) {
tmpList.push(pos[i]);
}
}
return tmpList;
}
this.put = function(key, val) {
mapVal[key] = val;
pos.push(key);
}
this.size = function() {
return pos.length;
}
}
}
var tchMenu = new menu();
tchMenu.className = "tchMenu";
tchMenu.addMenu("T01", "학습관리", "");
tchMenu.addMenu("T01S01", "테스트 조회", "/TCH/EXM/paper_list.htm");
tchMenu.addMenu("T01S02", "테스트 출제", "/TCH/EXM/make_paper.htm");
document.write(tchMenu.getMenu("T01"));
'Front-Html > Javascript' 카테고리의 다른 글
javascript 배열을 이용한 select box 2개 연결 (1) | 2010.04.09 |
---|---|
javascript 실시간 유동적 시간 변경 (1) | 2010.04.09 |
javascript calendar.js (1) | 2010.04.09 |
javascript lightbox lib (2) | 2010.04.09 |
Paging.js (2) | 2010.04.07 |