|
[plain] view plaincopyprint?
/**
* utils.js
* cheungmine
*/
if(!getElem){
var getElem=(function(){
return function(id){
return document.getElementById(id);
};
})();
}
if(!includeScript){
var includeScript=(function(){
return function(js){
document.write('<script type="text/javascript" src="'+js+'"></script>');
};
})();
}
if(!importScripts){
var importScripts=(function(globalEval){
var xhr=new XMLHttpRequest;
return function importScripts(){
var
args=Array.prototype.slice.call(arguments)
,len=args.length
,i=0
,meta
,data
,content
;
for(;i<len;i++){
if(args[i].substr(0,5).toLowerCase()==="data:"){
data=args[i];
content=data.indexOf(",");
meta=data.substr(5,content).toLowerCase();
data=decodeURIComponent(data.substr(content+1));
if(/;\s*base64\s*[;,]/.test(meta)){
data=atob(data);
}
if(/;\s*charset=[uU][tT][fF]-?8\s*[;,]/.test(meta)){
data=decodeURIComponent(escape(data));
}}else{
xhr.open("GET",args[i],false);
xhr.send(null);
data=xhr.responseText;
}
globalEval(data);
}
};
}(eval));
}
if(!usingScript){
var usingScript=(function(){
return function(js){
try{
includeScript(js);
}
catch(e){
importScripts(js);
}
};
})();
}
if(!getBrowserAgent){
var getBrowserAgent=(function(){
return function(){
if ((navigator.userAgent.indexOf('MSIE')>=0)&&(navigator.userAgent.indexOf('Opera')<0))
return "$IE";
else if (navigator.userAgent.indexOf('Firefox')>=0)
return "$FIREFOX";
else if (navigator.userAgent.indexOf('Opera')>=0)
return "$OPERA";
else if (navigator.userAgent.indexOf('Chrome')>=0)
return "$CHROME";
else
return navigator.userAgent;
};
})();
}
if(!extend_class__){
var extend_class__=(function(){
return function(deriveClass, baseClass) {
var base=new baseClass();
for (var m in base) {
deriveClass.prototype[m]=base[m];
}};
})();
}
if(!addEvent){
var addEvent=(function(){
if (document.addEventListener){
return function (el,type,fn){
if (el&&el.nodeName||el===window){
el.addEventListener(type,fn,false);
}else if(el&&el.length){
for(var i=0;i<el.length;i++){
addEvent(el[i],type,fn);
}}};
}else{
return function(el,type,fn){
if (el&&el.nodeName||el===window){
el.attachEvent('on'+type,function(){return fn.call(el,window.event);});
}else if(el&&el.length){
for(var i=0;i<el.length;i++){
addEvent(el[i],type,fn);
}}};
}})();
} |