There is no variable to indicate the type of current browser named “window.ie”anymore in Mootools version 1.2, it is embarrassed that we use“Browser.Engine.trident” instead of, so I decide to make a enhancement to Mootools Version 1.2, the code is listed below:
/*************************************************
The enhancement of Browser of Mootools
*************************************************/
if(Browser.IE==null)
{
Browser.IE = navigator.userAgent.indexOf("MSIE")>0;
Browser.IE7Plus = Browser.IE && (/msie 7\.0/i.test(navigator.userAgent)||/msie 8\.0/i.test(navigator.userAgent));
Browser.IE8 = Browser.IE && /msie 8\.0/i.test(navigator.userAgent);
Browser.IE7 = Browser.IE && /msie 7\.0/i.test(navigator.userAgent);
Browser.IE6 = Browser.IE&!Browser.IE7Plus;
//Case sensitive?No!
Browser.ie = Browser.IE ;
Browser.ie7plus = Browser.IE7Plus ;
Browser.ie8 = Browser.IE8 ;
Browser.ie7 = Browser.IE7 ;
Browser.ie6 = Browser.IE6 ;
}
Further more, I am familiar with DHTML and I want to create a dynamic element more easily, so I wrap a new static function named “$c”(It means “creation”) to class “Element”, the source code is :
/*************************************************
The enhancement of Element of Mootools
*************************************************/
if(null!=Element && null==Element.$c)
{
Element.$c=function(tag,props,styles)
{
var newProps=null==props?{}:($type(props)=="string"?props.decodeJSON():props);
if(!newProps)newProps={};
if(null!=styles)
{
if($type(styles)=="string")
{
styles=styles.decodeJSON();
}
if(null!=newProps.styles)
{
newProps.styles=$merge(newProps.styles,styles);
}
else
{
newProps.styles=styles;
}
}
return new Element(tag,newProps);
}
}
I feel so bad when I migrating my source code from Internet Explorer to Firefox, because I can not using the famous function “$()” to select the form elements whose property “id” have not been set. I have to enhance the form objects, so the source code is :
if(null==JeasonZhao.$firefox)
{
JeasonZhao.$firefox=function()
{
if(!window.IE)
{
$A(document.getElementsByTagName("input")).each(function(item)
{
if((null==item.id||item.id.length<1) && null!=item.name)
{
item.id=item.name;
}
});
$A(document.getElementsByTagName("button")).each(function(item)
{
if((null==item.id||item.id.length<1) && null!=item.name)
{
item.id=item.name;
}
if(null==item.type||item.id.length<1)
{
item.type="button";
}
});
$A(document.getElementsByTagName("select")).each(function(item)
{
if((null==item.id||item.id.length<1) && null!=item.name)
{
item.id=item.name;
}
});
$A(document.getElementsByTagName("textarea")).each(function(item)
{
if((null==item.id||item.id.length<1) && null!=item.name)
{
item.id=item.name;
}
});
}
}//end of function JeasonZhao.makeFFCompatControl
window.addEvent("domready",JeasonZhao.$firefox);
}