summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-02-04 17:51:29 (GMT)
committer Daniel Silverstone <dsilvers@digital-scurf.org>2017-02-04 17:51:29 (GMT)
commit4e9b50f5b200918088bc6b1136751ea81cd8984b (patch)
tree757c85d0f59cda346932a290941637df05a0718e
parent51ab1cdf25e80490023577c82cc35b68335eff5e (diff)
downloadlibdom-4e9b50f5b200918088bc6b1136751ea81cd8984b.tar.gz
libdom-4e9b50f5b200918088bc6b1136751ea81cd8984b.tar.bz2
Unregister all instances of a listener
Sometimes we register a listener a lot on an event target. This change allows us to pass NULL as the event type to the remove call in order to remove every instance of the given listener, regardless of event type and capture vs. bubble.
-rw-r--r--src/events/event_target.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/events/event_target.c b/src/events/event_target.c
index ef2dc83..4592fee 100644
--- a/src/events/event_target.c
+++ b/src/events/event_target.c
@@ -99,6 +99,9 @@ dom_exception _dom_event_target_add_event_listener(
/**
* Remove an EventListener from the EventTarget
*
+ * (LibDOM extension: If type is NULL, remove all listener registrations
+ * regardless of type and cature)
+ *
* \param et The EventTarget object
* \param type The event type this listener is registered for
* \param listener The listener object
@@ -114,9 +117,15 @@ dom_exception _dom_event_target_remove_event_listener(
struct listener_entry *le = eti->listeners;
do {
- if (dom_string_isequal(le->type, type) &&
- le->listener == listener &&
- le->capture == capture) {
+ bool matches;
+ if (type == NULL) {
+ matches = (le->listener == listener);
+ } else {
+ matches = dom_string_isequal(le->type, type) &&
+ (le->listener == listener) &&
+ (le->capture == capture);
+ }
+ if (matches) {
if (le->list.next == &le->list) {
eti->listeners = NULL;
} else {