2007年2月2日星期五

(javascript) Module.js


var Module = function(){
this.currentName = '';
this.previousName = '';
this.show = function(module){
if (this.currentName == module){return;};
try{
this[this.currentName].deconstruction();
}catch (e){};
try{
this[module].construction();
}catch (e){};
this.previousName = this.currentName;
this.currentName = module;
};
this.showPrevious = function(){
try{
this[this.currentName].showPreviousModule();
}catch (e){};
};
this.showNext = function(){
try{
this[this.currentName].showNextModule();
}catch (e){};
setTimeout('this.focus()', 10);
};
this.$new = function(){
try{
this[this.currentName].$new();
}catch (e){};
};
this.edit = function(){
try{
this[this.currentName].edit();
}catch (e){};
};
this.$delete = function(){
try{
this[this.currentName].$delete();
}catch (e){};
};
this.refresh = function(){
try{
this[this.currentName].refresh();
}catch (e){};
};
this.search = function(){
try{
this[this.currentName].search();
}catch (e){};
};
this.help = function(){
try{
this[this.currentName].help();
}catch (e){};
};
};

// Demo:
var HTBlog = new Module();
HTBlog.currentName = 'ArticleList';

HTBlog.ArticleList = new Object();
HTBlog.ArticleList.construction = function(){
$('moduleArticleList').style.display = '';
HTBlog.ArticleList.setStyle('on');
HTBlog.ArticleList.setButton();
HTBlog.ArticleList.setTitle();
};
HTBlog.ArticleList.deconstruction = function(){
HTBlog.ArticleList.setStyle('off');
$('moduleArticleList').style.display = 'none';
};

HTBlog.Article = new Object();
HTBlog.Article.construction = function(){
$('moduleArticle').style.display = '';
};
HTBlog.Article.deconstruction = function(){
$('moduleArticle').style.display = 'none';
};

// ...

没有评论:

发表评论