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

Function off

src/js/utils/events.js:352–408  ·  view source on GitHub ↗
(elem, type, fn)

Source from the content-addressed store, hash-verified

350 * type.
351 */
352export function off(elem, type, fn) {
353 // Don't want to add a cache object through getElData if not needed
354 if (!DomData.has(elem)) {
355 return;
356 }
357
358 const data = DomData.get(elem);
359
360 // If no events exist, nothing to unbind
361 if (!data.handlers) {
362 return;
363 }
364
365 if (Array.isArray(type)) {
366 return _handleMultipleEvents(off, elem, type, fn);
367 }
368
369 // Utility function
370 const removeType = function(el, t) {
371 data.handlers[t] = [];
372 _cleanUpEvents(el, t);
373 };
374
375 // Are we removing all bound events?
376 if (type === undefined) {
377 for (const t in data.handlers) {
378 if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) {
379 removeType(elem, t);
380 }
381 }
382 return;
383 }
384
385 const handlers = data.handlers[type];
386
387 // If no handlers exist, nothing to unbind
388 if (!handlers) {
389 return;
390 }
391
392 // If no listener was provided, remove all listeners for type
393 if (!fn) {
394 removeType(elem, type);
395 return;
396 }
397
398 // We're only removing a single handler
399 if (fn.guid) {
400 for (let n = 0; n < handlers.length; n++) {
401 if (handlers[n].guid === fn.guid) {
402 handlers.splice(n--, 1);
403 }
404 }
405 }
406
407 _cleanUpEvents(elem, type);
408}
409

Callers 1

funcFunction · 0.70

Calls 4

_handleMultipleEventsFunction · 0.85
removeTypeFunction · 0.85
_cleanUpEventsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected