百度空间 | 百度首页 
 
查看文章
 
树状菜单的生成(2)
2007-06-18 15:30
function TabSet_Add(title,div){
   if(!div)return;
   if(div.parentNode)
       div.parentNode.removeChild(div);
   this.appendChild(div);
   div.style.borderWidth=1;
   div.style.borderStyle='solid';
   div.style.display='none';
   var tabtd = getDocument(this).createElement('td');
   this.HeaderRow.appendChild(tabtd);

   var tabplace=new Div(tabtd);
   var button=new Link(tabplace);
   button.innerHTML='  '+title+'  ';
   button.href='#';
   button.style.textDecoration='none';

   tabplace.style.borderWidth=1;
   tabplace.style.borderStyle='solid';
   tabplace.style.borderBottomWidth=0;
   tabplace.style.position = 'relative';
   tabplace.style.zIndex = 2;
   

   this.Buttons[this.Buttons.length]=button;
   button.tab=div;
   button.tabtd=tabtd;
   div.tabbutton=button;
   div.Index=this.Items.length;
   this.Items[this.Items.length]=div;
   button.owner=this;
   button.tabplace=tabplace;
   button.onclick=TabSet_ButtonClick;

}
function TabSet_ButtonClick(){
this.tab.style.display='block';
if(this.owner.SelectTab)   
    if(this.owner.SelectTab!=this.tab){
      this.owner.SelectTab.style.display='none';
    this.owner.SelectTab.tabbutton.parentNode.style.backgroundColor='';
//      this.owner.SelectTab.tabbutton.style.fontSize=12;
      this.owner.SelectTab.tabbutton.tabplace.style.padding=0;
    }
this.owner.SelectTab=this.tab;
this.owner.SelectIndex=this.tab.Index;

this.parentNode.style.backgroundColor=clWhite;
this.tabplace.style.padding=2;
if(this.owner.OnTabChange)this.owner.OnTabChange(this.owner,this.tab.Index);

// this.style.fontSize=16;
}
function TabSet_GetSelectTab(){
return this.SelectTab;
}

function TabSet_GetSelectIndex(){
if(this.SelectTab)
    return this.SelectTab.Index;
}

function TabSet_SetSelectIndex(i){
    if(isInspect)return;
    if(i==null)i=0;
    var button=this.Buttons[i];
    if(button){
        if(isIE)
        button.click();
        else
        button.onclick();
    }
}

function TabSet_SetSelectTab(i){
    var tab=this.Items[i];
    if(tab){
        if(isIE)
        tab.tabbutton.click();
        else
        tab.tabbutton.onclick();
    }
}

//进度条
function ProgressBar(parent)
{
obj=new Div(parent);
obj.ProgressBar=new Div(obj);
obj.Step=0.1;
obj.ProgressBar.style.backgroundColor=clMaroon;
obj.ProgressBar.style.width = "0%";
obj.ProgressBar.style.height = "100%";
obj.style.borderWidth=1;
obj.style.borderStyle='solid';

obj.SetStep=ProgressBar_SetStep;
return obj;
}
function ProgressBar_SetStep(step){
if(step>100)step=100;
this.Step=step;
this.ProgressBar.style.width =step+"%";
}

//GroupBox
function GroupBox(parent)
{
obj=new Div(parent);
obj.Container=new Div(obj);
obj.Container.style.width = "95%";
obj.Container.style.height = "95%";
obj.Container.style.borderWidth=1;
obj.Container.style.borderStyle='solid';
obj.TitleLabel=new Span(obj);
obj.TitleLabel.innerHTML="Group";
obj.TitleLabel.style.position='absolute';
obj.TitleLabel.style.left=10;
obj.TitleLabel.style.top=-8;
obj.TitleLabel.style.backgroundColor=clWhite;
return obj;
}
//Line
function Line(parent)
{
var pdiv,obj=getDocument(parent).createElement('hr');//创建一个控制节点
if(parent){pdiv=parent;}else pdiv=getDocument(parent).body;//获取父块
pdiv.appendChild(obj);
obj.oncontextmenu=div_oncontextmenu;

obj.size=1;
obj.color=clBlack;
return obj;
}

