Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update toucher.js #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions asset/toucher.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,48 @@
return this;
};

/**
* @method 删除事件监听
* @description 支持链式调用
*
* @param eventStr
* @param a
* @param b
* @returns {Touch}
*/
Touch.prototype.off = function OFF(eventStr,a,b){
var className,fn;
if(typeof(a) == 'string'){
className = a.replace(/^\./,'');
fn = b;
}else{
className = null;
fn = a;
}
//检测callback是否合法,事件名参数是否存在·
if(typeof(fn) == 'function' && eventStr && eventStr.length){
var eventNames = eventStr.split(/\s+/);

for(var i=0,total=eventNames.length;i<total;i++){

var eventName = eventNames[i];
//事件堆无该事件,创建一个事件堆
if(!this._events[eventName]){
this._events[eventName] = [];
return this;
}
for(var i = 0;i<this._events[eventName].length;i++){
if(this._events[eventName][i].fn == fn){
this._events[eventName].splice(i,1);
}
}
}
}

//提供链式调用的支持
return this;
};

//对外提供接口
return function (dom){
return new Touch(dom);
Expand Down