Implemented InteractionMapper.off
This commit is contained in:
+40
-1
@@ -1087,6 +1087,10 @@ export class InteractionMapper extends InteractionDelegate {
|
||||
return this
|
||||
}
|
||||
|
||||
if (typeof Hammer.__hammers === 'undefined') {
|
||||
Hammer.__hammers = new Map()
|
||||
}
|
||||
|
||||
// convert to array
|
||||
types = Array.isArray(types) ? types : types.split(/\s/)
|
||||
if (elements instanceof NodeList || elements instanceof HTMLCollection) {
|
||||
@@ -1129,6 +1133,14 @@ export class InteractionMapper extends InteractionDelegate {
|
||||
hammer.on(type, event => {
|
||||
cb(event)
|
||||
})
|
||||
|
||||
if (Hammer.__hammers.has(elements[j])) {
|
||||
const elementHammers = Hammer.__hammers.get(elements[j])
|
||||
elementHammers.push(hammer)
|
||||
Hammer.__hammers.set(elements[j], elementHammers)
|
||||
} else {
|
||||
Hammer.__hammers.set(elements[j], [hammer])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < elements.length; j++) {
|
||||
@@ -1138,8 +1150,35 @@ export class InteractionMapper extends InteractionDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @static
|
||||
* @param {HTMLElement|HTMLElement[]} elements - An HTML element or an array of HTML elements.
|
||||
*/
|
||||
static off(elements) {
|
||||
if (typeof Hammer === 'undefined') {
|
||||
console.error('Hammer.js not found!')
|
||||
return this
|
||||
}
|
||||
|
||||
// convert to array
|
||||
if (elements instanceof NodeList || elements instanceof HTMLCollection) {
|
||||
elements = Array.from(elements)
|
||||
}
|
||||
elements = Array.isArray(elements) ? elements : [elements]
|
||||
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
const element = elements[i]
|
||||
|
||||
if (Hammer.__hammers.has(element)) {
|
||||
const elementHammers = Hammer.__hammers.get(element)
|
||||
elementHammers.forEach(it => it.destroy())
|
||||
Hammer.__hammers.delete(element)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user