//RadioGroup
function RadioGroup(parent){//构造函数   
    var pdiv,obj=getDocument(parent).createElement('div');//创建一个控制节点
    if(parent){pdiv=parent;}else pdiv=getDocument(parent).body;//获取父块
    pdiv.appendChild(obj);
    obj.Button=new Array(); //单选按钮radio
    obj.Span=new Array(); //标签
    obj.value;
    obj.Items=new Strings();
    obj.Values=new Strings();
    obj.SubDiv=new Array();//容纳radio的子块
    obj.OnClick=RadioGroup_onclick; //radion的onclick事件
    obj.Show=DBRG_createradio;//创建radio   
    obj.removeradios=DBRG_removeradios;
    obj.oncontextmenu=div_oncontextmenu;
    return obj;
}
function RadioGroup_createradio(){ //创建子块和radio,标签
if(this.FrameDiv)this.removeradios();
var item=this.Items.Strings;
var values=this.Values.Strings;
this.FrameDiv=getDocument(this).createElement('div');
this.appendChild(this.FrameDiv);//把子块添加到大块中       
for(var i=0;i<item.length;i++){
    this.Button[i]=getDocument(this).createElement('input');
    this.SubDiv[i]=getDocument(this).createElement('div');
    this.Span[i]=getDocument(this).createElement('span');
    this.FrameDiv.appendChild(this.SubDiv[i]);    //把子块添加到大块中       
    this.Button[i].type="radio";    
    if(!values[i])values[i]=item[i];
    this.Button[i].value=values[i];
    this.Span[i].innerText=item[i];//显示标签               
    this.Button[i].parent=this;               
    this.Button[i].onclick=this.OnClick;//添加onclick事件
    this.SubDiv[i].appendChild(this.Button[i]);//向子块中添加radio
    this.SubDiv[i].appendChild(this.Span[i]);//添加标签       
}       
}
function RadioGroup_removeradios()
{
   this.removeChild(this.FrameDiv);
   this.FrameDiv.removeNode(true);
}
function RadioGroup_onclick(){
    for(var i=0;i<this.parent.Items.Strings.length;i++){
        this.parent.Button[i].checked=false; //置所有的radio为没选中
    }
    this.checked=true; //把当前发生onclick事件的radio设为选中
    this.parent.value=this.value;
    this.Select=this;
}

//Form
function Form(parent)//构造函数
{
var pdiv,obj=getDocument(parent).createElement("form");//创建一个控制节点
if(parent){pdiv=parent;}else pdiv=getDocument(parent).body;//获取父块
pdiv.appendChild(obj);
return obj;
}
//IFrame
function IFrame(parent,name)//构造函数
{
var xml="<iframe name="+name+" ></iframe>";
if(isMoz)
    xml="iframe";
var pdiv,obj=getDocument(parent).createElement(xml);//创建一个控制节点
if(parent){pdiv=parent;}else pdiv=getDocument(parent).body;//获取父块
pdiv.appendChild(obj);
obj.Show=IFrame_Show;
return obj;
}
function IFrame_Show(){
if(isMoz){
    this.contentWindow.document.write(this.contentWindow.document.body.innerHTML);
}
}
System.js:
var getsessionurl='servlet/getsession';

var Err_HasDets='Master table has detail data.please do it after while you delete details.';
var Err_OpenErr=':DataSet open error.SQL:';
var Err_NoOpen='DataSet is not opened.';
var Err_Null="Data can't be empty.";
var Err_Long='Data exceed the limit length.';
var Err_Number='Invalid number.';
var Err_DateTime='Invalid date/time.';
var Err_NoURL="The URL not found,or URL service error,return null.";
var Err_ReadOnly="Readonly state.";
var Err_NoField="Field not found.";
var Err_NoDataSet="No dataset.";
var clBlack = "#000000";
var clMaroon = "#000080";
var clGreen = "#008000";
var clOlive = "#008080";
var clNavy = "#800000";
var clPurple = "#800080";
var clTeal = "#808000";
var clGray = "#808080";
var clSilver = "#C6C3C6";
var clRed = "#FF0000";
var clLime = "#00FF00";
var clYellow = "#00FFFF";
var clBlue = "#0000FF";
var clFuchsia = "#FF00FF";
var clAqua = "#FFFF00";
var clLtGray = "#C0C0C0";
var clDkGray = "#808080";
var clWhite = "#FFFFFF";

var clMoneyGreen = "#C0DCC0";
var clSkyBlue = "#F0CAA6";
var clCream = "#F0FBFF";
var clMedGray = "#A4A0A0";

var clNone = "#FFFFFF";
var clDefault = "#CCCCFF";
var StandardColorsCount = 16;
var ExtendedColorsCount = 4;
var clBlue0='#9CBEE7';
var clButton='#CECFCE';
var clShadow="#ADAAAD";
var clHightGray = "#F7F3F7";
var clBorder = "#9C9A9C";


