* 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)
| 23 | * Type of event to clean up |
| 24 | */ |
| 25 | function _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. |
no test coverage detected
searching dependent graphs…