/*
门面模式有助于简化常见的重复性任务,以及把经常相伴出现的常用函数组合在一起。
这个模式在DOM脚本编程这种需要面对各种不一致的浏览器接口的环境中很常用
*/
var DED = window.DED || {};
DED.util = {
getEvent: function(e){
return e || window.event;
},
getTarget: function(e){
return e.target || e.srcElement;
},
addEvent: function(el, type, fn){
if(window.addEventListener){
el.addEventListener(type, fn, false);
}else if(window.attachEvent){
el.attachEvent('on'+type, fn, false);
}else{
el['on'+type] = fn;
}
},
stopPropagation: function(e){
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
},
preventDefault: function(e){
if(window.preventDefault){
e.preventDefault();
}else{
e.returnValue = false;
}
},
stopEvent: function(e){
this.stopPropagation(e);
this.preventDefault(e);
}
}
门面模式有助于简化常见的重复性任务,以及把经常相伴出现的常用函数组合在一起。
这个模式在DOM脚本编程这种需要面对各种不一致的浏览器接口的环境中很常用
*/
var DED = window.DED || {};
DED.util = {
getEvent: function(e){
return e || window.event;
},
getTarget: function(e){
return e.target || e.srcElement;
},
addEvent: function(el, type, fn){
if(window.addEventListener){
el.addEventListener(type, fn, false);
}else if(window.attachEvent){
el.attachEvent('on'+type, fn, false);
}else{
el['on'+type] = fn;
}
},
stopPropagation: function(e){
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
},
preventDefault: function(e){
if(window.preventDefault){
e.preventDefault();
}else{
e.returnValue = false;
}
},
stopEvent: function(e){
this.stopPropagation(e);
this.preventDefault(e);
}
}