var DecPoint=".";

var jcl_ResourceURL = "treeview/";
var image_AppendRecord = "newrecord.gif";
var image_DeleteRecord = "deleterecord.gif";
var image_SaveRecord = "saverecord.gif";

var image_First = "image_first.gif";
var image_First_Disable = "image_first_disable.gif";

var isMoz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
var isIE = (typeof window.ActiveXObject != 'undefined');
var isInspect=true;

window.Exception=true;
if(window.opener)window.Parent=window.opener;
if(window.dialogArguments){window.Parent=window.dialogArguments;}
window.Show=function(url,title,ops){var bars;if(ops)bars=ops;else bars='menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes';return open(url,title,bars);}
window.ShowModal=function(url,ops){var o;if(ops)o=ops;else o='resizable:no';window.showModalDialog(url,window,o);}

function getDocument(object) {
var doc;
if(object)
    doc=object.ownerDocument
else doc=window.document;
return doc;
}
function GetXMLDOM() {
var xmlDoc;
if (isIE) {
     xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
} else if (isMoz) {
     xmlDoc = document.implementation.createDocument("","",null);
}
return xmlDoc;
}
//将字串XML对象化
function parseXML(st){
    var result;
    if(isIE){
        result = GetXMLDOM();
        result.loadXML(st);
    }else{
        var parser = new DOMParser();
        result = parser.parseFromString(st, "text/xml");
    }
    return result;
}
//将XML对象字符串化
function XMLToStr(xml){
    if(isIE){
        return xml.xml;
    }
    else{
        var xmls = new XMLSerializer();
        var s = xmls.serializeToString(xml);
        return s;
    }
}
function DateTimeToStr(d)
{
if(isNaN(d))return;
/*var y=d.getFullYear();var m=(d.getMonth()+1);var da=d.getDate();
var h=d.getHours();var mi=d.getMinutes();var sec=d.getSeconds();var ms=d.getMilliseconds();var s=y.toString()+'-';
if(m<10) s=s+'0';s=s+m+'-';if(da<10) s=s+'0';s=s+da+' ';
if(h||mi||sec||ms){if(h<10) s=s+'0';s=s+h+':';if(mi<10) s=s+'0';s=s+mi+':';if(sec<10) s=s+'0';s=s+sec+'.0';}
*/
var s = d.toLocaleString() ;
return s;
}
function DateToStr(d)
{
if(isNaN(d))return;
/*var y=d.getFullYear();var m=(d.getMonth()+1);var da=d.getDate();
var s=y.toString()+'-';
if(m<10) s=s+'0';s=s+m+'-';if(da<10) s=s+'0';s=s+da;
*/
var s = d.toLocaleString();
return s;
}
function StrToTimeLong(value) {
var r=/[\u4e00-\u9fa5]/;
value=value.replace(r, "/");
value=value.replace(r, "/");
value=value.replace(r, "");
var v=Date.parse(value);
return v;
}

function FormatFloat(value,mask)
{
    return BasicFormat(value,mask,'FormatNumber')
}
function FormatDate(varDate, bstrFormat, varDestLocale)
{
    return BasicFormat(varDate,bstrFormat,'FormatDate',varDestLocale);
}
function FormatTime(varTime, bstrFormat, varDestLocale)
{
    return BasicFormat(varTime,bstrFormat,'FormatTime',varDestLocale);
}
function BasicFormat(value,mask,action,param)
{
    var xmlDoc;
    var xslDoc;
    var v='<formats><format><value>'+value+'</value><mask>'+mask+'</mask></format></formats>';
    xmlDoc=parseXML(v);

    var x;
    if(isIE)
        x='<xsl:stylesheet xmlns:xsl="uri:xsl">'
    else
        x='<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">';
    x+='<xsl:template match="/">';
    if(isIE) {
        x+='<xsl:eval>'+action+'('+value+',"'+mask+'"';
        if(param)x+=','+param;
        x+=')</xsl:eval>';
    }
    else
        x+='<xsl:value-of select="format-number('+value+',\''+mask+'\')" />';

    x+='</xsl:template></xsl:stylesheet>';
    xslDoc=parseXML(x);
    var s;
    if(isIE)
    s= xmlDoc.transformNode(xslDoc)
    else{
        //for mozilla/netscape
        var processor = new XSLTProcessor();
        processor.importStylesheet(xslDoc);
        var result = processor.transformToFragment(xmlDoc, xmlDoc);
        var xmls = new XMLSerializer();
        s = xmls.serializeToString(result);
    }
    return s;
}
// 奇偶数判断
function isOddNumber(value)
{
var v = parseInt(value/2);
if(v*2!=value) return true
else return false;
}

//new Strings();
function Strings(){
this.Strings=new Array();
this.Count=0;
this.Add=function(v){var a=this.Strings;a[a.length]=v;this.Count=a.length};
this.Clear=function(){this.Strings.length=0;this.Count=0;};
}

function Items(parent){
// if(!type)type='items';
// var pdiv,obj = document.createElement(type);
this.Parent=parent;
// parent.appendChild(obj);
this.Item=new Array();
this.Count=0;
this.Add=Items_Add;
this.Clear=Items_Clear;
this.Delete=Items_Delete;
return this;
}
function Items_Add(item)
{
if(this.Parent)this.Parent.appendChild(item);
this.Item[this.Item.length]=item;
item.Index=this.Item.length-1;
item.Parent=this.Parent;
this.Count=this.Item.length;
}
function Items_Delete(item)
{
_arrayremove(this.Item,item.Index);
if(this.Parent)this.Parent.removeChild(item);
item.removeNode(true);
this.Count=this.Item.length;
}
function Items_Clear()
{
   for(var i=0;i<this.Item.length;i++){
       this.Delete(this.Item[i]);
   }
}


new Params();
Params.prototype.Count;
Params.prototype.Add=function(param){this.Param[param.Name]=param;this.Paramx[this.Paramx.length]=param;this.Count=this.Paramx.length;}
Params.prototype.Clear=function(){this.Paramx.length=0;this.Param=new Array();this.Count=0;}
function Params(){
this.Param=new Array();
this.Paramx=new Array();
}
new Param(null,null,null);
Param.prototype.Name;
Param.prototype.Value;
Param.prototype.Type;
function Param(name,value,type)
{
this.Name=name;this.Value=value;this.Type=type;
}
function jcl_err(e)
{
if(window.Exception){alert(e);}else throw e;
}

function DC_onpropertychange(sender)//属性变化处理
{
var n;
if(isIE) {
    n=event.propertyName;
    sender=this;
}
else
    n='DataSet';
switch(n){
    case 'DataSet':
    if(sender.OldDataSet==sender.DataSet)return;
    if(sender.OldDataSet)sender.OldDataSet.RemoveLink(sender);//从原来的DATASET中移除
      if(sender.DataSet)sender.DataSet.LinkObj(sender);
    sender.OldDataSet=sender.DataSet;
    break;
}
}

//增加函数定时侦听执行
function addEventTimerListener(obj,func){
    listenerFuncList[listenerFuncList.length]=func;
    listenerObjList[listenerObjList.length]=obj;
    return listenerFuncList.length-1;
}
//删除增加函数定时侦听执行
function removeEventTimerListener(index){
    _arrayremove(listenerFuncList, index);
    _arrayremove(listenerObjList, index);
}
//清除所有侦听执行
function clearEventTimerListener(index){
    listenerFuncList.length=0;
    listenerObjList.length=0;
}

//调用函数定时侦听执行
function processEventTimerListener(){
    for(var i=0;i<window.listenerFuncList.length;i++){
        listenerFuncList[i](listenerObjList[i]);
    }
}
//开始其他非IE浏览器属性变化侦听
function startEventListener(){
    window.listenerFuncList=new Array();
    window.listenerObjList=new Array();
    window.eventDelay=300;
    window.eventTimer=setInterval(processEventTimerListener, window.eventDelay);
}
//停止其他非IE浏览器属性变化侦听
function stopEventListener(){
    clearInterval(window.eventTimer);
}

if(isMoz){
    startEventListener();
}


