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

    第一次申请个blog,在博客园安个家。希望大家常来窜门~~
    这一段在编写DateEditor和配合使用的DatePicker的WebContorl,客户端使用htc实现。客户端的HTC组件通过 VimeJsFramework 实现强大的样式配制管理。

    以下是 ClassTree:

    vmframe.jpg

  • 以下是基本框架文件 VmSystem.js。
       
None.gif /*
None.gif    Copyright (c) 2005 Vime. All rights reserved.
None.gif    Version 1.0.1.18
None.gif    
None.gif    对象基类支持。
None.gif
*/
None.gif
None.gif
// 支持 VimeJsFramework 类层次结构中的所有类,并为派生类提供低级别服务。
None.gif

None.gifVmObject 
=   function ()
None.gif{
None.gif    
var  hashCode  =   null ;
None.gif    
this .GetHashCode  =   function  VmObject_GetHashCode()
None.gif    {
None.gif        
if (hashCode  == null )
None.gif            hashCode 
=  Math.round(Math.random() * 10000 );
None.gif        
return  hashCode;
None.gif    }
None.gif    
this .Equals  =   function  VmObject_Equals(o)
None.gif    {
None.gif        
if (VmObject.prototype.isPrototypeOf(o))
None.gif            
return  o.GetHashCode()  ==   this .GetHashCode();
None.gif        
new  VmInterfaceException( this .GetType(), this .GetType()).Throw();
None.gif    }
None.gif    
this .Dispose  =   function  VmObject_Dispose()
None.gif    {
None.gif    }
None.gif    
this .GetType  =   function  VmObject_GetType()
None.gif    {
None.gif        
return   " VmObject " ;
None.gif    }
None.gif    
// Protected 获得调用方法的名称
None.gif
     this ._GetFunctionName  =   function  VmObject__GetFunctionName(s)
None.gif    {
None.gif        
return  s.substr( 0 ,s.indexOf( " { " )).replace( " function  " , "" ).replace( " \r\n " , "" ).replace( " \t " , "" ).replace( "   " , "" ).replace( " _ " , " . " ).replace( " _ " , "" );
None.gif    }
None.gif};
None.gifVmObject.prototype 
=   new  Object();
None.gifVmObject.Equals 
=   function  VmObject_Equals_(oa,ob)
None.gif{
None.gif    
if ( ! VmObject.prototype.isPrototypeOf(oa))
None.gif        
new  VmInterfaceException( " VmObject.Equals " , " VmObject " ).Throw();
None.gif    
if ( ! VmObject.prototype.isPrototypeOf(ob))
None.gif        
new  VmInterfaceException( " VmObject.Equals " , " VmObject " ).Throw();
None.gif    
return  oa.GetHashCode()  ==  ob.GetHashCode();
None.gif};
None.gifVmObject.prototype 
=   new  Object();
None.gif
None.gif
None.gif
// VimeJsFrameWrok 信息
None.gif
VmFrameWork  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmFrameWork_GetType()
None.gif    {
None.gif        
return   " VmFrameWork " ;
None.gif    }
None.gif}
None.gifVmFrameWork.prototype 
=   new  VmObject();
None.gifVmFrameWork.Version 
=   " 1.00 " ;
None.gifVmFrameWork.Author 
=   " vme " ;
None.gif
None.gif
None.gif
// 有关浏览器的信息
None.gif
VmBrowerInfo  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmBrowerInfo_GetType()
None.gif    {
None.gif        
return   " VmBrowerInfo " ;
None.gif    }
None.gif    
None.gif    
var  ua = navigator.userAgent;
None.gif    
this ._IsIE =   / msie / i.test(ua);
None.gif    
None.gif    
/ MSIE\s + ([ ^ \);] + )(\) | ;) / .test(ua);
None.gif    
this ._IEVersion = RegExp.$ 1 ;
None.gif    
None.gif    
this ._IsAboveVersion  =   function  _VmBrowerInfo_IsAboveVersion(v)
None.gif    {
None.gif        
var  nv  =  parseFloat( this ._IEVersion);
None.gif        
return  nv >= v;
None.gif    }
None.gif}
None.gifVmBrowerInfo.prototype 
=   new  VmObject();
None.gif
var  vmbi  =   new  VmBrowerInfo();
None.gifVmBrowerInfo.IsIE 
=  vmbi._IsIE;
None.gifVmBrowerInfo.IEVersion 
=  vmbi._IEVersion;
None.gifVmBrowerInfo.IsAboveVersion 
=   function (v)
None.gif{
None.gif    
return  vmbi._IsAboveVersion(v);
None.gif}
None.gif
None.gif
// 表示在程序执行期间发生的异常。
None.gif
VmException  =   function (s,m)
None.gif{
None.gif    
this .GetType  =   function  VmException_GetType()
None.gif    {
None.gif        
return   " VmException " ;
None.gif    }
None.gif    
this .getSource  =   function  VmException_getSource()
None.gif    {
None.gif        
return  s;
None.gif    }
None.gif    
this .getMessage  =   function  VmException_getMessage()
None.gif    {
None.gif        
return  m;
None.gif    }
None.gif    
this ._Throw  =   function  VmException__Throw(e)
None.gif    {
None.gif        
var  invokeTrace  =   new  Array();
None.gif        
var  o = this .Throw.caller;
None.gif        
while (o != null )
None.gif        {
None.gif            invokeTrace.push(
this ._GetFunctionName(o.toString()));
None.gif            o
= o.caller;
None.gif        }
None.gif        
var  deepthTab = "      " ;
None.gif        
var  invokeString  =   "" ;
None.gif        
while (invokeTrace.length > 0 )
None.gif        {
None.gif            invokeString 
+=  deepthTab  +  ((deepthTab.length == 4 ) ? "" : " " +  invokeTrace.pop()  +   " \r\n " ;
None.gif            deepthTab 
+= "    " ;
None.gif        }
None.gif        alert(e 
+   " \r\n\r\n错误源:  "   +   this .getSource()  +   " \r\n信息:  "   +   this .getMessage()  +   " \r\n调用堆栈: \r\n "   +  invokeString);
None.gif        
throw   this ;
None.gif    }
None.gif    
this .Throw  =   function  VmException_Throw()
None.gif    {
None.gif        
this ._Throw( this .GetType());
None.gif    }
None.gif};
None.gifVmException.prototype 
=   new  VmObject();
None.gif
None.gif
None.gif
// 不实现某类接口产生的异常。
None.gif
VmInterfaceException  =   function (s,i)
None.gif{
None.gif    
this .GetType  =   function  VmInterfaceException_GetType()
None.gif    {
None.gif        
return   " VmInterfaceException " ;
None.gif    }
None.gif    
this .getSource  =   function  VmInterfaceException_getSource()
None.gif    {
None.gif        
return  s;
None.gif    }
None.gif    
this .getMessage  =   function  VmInterfaceException_getMessage()
None.gif    {
None.gif        
return   " 不实现某类接口产生的异常。 "   +   " \r\n类接口:  "   +  i;
None.gif    }
None.gif    
this .Throw  =   function  VmInterfaceException_Throw()
None.gif    {
None.gif        
this ._Throw( this .GetType());
None.gif    }
None.gif};
None.gifVmInterfaceException.prototype 
=   new  VmException();
None.gif
None.gif
None.gif
// 在向方法提供的其中一个参数无效时引发的异常。
None.gif
VmArgumentException  =   function (s,a)
None.gif{
None.gif    
this .GetType  =   function  VmArgumentException_GetType()
None.gif    {
None.gif        
return   " VmArgumentException " ;
None.gif    }
None.gif    
this .getSource  =   function  VmArgumentException_getSource()
None.gif    {
None.gif        
return  s;
None.gif    }
None.gif    
this .getMessage  =   function  VmArgumentException_getMessage()
None.gif    {
None.gif        
return   " 无效的参数。 "   +   " \r\n参数名:  "   +  a;
None.gif    }
None.gif    
this .Throw  =   function  VmArgumentException_Throw()
None.gif    {
None.gif        
this ._Throw( this .GetType());
None.gif    }
None.gif}
None.gifVmArgumentException.prototype 
=   new  VmException();
None.gif
None.gif
// 当参数值超出调用的方法所定义的允许取值范围时引发的异常。
None.gif
VmArgumentOutOfRangeException  =   function (s,a)
None.gif{
None.gif    
this .GetType  =   function  VmArgumentOutOfRangeException_GetType()
None.gif    {
None.gif        
return   " VmArgumentOutOfRangeException " ;
None.gif    }
None.gif    
this .getSource  =   function  VmArgumentOutOfRangeException_getSource()
None.gif    {
None.gif        
return  s;
None.gif    }
None.gif    
this .getMessage  =   function  VmArgumentOutOfRangeException_getMessage()
None.gif    {
None.gif        
return   " 参数值超出调用的方法所定义的允许取值范围。 "   +   " \r\n参数名:  "   +  a;
None.gif    }
None.gif    
this .Throw  =   function  VmArgumentOutOfRangeException_Throw()
None.gif    {
None.gif        
this ._Throw( this .GetType());
None.gif    }
None.gif}
None.gifVmArgumentOutOfRangeException.prototype 
=   new  VmException();
None.gif
None.gif
None.gif
// 表示可按照索引单独访问的一组对象。
None.gif
VmCollectionBase  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmCollectionBase_GetType()
None.gif    {
None.gif        
return   " VmCollectionBase " ;
None.gif    }
None.gif    
var  c  =   new  Array();
None.gif    
this .getCount  =   function  VmCollectionBase_getCount()
None.gif    {
None.gif        
return  c.length;
None.gif    }
None.gif    
this .getItem  =   function  VmCollectionBase_getItem(index)
None.gif    {
None.gif        
if (index < 0   ||  index >= c.length)
None.gif            
new  VmArgumentOutOfRangeException( " VmCollectionBase.getItem " , " index " ).Throw();
None.gif        
return  c[index];
None.gif    }
None.gif    
this .setItem  =   function  VmCollectionBase_setItem(index,v)
None.gif    {
None.gif        
if (index < 0   ||  index >= c.length)
None.gif            
new  VmArgumentOutOfRangeException( " VmCollectionBase.setItem " , " index " ).Throw();
None.gif        c[index]
= v;
None.gif    }
None.gif    
this .Add  =   function  VmCollectionBase_Add(v)
None.gif    {
None.gif        
return  c.push(v) - 1 ;
None.gif    }
None.gif    
this .Clear  =   function  VmCollectionBase_Clear()
None.gif    {
None.gif        c.splice(
0 ,c.length);
None.gif    }
None.gif    
this .Contains  =   function  VmCollectionBase_Contains(v)
None.gif    {
None.gif        
return   this .indexOf(v) !=   - 1 ;
None.gif    }
None.gif    
this .IndexOf  =   function  VmCollectionBase_IndexOf(v)
None.gif    {
None.gif        
for ( var  j = 0 ;j < c.length;j ++ )
None.gif        {
None.gif            
if (c[j] == v)
None.gif                
return  j;
None.gif        }
None.gif        
return   - 1 ;
None.gif    }
None.gif    
this .Insert  =   function  VmCollectionBase_Insert(i,v)
None.gif    {
None.gif        
if (i < 0   ||  i >= c.length)
None.gif            
new  VmArgumentOutOfRangeException( " VmCollectionBase.Insert " , " index " ).Throw();
None.gif        c.splice(i,
0 ,v);
None.gif    }
None.gif    
this .Remove  =   function  VmCollectionBase_Remove(v)
None.gif    {
None.gif        
var  i = this .IndexOf(v);
None.gif        
if (i !=   - 1 )
None.gif            c.splice(i,
1 );
None.gif    }
None.gif    
this .RemoveAt  =   function  VmCollectionBase_RemoveAt(i)
None.gif    {
None.gif        
if (i < 0   ||  i >= c.length)
None.gif            
new  VmArgumentOutOfRangeException( " VmCollectionBase.RemoveAt " , " index " ).Throw();
None.gif        c.splice(i,
1 );
None.gif    }
None.gif}
None.gifVmCollectionBase.prototype 
=   new  VmObject();
None.gif
None.gif
None.gif
// 为枚举提供基类。
None.gif
VmEnum  =   function ()
None.gif{
None.gif    
this ._Value  =   "" ;
None.gif    
this .GetType  =   function  VmEnum_GetType()
None.gif    {
None.gif        
return   " VmEnum " ;
None.gif    }
None.gif    
this .setValue  =   function  VmEnum_setValue(name)
None.gif    {
None.gif        
this ._Value  =   this ._GetValue(name);
None.gif    }
None.gif    
this .getValue  =   function  VmEnum_getValue()
None.gif    {
None.gif        
return   this ._Value;
None.gif    }
None.gif    
this ._GetValue  =   function  VmEnum__GetValue(name)
None.gif    {
None.gif        
if ( this [name] == null )
None.gif            
new  VmArgumentOutOfRangeException( " VmEnum._GetValue " , " name " ).Throw();
None.gif        
return   this [name];
None.gif    }
None.gif}
None.gifVmEnum.prototype 
=   new  VmObject();
None.gif
None.gif
None.gif
// //为位枚举提供基类。
None.gif
VmFlagEnum  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmFlagEnum_GetType()
None.gif    {
None.gif        
return   " VmFlagEnum " ;
None.gif    }
None.gif    
this ._Value  =   0 ;
None.gif    
this .And  =   function  VmFlagEnum_Add(name)
None.gif    {
None.gif        
this ._Value  &=  parseInt( this ._GetValue(name));
None.gif    }
None.gif    
this .Or  =   function  VmFlagEnum_Or(name)
None.gif    {
None.gif        
this ._Value  |=  parseInt( this ._GetValue(name));
None.gif    }
None.gif    
this .Xor  =   function  VmFlagEnum_Xor(name)
None.gif    {
None.gif        
this ._Value  ^=  parseInt( this ._GetValue(name));
None.gif    }
None.gif}
None.gifVmFlagEnum.prototype 
=   new  VmEnum();
None.gifVmFlagEnum.And 
=   function  VmFlagEnum_And_(e1,e2)
None.gif{
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e1))
None.gif        
new  VmInterfaceException( " VmFlagEnum.And " , " VmFlagEnum " ).Throw();
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e2))
None.gif        
new  VmInterfaceException( " VmFlagEnum.And " , " VmFlagEnum " ).Throw();
None.gif    
return  e1.getValue()  &  e2.getValue();
None.gif}
None.gifVmFlagEnum.Or 
=   function  VmFlagEnum_Or(e1,e2)
None.gif{
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e1))
None.gif        
new  VmInterfaceException( " VmFlagEnum.Or " , " VmFlagEnum " ).Throw();
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e2))
None.gif        
new  VmInterfaceException( " VmFlagEnum.Or " , " VmFlagEnum " ).Throw();
None.gif    
return  e1.getValue()  |  e2.getValue();
None.gif}
None.gifVmFlagEnum.Xor 
=   function  VmFlagEnum_Xor_(e1,e2)
None.gif{
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e1))
None.gif        
new  VmInterfaceException( " VmFlagEnum.Xor " , " VmFlagEnum " ).Throw();
None.gif    
if ( ! VmFlagEnum.prototype.isPrototypeOf(e2))
None.gif        
new  VmInterfaceException( " VmFlagEnum.Xor " , " VmFlagEnum " ).Throw();
None.gif    
return  e1.getValue()  ^  e2.getValue();
None.gif}
None.gif
None.gif
None.gif
// 为事件的实现提供低级别服务。
None.gif
VmEvent  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmEvent_GetType()
None.gif    {
None.gif        
return   " VmEvent " ;
None.gif    }
None.gif    
var  c  =   new  VmCollectionBase();
None.gif    
this .AttachHandler  =   function  VmEvent_AttachHandler(h)
None.gif    {
None.gif        c.Add(h);
None.gif    }
None.gif    
this .RemoveHandler  =   function  VmEvent_RemoveHandler(h)
None.gif    {
None.gif        c.Remove(h);
None.gif    }
None.gif    
this .ActiveEvent  =   function  VmEvent_ActiveEvent(args)
None.gif    {
None.gif        
for ( var  i = 0 ; i < c.getCount(); i ++ )
None.gif        {
None.gif            
try
None.gif            {
None.gif                eval(c.getItem(i).toString() 
+   " (args) " );
None.gif            }
None.gif            
catch (e)
None.gif            {
None.gif                
new  VmException( " VmEvent " ,e.message).Throw();
None.gif            }
None.gif        }
None.gif    }
None.gif}
None.gifVmCollectionBase.prototype 
=   new  VmObject();
None.gif
None.gif
None.gif
// 事件的数据类
None.gif
VmEventArgs  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmEventArgs_GetType()
None.gif    {
None.gif        
return   " VmEventArgs " ;
None.gif    }
None.gif}
None.gifVmEventArgs.prototype 
=   new  VmObject();
None.gifVmEventArgs.getEmpty 
=   function  VmEventArgs_getEmpty_()
None.gif{
None.gif    
return   new  VmEventArgs();
None.gif}
None.gif
None.gif
None.gif
// 将一个字符串类型数据转换为另一个基本数据类型。
None.gif
VmConvert  =   function ()
None.gif{
None.gif    
this .GetType  =   function  VmConvert_GetType()
None.gif    {
None.gif        
return   " VmConvert " ;
None.gif    }
None.gif}
None.gifVmConvert.prototype 
=   new  VmObject();
None.gifVmConvert.ToInt 
=   function  VmConvert_ToInt_(op)
None.gif{
None.gif    
var  exp  =   /^ \s * [ - \ + ] ? \d + \s * $ / ;
None.gif    
if  (op.match(exp)  ==   null
None.gif        
return   null ;
None.gif    
var  num  =  parseInt(op,  10 );
None.gif    
return  (isNaN(num)  ?   null  : num);
None.gif}
None.gifVmConvert.ToDouble 
=   function  VmConvert_ToDouble_(op)
None.gif{
None.gif    
var  exp  =   new  RegExp( " ^\\s*([-\\+])?(\\d+)?(\\.(\\d+))?\\s*$ " );
None.gif    
var  m  =  op.match(exp);
None.gif    
if  (m  ==   null )
None.gif        
return   null ;
None.gif    
var  cleanInput  =  m[ 1 +  (m[ 2 ].length > 0   ?  m[ 2 ] :  " 0 " +   " . "   +  m[ 4 ];
None.gif    
var  num  =  parseFloat(cleanInput);
None.gif    
return  (isNaN(num)  ?   null  : num); 
None.gif}
None.gifVmConvert.ToCurrency 
=   function  VmConvert_ToCurrentcy_(op,digits)
None.gif{
None.gif    
var  exp  =   new  RegExp( " ^\\s*([-\\+])?(((\\d+)\\,)*)(\\d+) "
None.gif                        
+  ((digits  >   0 ?   " (\\.(\\d{1, "   +  val.digits  +   " }))? "  :  "" )
None.gif                        
+   " \\s*$ " );
None.gif    
var  m  =  op.match(exp);
None.gif    
if  (m  ==   null )
None.gif        
return   null ;
None.gif    
var  intermed  =  m[ 2 +  m[ 5 ] ;
None.gif    
var  cleanInput  =  m[ 1 +  intermed.replace( new  RegExp( " (\\,) " " g " ),  "" +  ((digits  >   0 ?   " . "   +  m[ 7 ] :  0 );
None.gif    
var  num  =  parseFloat(cleanInput);
None.gif    
return  (isNaN(num)  ?   null  : num);       
None.gif}
None.gifVmConvert.ToDate 
=   function  VmConvert_ToConvert_(op,dateorder)
None.gif{
None.gif    
function  GetFullYear(year) {
None.gif        
return  (year  +   1900 );
None.gif    }
None.gif    
var  yearFirstExp  =   new  RegExp( " ^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$ " );
None.gif    
var  m  =  op.match(yearFirstExp);
None.gif    
var  day, month, year;
None.gif    
if  (m  !=   null   &&  (m[ 2 ].length  ==   4   ||  dateorder  ==   " ymd " ))
None.gif    {
None.gif        day 
=  m[ 6 ];
None.gif        month 
=  m[ 5 ];
None.gif        year 
=  (m[ 2 ].length  ==   4 ?  m[ 2 ] : GetFullYear(parseInt(m[ 3 ],  10 ))
None.gif    }
None.gif    
else
None.gif    {
None.gif        
if  (dateorder  ==   " ymd " )
None.gif        {
None.gif            
return   null ;
None.gif        }
None.gif        
var  yearLastExp  =   new  RegExp( " ^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$ " );
None.gif        m 
=  op.match(yearLastExp);
None.gif        
if  (m  ==   null )
None.gif        {
None.gif            
return   null ;
None.gif        }
None.gif        
if  (dateorder  ==   " mdy " )
None.gif        {
None.gif            day 
=  m[ 3 ];
None.gif            month 
=  m[ 1 ];
None.gif        }
None.gif        
else
None.gif        {
None.gif            day 
=  m[ 1 ];
None.gif            month 
=  m[ 3 ];
None.gif        }
None.gif        year 
=  (m[ 5 ].length  ==   4 ?  m[ 5 ] : GetFullYear(parseInt(m[ 6 ],  10 ))
None.gif    }
None.gif    month 
-=   1 ;
None.gif    
var  date  =   new  Date(year, month, day);
None.gif    
return  ( typeof (date)  ==   " object "   &&  year  ==  date.getFullYear()  &&  month  ==  date.getMonth()  &&  day  ==  date.getDate())  ?  date.valueOf() :  null ;
None.gif}
None.gif
None.gif


转载于:https://www.cnblogs.com/vme/archive/2005/02/01/100618.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值