📄 tv20.js
字号:
//=========================================
// 记录着树根
tv_topnodeitem = null ;
//=============================================================================
//数组,装着所有的节点
nodeitems = new Array() ;
nodeitem.prototype.show = nodeitem_show ;
nodeitem.prototype.refresh = nodeitem_refresh ;
nodeitem.prototype.boxclick = nodeitem_boxclick ;
nodeitem.prototype.close = nodeitem_close ;
nodeitem.prototype.open = nodeitem_open ;
nodeitem.prototype.remove = nodeitem_remove ;
nodeitem.prototype.setTag = nodeitem_setTag ;
nodeitem.prototype.getTag = nodeitem_getTag ;
function addNode( parentkey , key , lable , img ) {
return new nodeitem( parentkey , key , lable , img ) ;
}
//===============================================
//定义一个类:nodeitem
//lable:文本
//key:键
//parent:
//subitems:数组,装着所有儿子
//
//
//
//status------------------------1:two-direction 0:nobox 0: disactivite
// 2:three-0direction 1:close-box 1: activite
// 2:open-box
//===============================================
function nodeitem( parentkey , key , lable , img ) {
this.lable = lable ;
this.key = key ;
this.parent = findNode( parentkey ) ;
//如果找到父亲
if( this.parent != null ) {
aa = this.parent.status ;
if( aa.substring( 1 , 2 ) == "0" )
this.parent.status = aa.substring( 0 , 1 ) + "1" + aa.substring( 2 , 3 ) ;
if( this.parent.maxsubitem != null )
this.parent.maxsubitem.status = "2" + this.parent.maxsubitem.status.substring( 1 , 3 ) ;
this.parent.subitems[ this.parent.subitems.length ] = this ;
this.parent.maxsubitem = this ;
}
//如果没找到父亲
else {
if( tv_topnodeitem != null ) {
alert( "不能有两个顶项!" ) ;
return ;
}
tv_topnodeitem = this ;
}
this.img = img ;
this.tag = null ;
this.status = "100" ;
this.subitems = new Array() ;
//最后一个儿子
this.maxsubitem = null ;
//0
this.id = nodeitemRegister( this ) ;
//**********************
//this.questionId = 0;
//this.description = "";
//this.url = null;
//**********************
//added by msb for the sort and move up/down
/*if ( this == tv_topnodeitem )
{
this.nodeIndex = 0;
} else {
this.nodeIndex = this.parent.subitems.length;
}*/
//end added
}
//=============================================================================
//找到父亲
function findNode( key ) {
pppp = null;
for( i = 0 ; i < nodeitems.length ; i ++ ) {
if( nodeitems[ i ] != null ) {
if( nodeitems[ i ].key == key ) {
pppp = nodeitems[ i ] ;
}
}
}
return pppp ;
}
//注册一个nodeitem
function nodeitemRegister( obj ) {
nodeitems[ nodeitems.length ] = obj ;
return nodeitems.length - 1 ;
}
//=========================================
//Image List
//=========================================
treeview_box_0_none = "../images/4_clos.gif" ;
treeview_box_0_line = "../images/4_none.gif" ;
treeview_box_2_open = "../images/2_open.gif" ;
treeview_box_2_none = "../images/2_none.gif" ;
treeview_box_2_close = "../images/2_clos.gif" ;
treeview_box_1_open = "../images/3_open.gif" ;
treeview_box_1_none = "../images/3_none.gif" ;
treeview_box_1_close = "../images/3_clos.gif" ;
//==========================================================
// 显示树
function showTV() {
tv_topnodeitem.show() ;
}
//类nodeitem的show方法
function nodeitem_show() {
str = "<span id = 'preface" + this.id + "'><table border='1' cellspacing='0' cellpadding='0'><tr><td>" ;
str_f = "" ;
//缩进
for( j = this.parent ; j != null ; j = j.parent ) {
if( j.status.substring( 0 , 1 ) == 1 )
str_f = "<img src = '" + treeview_box_0_none + "' align='absmiddle' >" + str_f ;
else
str_f = "<img src = '" + treeview_box_0_line + "' align='absmiddle' >" + str_f ;
}
str = str + str_f ;
//根据状态头两位,判断向几个方向出头,判断是+号还是-号,
str += "<img id = 'box" + this.id + "' nodeid = '" + this.id + "' src = '" ;
switch( this.status.substring( 0 , 2 ) ) {
case "10" : str += treeview_box_1_none ; break ;
case "11" : str += treeview_box_1_close ; break ;
case "12" : str += treeview_box_1_open ; break ;
case "20" : str += treeview_box_2_none ; break ;
case "21" : str += treeview_box_2_close ; break ;
case "22" : str += treeview_box_2_open ; break ;
}
str += "' align='absmiddle' onclick='box_on_click(this)'>" ;
if( this.img == "" )
str += this.img ;
else
str += "<img src = '" + this.img + "' align='absmiddle' width='16' height='16'>" ;
str += "</td><td><table border='0' cellspacing='1' cellpadding='1' style='font-size:9pt; color:#333333' id='lablePanel" + this.id + "'><tr><td ondblclick = 'lable_on_dblclick(" + this.id + ")' onclick='lable_on_click(" + this.id + ")' style='cursor:hand' id='f_lablePanel" + this.id + "' nowrap>" + this.lable + "</td></tr></table></td></tr></table>" ;
str += "</span><span id = 'tv_panel_" + this.id + "' style='display:" ;
if( this.status.substring( 1 , 2 ) == '2' )
str += "" ;
else
str += "none" ;
str += "'></span>" ;
//显示出lai
if( this.parent == null )
for(var i in document.all){
if (document.all[i].tagName == "BODY")
{
document.all[i].insertAdjacentHTML( "AfterBegin" , str ) ;
break
}
}
else
//如果有父亲,加到以父亲的id命名的以tv_panel_开头的span,快要结束的位置
document.all( "tv_panel_" + this.parent.id ).insertAdjacentHTML( "BeforeEnd" , str ) ;
//递归调用儿子们的show方法
for(var m = 0 ; m < this.subitems.length ; m ++ ) {
if( this.subitems[ m ] != null ) {
this.subitems[ m ].show() ;
}
}
}
//=============================================================================
//暂时没用
//=============================================================================
//========================================
//Envrionment to hold Listeners
//========================================
tv_listeners = new Array() ;
function listener( type , handler ) {
this.type = type ;
this.handler = handler ;
this.id = tv_listeners.length ;
tv_listeners[ tv_listeners.length ] = this ;
}
function addListener( type , handler ) {
new listener( type , handler ) ;
}
//=== END =====
//===== END =======
//=== END =======
//=================================
//Custom a stack
//Class : stack
//metheds : get()
// put( obj )
//=================================
function stack() {
this.value = new Array() ;
this.cursor = 0 ;
}
function stack_get() {
this.cursor = this.cursor - 1 ;
return this.value[ this.cursor ] ;
}
function stack_put( obj ) {
this.value[ this.cursor ] = obj ;
this.cursor = this.cursor + 1 ;
}
stack.prototype.get = stack_get ;
stack.prototype.put = stack_put ;
//=======END ==========
//=========================================
// Define a public stack
//=========================================
userstack = new stack() ;
//====== END ===========
//===============================================
//Class : nodeitem
//status------------------------1:two-direction 0:nobox 0: disactivite
// 2:three-0direction 1:close-box 1: activite
// 2:open-box
//===============================================
function nodeitem( parentkey , key , lable , img ) {
this.lable = lable ;
this.key = key ;
this.parent = findNode( parentkey ) ;
if( this.parent != null ) {
aa = this.parent.status ;
if( aa.substring( 1 , 2 ) == "0" )
this.parent.status = aa.substring( 0 , 1 ) + "1" + aa.substring( 2 , 3 ) ;
if( this.parent.maxsubitem != null )
this.parent.maxsubitem.status = "2" + this.parent.maxsubitem.status.substring( 1 , 3 ) ;
this.parent.subitems[ this.parent.subitems.length ] = this ;
this.parent.maxsubitem = this ;
}
else {
if( tv_topnodeitem != null ) {
alert( "不能有两个顶项!" ) ;
return ;
}
tv_topnodeitem = this ;
}
this.img = img ;
this.tag = null ;
this.status = "100" ;
this.subitems = new Array() ;
this.maxsubitem = null ;
this.id = nodeitemRegister( this ) ;
//**********************
//this.questionId = 0;
//this.description = "";
//this.url = null;
//**********************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -