用于js组件开发的js基类(模拟.net的WebControl的体系)(2)

  • 以下是组件支持文件 VmWebUI.js。
    /*
        Copyright (c) 2005 Vime. All rights reserved.
        Version 1.0.2.2
        
        对于Web组件的支持;
        需要先加载 VmSystem.js。
    */


    // 封装文本的字体属性。
    VmFontInfo  =   function ()
    {
        
    this .GetType  =   function  VmFontInfo_GetType()
        {
            
    return   " VmFontInfo " ;
        }
        
    this .Bold  =   false ;
        
    this .Italic  =   false ;
        
    this .Strikeout  =   false ;
        
    this .Underline  =   false ;
        
    this .Overline  =   false ;
        
    this .Name  =   "" ;
        
    this .Names  =   "" ;
        
    this .Size  =   "" ;
        
    this .CopyFrom  =   function  VmFontInfo_CopyFrom(f)
        {
            
    if ( ! VmFontInfo.prototype.isPrototypeOf(f))
                
    new  VmInterfaceException( " VmFontInfo.CopyFrom " , " VmFontInfo " ).Throw();
            
    this .Bold  =  f.Bold;
            
    this .Italic  =  f.Italic;
            
    this .Strikeout  =  f.Strikeout;
            
    this .Underline  =  f.Underline;
            
    this .Overline  =  f.Overline;
            
    this .Name  =  f.Name;
            
    this .Size  =  f.Size;
        }
        
    this .MergeWith  =   function  VmFontInfo_MergeWith(f)
        {
            
    if ( ! VmFontInfo.prototype.isPrototypeOf(f))
                
    new  VmInterfaceException( " VmFontInfo.MergeWith " , " VmFontInfo " ).Throw();
            
    if ( ! this .Bold)
                
    this .Bold  =  f.Bold;
            
    if ( ! this .Italic)
                
    this .Italic  =  f.Italic;
            
    if ( ! this .Strikeout)
                
    this .Strikeout  =  f.Strikeout;
            
    if ( ! this .Underline)
                
    this .Underline  =  f.Underline;
            
    if ( ! this .Overline)
                
    this .Overline  =  f.Overline;
            
    if ( this .Name  ==   "" )
                
    this .Name  =  f.Name;
            
    if ( this .Size  ==   "" )
                
    this .Size  =  f.Size;
        }
        
    this ._ParseStyle  =   function  VmFontInfo__ParseStyle(s)
        {
            
    var  xmlDoc  =   new  ActiveXObject( " Msxml2.DOMDocument " );
            
    try
            {
                xmlDoc.loadXML(s);
            }
            
    catch (e)
            {
                
    new  VmArgumentException( " 无法分析XML数据。 " , " s " ).Throw();
            }
            
    var  root  =  xmlDoc.documentElement;
            
    for ( var  i = 0 ;i < root.attributes.length;i ++ )
            {
                
    var  attr  =  root.attributes[i];
                
    switch (attr.nodeName)
                {
                    
    case   " Font-Bold " :
                        
    this .Bold  =  attr.value.toLowerCase() == " true " ;
                        
    break ;
                    
    case   " Font-Italic " :
                        
    this .Italic  =  attr.value.toLowerCase() == " true " ;
                        
    break ;
                    
    case   " Font-Strikeout " :
                        
    this .Strikeout  =  attr.value.toLowerCase() == " true " ;
                        
    break ;
                    
    case   " Font-Underline " :
                        
    this .Underline  =  attr.value.toLowerCase() == " true " ;
                        
    break ;
                    
    case   " Font-Overline " :
                        
    this .Overline  =  attr.value.toLowerCase() == " true " ;
                        
    break ;
                    
    case   " Font-Name " :
                        
    this .Name  =  attr.value;
                        
    break ;
                    
    case   " Font-Size " :
                        
    this .Size  =  attr.value;
                        
    break ;
                }
            }
        }
        
    this ._RenderStyle  =   function  VmFontInfo__RenderStyle(o)
        {
            
    var  s  =  o.style;
            
    if ( this .Bold)
                s.setAttribute(
    " fontWeight " , " bold " );
            
    if ( this .Italic)
                s.setAttribute(
    " fontStyle " , " italic " );
            
    if ( this .Strikeout)
                s.setAttribute(
    " textDecorationLineThrough " , this .Strikeout);
            
    if ( this .Underline)
                s.setAttribute(
    " textDecorationUnderline " , this .Underline);    
            
    if ( this .Overline)
                s.setAttribute(
    " textDecorationOverline " , this .Overline);
            
    if ( this .Name  !=   "" )
                s.setAttribute(
    " fontFamily " , this .Name);
            
    if ( this .Size  !=   "" )
                s.setAttribute(
    " fontSize " , this .Size);
        }
        
    this .Reset  =   function  VmFontInfo_Reset()
        {
            
    this .Bold  =   false ;
            
    this .Italic  =   false ;
            
    this .Strikeout  =   false ;
            
    this .Underline  =   false ;
            
    this .Overline  =   false ;
            
    this .Name  =   "" ;
            
    this .Names  =   "" ;
            
    this .Size  =   "" ;
        }
    }
    VmFontInfo.prototype 
    =   new  VmObject();


    // 指定组件的边框样式。
    VmBorderStyle  =   function ()
    {
        
    this .GetType  =   function  VmBorderStyle_GetType()
        {
            
    return   " VmFontInfo " ;
        }
        
    this .NotSet  =   " NotSet " ;
        
    this .None  =   " None " ;
        
    this .Dotted  =   " Dotted " ;
        
    this .Dashed  =   " Dashed " ;
        
    this .Solid  =   " Solid " ;
        
    this .Double  =   " Double " ;
        
    this .Groove  =   " Groove " ;
        
    this .Ridge  =   " Ridge " ;
        
    this .Inset  =   " Inset " ;
        
    this .Outset  =   " Outset " ;
        
    this ._Value  =   this .NotSet;
    }
    VmBorderStyle.prototype 
    =   new  VmEnum();


    // 指定容器中的项的水平对齐方式。
    VmHorizontalAlign  =   function ()
    {
        
    this .GetType  =   function  VmHorizontalAlign_GetType()
        {
            
    return   " VmHorizontalAlign " ;
        }
        
    this .NotSet  =   " NotSet " ;
        
    this .Left  =   " Left " ;
        
    this .Center  =   " Center " ;
        
    this .Right  =   " Right " ;
        
    this ._Value  =   this .NotSet;
    }
    VmHorizontalAlign.prototype 
    =   new  VmEnum();


    // 指定容器中的项的垂直对齐方式。
    VmVerticalAlign  =   function ()
    {
        
    this .GetType  =   function  VmVerticalAlign_GetType()
        {
            
    return   " VerticalAlign " ;
        }
        
    this .NotSet  =   " NotSet " ;
        
    this .Top  =   " Top " ;
        
    this .Middle  =   " Middle " ;
        
    this .Bottom  =   " Bottom " ;
        
    this ._Value  =   this .NotSet;
    }
    VmVerticalAlign.prototype 
    =   new  VmEnum();


    // 为在表格结构中显示项的控件指定网格线样式。
    VmGridLines  =   function ()
    {
        
    this .GetType  =   function  VmGridLines_GetType()
        {
            
    return   " VmGridLines " ;
        }
        
    this .None  =   " None " ;
        
    this .Horizontal  =   " Rows " ;
        
    this .Vertical  =   " Cols " ;
        
    this .Both  =   " All " ;
        
    this ._Value  =   this .None;
    }
    VmGridLines.prototype 
    =   new  VmEnum();


    // 表示组件的样式。
    VmStyle  =   function ()
    {
        
    this .GetType  =   function  VmStyle_GetType()
        {
            
    return   " VmStyle " ;
        }
        
    this .BackColor  =   "" ;
        
    this .BorderColor  =   "" ;
        
    this .BorderStyle  =   new  VmBorderStyle();;
        
    this .BorderWidth  =   "" ;
        
    this .CssClass  =   "" ;
        
    this .Font  =   new  VmFontInfo();
        
    this .ForeColor  =   "" ;
        
    this .Height  =   "" ;
        
    this .Width  =   "" ;
        
    this .CopyFrom  =   function  VmStyle_CopyFrom(s)
        {
            
    if ( ! VmStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmStyle.CopyFrom " , " VmStyle " ).Throw();
            
    this .BackColor  =  s.BackColor;
            
    this .BorderColor  =  s.BorderColor;
            
    this .BorderStyle  =  s.BorderStyle;
            
    this .BorderWidth  =  s.BorderWidth;
            
    this .CssClass  =  s.CssClass;
            
    this .Font  =  s.Font;
            
    this .ForeColor  =  s.ForeColor;
            
    this .Height  =  s.Height;
            
    this .Width  =  s.Width;
        }
        
    this .MergeWith  =   function  VmStyle_MergeWith(s)
        {
            
    if ( ! VmStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmStyle.MergeWith " , " VmStyle " ).Throw();
            
    if ( this .BackColor  ==   "" )
                
    this .BackColor  =  s.BackColor;
            
    if ( this .BorderColor  ==   "" )
                
    this .BorderColor  =  s.BorderColor;
            
    if ( this .BorderStyle.getValue()  ==   " NotSet " )
                
    this .BorderStyle  =  s.BorderStyle;
            
    if ( this .BorderWidth  ==   "" )
                
    this .BorderWidth  =  s.BorderWidth;
            
    if ( this .CssClass  ==   "" )
                
    this .CssClass  =  s.CssClass;
            
    this .Font.MergeWith(s.Font);
            
    if ( this .ForeColor  ==   "" )
                
    this .ForeColor  =  s.ForeColor;
            
    if ( this .Height  ==   "" )
                
    this .Height  =  s.Height;
            
    if ( this .Width  ==   "" )
                
    this .Width  =  s.Width;
        }
        
    this .RenderStyle  =   function  VmStyle_RenderStyle(o)
        {
            
    var  s  =  o.style;
            
    if ( this .BackColor  !=   "" )
                s.setAttribute(
    " backgroundColor " , this .BackColor.toLowerCase());
            
    if ( this .BorderColor  !=   "" )
                s.setAttribute(
    " borderColor " , this .BorderColor.toLowerCase());
            
            
    if ( this .BorderWidth != "" )
            {
                s.setAttribute(
    " borderWidth " , this .BorderWidth);
                
    if ( this .BorderStyle.getValue()  ==   " NotSet " )
                {
                    
    if ( this .BorderWidth.substr( 0 , 1 ) != " 0 " )
                        s.setAttribute(
    " borderStyle " , " solid " );
                }
                
    else
                {
                    s.setAttribute(
    " borderStyle " , this .BorderStyle.getValue().toLowerCase());
                }
            }
            
    else   if ( this .BorderStyle.getValue()  !=   " NotSet " )
            {
                s.setAttribute(
    " borderStyle " , this .BorderStyle.getValue().toLowerCase());
            }
            
    if ( this .ForeColor  !=   "" )
                s.setAttribute(
    " color " , this .ForeColor);
            
    if ( this .Height  !=   "" )
                s.setAttribute(
    " height " , this .Height);
            
    if ( this .Width  !=   "" )
                s.setAttribute(
    " width " , this .Width);
            
    this .Font._RenderStyle(o);
            
    if ( this .CssClass  !=   "" )
                o.setAttribute(
    " class " , this .CssClass);
        }
        
    this .ParseStyle  =   function  VmStyle_ParseStyle(s)
        {
            
    var  xmlDoc  =   new  ActiveXObject( " Msxml2.DOMDocument " );
            
    try
            {
                xmlDoc.loadXML(s);
            }
            
    catch (e)
            {
                
    new  VmArgumentException( " 无法分析XML数据。 " , " s " ).Throw();
            }
            
    var  root  =  xmlDoc.documentElement;
            
    for ( var  i = 0 ;i < root.attributes.length;i ++ )
            {
                
    var  attr  =  root.attributes[i];
                
    switch (attr.nodeName)
                {
                    
    case   " BackColor " :
                        
    this .BackColor  =  attr.value;
                        
    break ;
                    
    case   " BorderColor " :
                        
    this .BorderColor  =  attr.value;
                        
    break ;
                    
    case   " BorderStyle " :
                        
    this .BorderStyle.setValue(attr.value);
                        
    break ;
                    
    case   " BorderWidth " :
                        
    this .BorderWidth  =  attr.value;
                        
    break ;
                    
    case   " CssClass " :
                        
    this .CssClass  =  attr.value;
                        
    break ;
                    
    case   " ForeColor " :
                        
    this .ForeColor  =  attr.value;
                        
    break ;
                    
    case   " Height " :
                        
    this .Height  =  attr.value;
                        
    break ;
                    
    case   " Width " :
                        
    this .Width  =  attr.value;
                        
    break ;
                }
            }
            
    this .Font._ParseStyle(s);
        }
        
    this .Reset  =   function  VmStyle_Reset()
        {
            
    this .BackColor  =   "" ;
            
    this .BorderColor  =   "" ;
            
    this .BorderStyle.setValue( " NotSet " );
            
    this .BorderWidth  =   "" ;
            
    this .CssClass  =   "" ;
            
    this .Font.Reset();
            
    this .ForeColor  =   "" ;
            
    this .Height  =   "" ;
            
    this .Width  =   "" ;
        }
    }
    VmStyle.prototype 
    =   new  VmObject();


    //  TR 或 TD 元素的样式。
    VmTableItemStyle  =   function ()
    {
        
    this .GetType  =   function  VmTableItemStyle_GetType()
        {
            
    return   " VmTableItemStyle " ;
        }
        
    this .HorizontalAlign  =   new  VmHorizontalAlign();
        
    this .VerticalAlign  =   new  VmVerticalAlign();
        
    this .Wrap  =   true ;
        
    this .Style  =   new  VmStyle();
        
    this .CopyFrom  =   function  VmTableItemStyle_CopyFrom(s)
        {
            
    if ( ! VmTableItemStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmTableItemStyle.CopyFrom " , " VmTableItemStyle " ).Throw();
            
    this .HorizontalAlign  =  s.HorizontalAlign;
            
    this .VerticalAlign  =  s.VerticalAlign;
            
    this .Wrap  =  s.Wrap;
            
    this .Style  =  s.Style;
        }
        
    this .MergeWith  =   function  VmTableItemStyle_MergeWith(s)
        {
            
    if ( ! VmTableItemStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmTableItemStyle.MergeWith " , " VmTableItemStyle " ).Throw();
            
    if ( this .HorizontalAlign.getValue()  ==   " NotSet " )
                
    this .HorizontalAlign  =  s.HorizontalAlign;
            
    if ( this .VerticalAlign.getValue()  ==   " NotSet " )
                
    this .VerticalAlign  =  s.VerticalAlign;
            
    if ( this .Wrap)
                
    this .Wrap  =  s.Wrap;
            
    this .Style.MergeWith(s.Style);
        }
        
    this .RenderStyle  =   function  VmTableItemStyle_RenderStyle(o)
        {
            
    if ( this .HorizontalAlign.getValue()  !=   " NotSet " )
                o.setAttribute(
    " align " , this .HorizontalAlign.getValue().toLowerCase());
            
    if ( this .VerticalAlign.getValue()  !=   " NotSet " )
                o.setAttribute(
    " vAlign " , this .VerticalAlign.getValue().toLowerCase());
            
    if ( ! this .Wrap)
                o.setAttribute(
    " nowrap " , ! this .Wrap);
            
    this .Style.RenderStyle(o);
        }
        
    this .ParseStyle  =   function  VmTableItemStyle_ParseStyle(s)
        {
            
    var  xmlDoc  =   new  ActiveXObject( " Msxml2.DOMDocument " );
            
    try
            {
                xmlDoc.loadXML(s);
            }
            
    catch (e)
            {
                
    new  VmArgumentException( " 无法分析XML数据。 " , " s " ).Throw();
            }
            
    var  root  =  xmlDoc.documentElement;
            
    for ( var  i = 0 ;i < root.attributes.length;i ++ )
            {
                
    var  attr  =  root.attributes[i];
                
    switch (attr.nodeName)
                {
                    
    case   " HorizontalAlign " :
                        
    this .HorizontalAlign.setValue(attr.value);
                        
    break ;
                    
    case   " VerticalAlign " :
                        
    this .VerticalAlign.setValue(attr.value);
                        
    break ;
                    
    case   " Wrap " :
                        
    this .Wrap  =  attr.value;
                        
    break ;
                }
            }
            
    this .Style.ParseStyle(s);
        }
        
    this .Reset  =   function  VmTableItemStyle_Reset()
        {
            
    this .HorizontalAlign.setValue( " NotSet " );
            
    this .VerticalAlign.setValue( " NotSet " );
            
    this .Wrap  =   true ;
            
    this .Style.Reset();
        }
    }
    VmTableItemStyle.prototype 
    =   new  VmStyle();


    // 表示表控件的样式。
    VmTableStyle  =   function ()
    {
        
    this .GetType  =   function  VmTableStyle_GetType()
        {
            
    return   " VmTableStyle " ;
        }
        
    this .BackImageUrl  =   "" ;
        
    this .CellPadding  =   0 ;
        
    this .CellSpacing  =   0 ;
        
    this .GridLines  =   new  VmGridLines();
        
    this .HorizontalAlign  =   new  VmHorizontalAlign();
        
    this .Style  =   new  VmStyle();
        
    this .CopyFrom  =   function  VmTableStyle_CopyFrom(s)
        {
            
    if ( ! VmTableStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmTableStyle.CopyFrom " , " VmTableStyle " ).Throw();
            
    this .BackImageUrl  =  s.BackImageUrl;
            
    this .CellPadding  =  s.CellPadding;
            
    this .CellSpacing  =  s.CellSpacing;
            
    this .GridLines  =  s.GridLines;
            
    this .HorizontalAlign  =  s.HorizontalAlign;
            
    this .Style  =  s.Style;
        }
        
        
    this .MergeWith  =   function  VmTableStyle_MergeWith(s)
        {
            
    if ( ! VmTableStyle.prototype.isPrototypeOf(s))
                
    new  VmInterfaceException( " VmTableStyle.MergeWith " , " VmTableStyle " ).Throw();
            
    if ( this .BackImageUrl  ==   "" )
                
    this .BackImageUrl  =  s.BackImageUrl;
            
    if ( this .CellPadding  ==   "" )
                
    this .CellPadding  =  s.CellPadding;
            
    if ( this .CellSpacing  ==   "" )
                
    this .CellSpacing  =  s.CellSpacing;
            
    if ( this .GridLines.getValue()  ==   " None " )
                
    this .GridLines  =  s.GridLines;
            
    if ( this .HorizontalAlign.getValue()  ==   " NotSet " )
                
    this .HorizontalAlign  =  s.HorizontalAlign;
            
    this .Style.MergeWith(s.Style);
        }
        
    this .RenderStyle  =   function  VmTableItemStyle_RenderStyle(o)
        {
            
    var  s  =  o.style;
            
    if ( this .BackImageUrl  !=   "" )
                s.setAttribute(
    " backgroundImage " , this .BackImageUrl);
            
    if ( this .CellPadding  !=   "" )
                o.setAttribute(
    " cellpadding " , this .CellPadding);
            
    if ( this .CellSpacing  !=   "" )
                o.setAttribute(
    " cellSpacing " , this .CellSpacing);
            
    if ( this .GridLines.getValue()  !=   " None " )
                o.setAttribute(
    " rules " , this .GridLines.getValue().toLowerCase());
            
    if ( this .HorizontalAlign.getValue()  !=   " NotSet " )
                s.setAttribute(
    " align " , this .HorizontalAlign.getValue().toLowerCase());
            
    this .Style.RenderStyle(o);
        }
        
    this .ParseStyle  =   function  VmTableStyle_ParseStyle(s)
        {
            
    var  xmlDoc  =   new  ActiveXObject( " Msxml2.DOMDocument " );
            
    try
            {
                xmlDoc.loadXML(s);
            }
            
    catch (e)
            {
                
    new  VmArgumentException( " 无法分析XML数据。 " , " s " ).Throw();
            }
            
    var  root  =  xmlDoc.documentElement;
            
    for ( var  i = 0 ;i < root.attributes.length;i ++ )
            {
                
    var  attr  =  root.attributes[i];
                
    switch (attr.nodeName)
                {
                    
    case   " BackImageUrl " :
                        
    this .BackImageUrl  =  attr.value;
                        
    break ;
                    
    case   " CellPadding " :
                        
    this .CellPadding  =  attr.value;
                        
    break ;
                    
    case   " CellSpacing " :
                        
    this .CellSpacing  =  attr.value;
                        
    break ;
                    
    case   " GridLines " :
                        
    this .GridLines.setValue(attr.value);
                        
    break ;
                    
    case   " HorizontalAlign " :
                        
    this .HorizontalAlign.setValue(attr.value);
                        
    break ;
                }
            }
            
    this .Style.ParseStyle(s);
        }
        
    this .Reset  =   function  VmTableStyle_Reset()
        {
            
    this .BackImageUrl  =   "" ;
            
    this .CellPadding  =   0 ;
            
    this .CellSpacing  =   0 ;
            
    this .GridLines.setValue( " None " );
            
    this .HorizontalAlign.setValue( " NotSet " );
            
    this .Style.Reset();
        }
    }
    VmTableStyle.prototype 
    =   new  VmStyle();

    // 样式辅助
    VmStyleUtil  =   function ()
    {
        
    this .GetType  =   function  VmStyleUtil_GetType()
        {
            
    return   " VmStyleUtil " ;
        }
        
    this .ClearFontAttribute  =   function  VmStyleUtil_ClearFontStyle(o)
        {
            
    var  s  =  o.style;
            s.removeAttribute(
    " fontWeight " );
            s.removeAttribute(
    " fontStyle " );
            s.removeAttribute(
    " textDecorationLineThrough " );
            s.removeAttribute(
    " textDecorationUnderline " );
            s.removeAttribute(
    " textDecorationOverline " );
            s.removeAttribute(
    " fontFamily " );
            s.removeAttribute(
    " fontSize " );
        }
        
    this .ClearStyleAttribute  =   function  VmStyleUtil_ClearStyleAttribute(o)
        {
            
    var  s  =  o.style;
            s.removeAttribute(
    " backgroundColor " );
            s.removeAttribute(
    " borderColor " );
            s.removeAttribute(
    " borderWidth " );
            s.removeAttribute(
    " borderStyle " );
            s.removeAttribute(
    " color " );
            s.removeAttribute(
    " height " );
            s.removeAttribute(
    " width " );
            o.removeAttribute(
    " class " );
            
    this .ClearFontAttribute(o);
        }
        
    this .ClearTableItemStyleAttribute  =   function  VmStyleUtil_ClearTableItemStyleAttribute(o)
        {
            
    var  s  =  o.style;
            o.removeAttribute(
    " align " );
            o.removeAttribute(
    " vAlign " );
            o.removeAttribute(
    " nowrap " );
            
    this .ClearStyleAttribute(o);
        }
        
    this .ClearTableStyleAttribute  =   function  VmStyleUtil_ClearTableStyleAttribute(o)
        {
            
    var  s  =  o.style;
            s.removeAttribute(
    " backgroundImage " );
            o.removeAttribute(
    " cellpadding " );
            o.removeAttribute(
    " cellSpacing " );
            o.removeAttribute(
    " rules " );
            o.removeAttribute(
    " align " );
            
    this .ClearStyleAttribute(o);
        }
    }
    VmStyleUtil.prototype 
    =   new  VmObject();
    var  vmsu  =   new  VmStyleUtil();
    VmStyleUtil.ClearFontAttribute 
    =   function (o)
    {
        vmsu.ClearFontAttribute(o);
    }
    VmStyleUtil.ClearStyleAttribute 
    =   function (o)
    {
        vmsu.ClearStyleAttribute(o);
    }
    VmStyleUtil.ClearTableItemStyleAttribute 
    =   function (o)
    {
        vmsu.ClearTableItemStyleAttribute(o);
    }
    VmStyleUtil.ClearTableStyleAttribute 
    =   function (o)
    {
        vmsu.ClearTableStyleAttribute(o);
    }

你可能感兴趣的:(.net)