//实现类反射封装
function Reflector()
{
    var obj = new Object();
    obj.getProperties=function(obj){
        var props = "";
        var type;
        for (idx in obj)
        {
            type = typeof(obj[idx]);
            if(type!='function')
               props += idx+":"+type+";";
        }
        return props;
    }
    obj.getMethods=function(obj){
        var props = "";
        var type;
        for (idx in obj)
        {
            type = typeof(obj[idx]);
            if(type=='function')
               props += idx+":"+type+";";
        }
        return props;
    }   
    obj.getMembers=function(obj){
        var props = "";
        var type;
        var member;
        var pos;
        for (idx in obj)
        {
            member = obj[idx];
            if(member) {
                type = typeof(obj[idx]);
                if(type=='function') {
                    member = member.toString();
                    pos = member.indexOf('(');
                    if(pos!=-1) {
                        member = member.substring(pos);
                        pos = member.indexOf(')');
                        if(pos!=-1)
                            member = member.substring(0,pos+1);
                    }
                    props += idx+":"+type+member+";";
                }
                else
                    props += idx+":"+type+";";
            }
        }
        return props;
    }   
    return obj;
}
function _arrayremove(changingarray,index){
    if(changingarray)    {

        var newarray1=changingarray.slice(0,index);
        var newarray2=changingarray.slice(index+1,changingarray.length);
        changingarray.length=0;
        changingarray=newarray1.concat(newarray2);
        return changingarray;
    }
}

function _arraypush(changingarray,newarraynode,index) {
   if ( changingarray ) {
     var newarray1 = changingarray.slice(0,index);
     var newarray2 = changingarray.slice(index,changingarray.length);
     newarray1[newarray1.length] = newarraynode;
     changingarray.length = 0;
     changingarray = newarray1.concat(newarray2);
     return changingarray;
}
}

function _arrayswap(changingarray,indexfirst,index) {
   if ( changingarray ) {
      var m=changingarray[indexfirst];
      changingarray[indexfirst] = changingarray[index];
      changingarray[index] = m;
   }
}

function VLine(parent)
{
var obj=new Div(parent);
obj.style.borderLeftStyle='solid';
obj.style.borderLeftWidth=1;
obj.style.position='absolute';
// obj.style.borderLeftColor='black';
return obj;
}
function HLine(parent)
{
var obj=new Div(parent);
obj.style.borderTopStyle='solid';
obj.style.borderTopWidth=1;
obj.style.position='absolute';
// obj.style.borderLeftColor='black';
return obj;
}
function Point(parent)
{
var obj=new HLine(parent);
obj.style.width = 1;
obj.style.height = 1;
return obj;
}

function Draw(parent)
{
if(parent){this.Parent=parent;}else this.Parent=document.body;//获取父块
this.LineTo=Draw_LineTo;
this.DashedTo1=Draw_DashedTo1;
return this;
}
function Draw_LineTo(x1,y1,x2,y2)
{
var xstep,ystep,point,x,y,obj=new Div(this.Parent);
obj.style.position='absolute';
x=x1;y=y1;
if(x2-x1>0)xstep=(y2-y1)/(x2-x1);else xstep=0;
if(y2-y1>0)ystep=(x2-x1)/(y2-y1);else ystep=0;
if(xstep>1)xstep=1;
if(ystep>1)ystep=1;

while (true)
{
    point=new Point(obj);
    point.style.left=x;
    point.style.top=y;
    y+=ystep;
    if(y2-y1>0)y+=2;
    x+=xstep;
    if(x2-x1>0)x+=2;
    if(x>=x2&&y>=y2)break;
}
return obj;
}
function Draw_DashedTo1(x1,y1,x2,y2)
{
var xstep,ystep,point,x,y,obj=new Div(this.Parent);
obj.style.position='absolute';
x=x1;y=y1;
if(x2-x1>0)xstep=(y2-y1)/(x2-x1);else xstep=0;
if(y2-y1>0)ystep=(x2-x1)/(y2-y1);else ystep=0;
if(xstep>1)xstep=1;
if(ystep>1)ystep=1;

while (true)
{
    point=new Point(obj);

    point.style.left=x;
    point.style.top=y;
    y+=ystep;
    if(y2-y1>0)y+=2;
    x+=xstep;
    if(x2-x1>0)x+=2;
    if(x>=x2&&y>=y2)break;
}
return obj;
}
function Rectangle(x,y,w,h){
this.x=x;this.y=y;this.width=w;this.height=h;
this.isContainXY=Rectangle_isContainXY;
}
function Rectangle_isContainXY(x,y){
var result=false;
if(x>this.x&&x<(this.x+this.width)&&y>this.y&&y<(this.y+this.height))
    result=true;
// alert(x+":"+y+":"+this.x+":"+this.y+"="+result);
return result;
}
function setStyle(obj)
{
// obj.style.borderStyle='solid';
// obj.style.borderWidth=1;
obj.style.fontFamily='Tahoma';
obj.style.fontSize='12';
}
function setFont(obj)
{
obj.style.fontFamily='Tahoma';
obj.style.fontSize='12';
obj.style.color=clBlack;
}


类别:Ajax | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu