touch-layer icon indicating copy to clipboard operation
touch-layer copied to clipboard

Need a way to unbind event.

Open thomasyip opened this issue 15 years ago • 4 comments

There is a way to bind a touch-layer event, such as 'swipe'. But, there is no way to unbind it. (ie, gt('swipe', function() { ... });

thomasyip avatar Dec 06 '10 08:12 thomasyip

I made a patch on this, because I need it.

I am not sure calling onEnd is entirely correct in all cases. Please review. Thanks!

https://github.com/beedesk/touch-layer/commit/3af84685cddb9fe37ec367fda70ed88e3ebd2097

thomasyip avatar Dec 06 '10 08:12 thomasyip

Thanks for the report, it's a known "bug". Events get registered into an array, I just have to add the unbind method which traverses the array and remove the listeners.

cubiq avatar Dec 06 '10 09:12 cubiq

The link in my first comment included this patch. Hope this help. Thanks.

@@ -99,7 +99,40 @@ NL.prototype = {
        ...
    off: function (type, fn) {
        if (!type) {
            return;
        }

        var that = this;

        type = type.toLowerCase();

        if (!customEvents[type]) {
            return that;
        }

        var results = [];
        for (var i=(eventList.length - 1); i >= 0; i--) {
            if (this[0] == eventList[i].el[0]) {
                var events = eventList[i];
                if (events.type === events.type) {
                    if (!fn || events.fn === fn) {
                        results.push(events);
                        eventList.splice(i, 1);
                    }
                }
            }
        }
        for (var i=0, len=results.length; i

thomasyip avatar Dec 06 '10 20:12 thomasyip

It seems like this is still an open issue. Is there a planned fix? Thanks.

mzheng avatar Jun 02 '11 02:06 mzheng