MCPcopy
hub / github.com/videojs/video.js / _cleanUpEvents

Function _cleanUpEvents

src/js/utils/events.js:25–56  ·  view source on GitHub ↗

* Clean up the listener cache and dispatchers * * @param {Element|Object} elem * Element to clean up * * @param {string} type * Type of event to clean up

(elem, type)

Source from the content-addressed store, hash-verified

23 * Type of event to clean up
24 */
25function _cleanUpEvents(elem, type) {
26 if (!DomData.has(elem)) {
27 return;
28 }
29 const data = DomData.get(elem);
30
31 // Remove the events of a particular type if there are none left
32 if (data.handlers[type].length === 0) {
33 delete data.handlers[type];
34 // data.handlers[type] = null;
35 // Setting to null was causing an error with data.handlers
36
37 // Remove the meta-handler from the element
38 if (elem.removeEventListener) {
39 elem.removeEventListener(type, data.dispatcher, false);
40 } else if (elem.detachEvent) {
41 elem.detachEvent('on' + type, data.dispatcher);
42 }
43 }
44
45 // Remove the events object if there are no types left
46 if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
47 delete data.handlers;
48 delete data.dispatcher;
49 delete data.disabled;
50 }
51
52 // Finally remove the element data if there is no data left
53 if (Object.getOwnPropertyNames(data).length === 0) {
54 DomData.delete(elem);
55 }
56}
57
58/**
59 * Loops through an array of event types and calls the requested method for each type.

Callers 2

removeTypeFunction · 0.85
offFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…