/*
* Function.prototype.bind 外置函数;
* 当连续bind事件的时候无法保证顺序;
*/
if(!Function.prototype.bind){
Function.prototype.bind = function(){
var args = Array.prototype.slice.call(arguments);
var _obj = args.shift();
var _fun = this;
return function(){
return _fun.apply(_obj,args.concat(Array.prototype.slice.call(arguments)));
};
};
}
var eventHandler = {
add:function(node,en,fu){
node.addEventListener ? node.addEventListener(en,fu,false) : node.attachEvent("on" + en, fu);
},
remove:function(node,en,fu){
node.removeEventListener ? node.removeEventListener(en,fu,false) : node.detachEvent("on" + en, fu);
},
guid:0,
bind:function(node,en,fu){
var _this = this;
fu = fu.bind(node);
_this.guid++;
if(!node.evenfun) node.evenfun = {};
if(!node.evenfun[en])node.evenfun[en] = {};
node.evenfun[en][_this.guid] = fu;
_this.add(node,en,node.evenfun[en][_this.guid]);
},
unbind:function(node,en){
var _this = this;
if(!node.evenfun || !node.evenfun.hasOwnProperty(en)) return;
for(var i in node.evenfun[en]){
_this.remove(node,en,node.evenfun[en][i]);
}
delete node.evenfun[en];
},
bindBn:function(node,en,fu){
var funame = fu.toString(),_this = this;
fu = fu.bind(node);
if(!node.evenfun) node.evenfun = {};
if(!node.evenfun[en])node.evenfun[en] = {};
node.evenfun[en][funame] = fu;
_this.add(node,en,node.evenfun[en][funame]);
},
unbindBn:function(node,en,name){
var _this = this;
name = name.toString();
if(!node.evenfun || !node.evenfun[en].hasOwnProperty(name)) return;
_this.remove(node,en,node.evenfun[en][name]);
delete node.evenfun[en][name];
}
}