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

Mouse events keep firing after removal of icropper #3

Open
mschipperheyn opened this issue May 18, 2015 · 1 comment
Open

Mouse events keep firing after removal of icropper #3

mschipperheyn opened this issue May 18, 2015 · 1 comment

Comments

@mschipperheyn
Copy link

I'm seeing document based mouseevents that keep firing (and generating exceptions) even when references to icropper have been nulled.

@mschipperheyn
Copy link
Author

I resolved this by

 ,connect: function(node, evtType, context, callback){
        //TODO: use event listeners instead
        var self = this;
        function handler(evt){
            evt = self.fixEvent(evt);
            context[callback](evt);
        }
        if(node.attachEvent)node.attachEvent('on' + evtType, handler);
        else node.addEventListener(evtType, handler, false);

        context._handles.push({
            node:node,
            type:evtType,
            handler:handler
        });
    }

        ,destroy: function(){

        var ieListener = this.cropNode && this.cropNode.attachEvent;

        for(var x = 0;x<this._handles.length;x++){
            var handle = this._handles[x];
            if(ieListener) handle.node.detachEvent('on' + handle.type, handle.handler);
            else handle.node.removeEventListener(handle.type, handle.handler, false);
        }

        this._handles = null;

        this.cropNode && this.cropNode.parentNode.removeChild(this.cropNode);
        this.cropNode = null;

        this.imageNode && this.imageNode.parentNode.removeChild(this.imageNode);
        this.imageNode = null;

        this.preview && this.preview.parentNode.removeChild(this.preview);
        this.preview = null;

        this.domNode && this.domNode.parentNode.removeChild(this.domNode);
        this.domNode = null;

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant