azoff/Overscroll — Issue #30: Defer Click Fix
Author: azoff
Created: 2011-11-25 05:09:02+00:00
State: open

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:

```javascript
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.