papegaaij opened a new issue, #1646:
URL: https://github.com/apache/wicket/issues/1646
On master, `Wicket.Event.remove` in `wicket-ajax-jquery.js` cannot remove a
listener that was added for several space separated event types.
`Wicket.Event.add` now records each listener in
`Wicket.Event._listenerRegistry`, keyed by the type string exactly as it was
given, e.g. `'input change'`. `Wicket.Event.remove` splits its type argument on
whitespace and looks up `'input'` and `'change'`, which were never recorded, so
nothing is unbound:
```js
var calls = 0, handler = function () { calls++; };
Wicket.Event.add(el, 'input change', handler);
Wicket.Event.remove(el, 'input change', handler);
Wicket.Event.fire(el, 'input');
Wicket.Event.fire(el, 'change');
// calls === 2, expected 0
```
Results in headless Chrome. In every case the listener was added with two
types and both events were fired after the remove:
| How the listener was removed | master, jQuery engine | wicket-10.x, jQuery
engine | master, `wicket-ajax.js` |
|---|---|---|---|
| `remove(el, 'input change', fn)` | 2 calls | 0 | 0 |
| `remove(el, 'focus', fn)`, added as `'focus blur'` | 2 calls | 1 (blur
only) | 1 |
| `remove(el, 'keyup keydown')`, no `fn` | 2 calls | 0 | 0 |
| single type `click`, for comparison | 0 | 0 | 0 |
This is a regression from 10.x, where `remove` delegated to
`jQuery(element).off(type, fn)`, which handles several types. The jQuery-free
`wicket-ajax.js` is not affected, because its `add` splits the type and records
each one separately. Only `remove(el)`, with no type at all, still works on the
jQuery engine.
Wicket's own code does not call `Wicket.Event.remove` with several types,
and `Wicket.Ajax.ajax` adds each event of `attrs.e` separately, so only
application scripts are affected. The QUnit test that calls
`Wicket.Event.remove(window, "event1 event2")` passes because those two events
were added separately.
Proposed fix: split the type in the jQuery engine's `add` the same way
`wicket-ajax.js` does, and record each type separately. Add a QUnit test that
adds a listener for several types and removes it again, both with all the types
and with a single one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]