Defer Click Fix #30

Closed
azoff opened this Issue Nov 25, 2011 · 0 comments

Comments

Projects
None yet
1 participant
Owner

azoff commented Nov 25, 2011

Hi Azoff,

first of all, great work on this. I have had an issue with the click event handling, though. I was able to solve it, so I wanted to share for future releases. Here goes:

deferClick: function(target) {
    var events = target.data('events');
    if (events && events.click && events.click.length) {
        events = events.click.slice();
        target.unbind('click').one('click',
        function(event) {
            event.preventDefault(); - >event.stopPropagation(); - >event.stopImmediatePropagation();
            $.each(events,
            function(i, event) {
                target.click(event);
            });
        }); - >
    } else { - >target.one('click',
        function(event) { - >event.preventDefault(); - >event.stopPropagation(); - >event.stopImmediatePropagation(); - >
        }); - >
    }
},

I marked all new lines with -> arrows. To explain: I am using your script in combination with jqGrid. It allows you to select rows by clicking. The click event however is not on the dragging element (e.g. the ) but on the parent (). The previous code would only prevent click events for the element itself and reattach any previously detached click events. My extension always defers the click event, and stops propagation, so the click event won't be fired on parent elements.

Hope this helps.

azoff closed this in 817f785 Nov 25, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment