diff options
-rw-r--r-- | src/js/plyr.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index f065feb4..e625504e 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -472,13 +472,21 @@ // Bind along with custom handler function _proxyListener(element, eventName, userListener, defaultListener, useCapture) { + if(userListener) { + // Register this before defaultListener + _on( + element, + eventName, + function(event) { + userListener.apply(element, [event]); + }, + useCapture + ); + } _on( element, eventName, function(event) { - if (userListener) { - userListener.apply(element, [event]); - } defaultListener.apply(element, [event]); }, useCapture @@ -519,11 +527,11 @@ } // Unbind event - /*function _off(element, events, callback, useCapture) { + function _off(element, events, callback, useCapture) { if (element) { _toggleListener(element, events, callback, false, useCapture); } - }*/ + } // Trigger event function _event(element, type, bubbles, properties) { @@ -2949,6 +2957,10 @@ } } + function onBodyClick() { + _toggleClass(_getElement('.' + config.classes.tabFocus), config.classes.tabFocus, false); + } + // Listen for control events function _controlListeners() { // IE doesn't support input event, so we fallback to change @@ -3163,9 +3175,7 @@ checkTabFocus(focused); } }); - _on(document.body, "click", function() { - _toggleClass(_getElement("." + config.classes.tabFocus), config.classes.tabFocus, false); - }); + _on(document.body, "click", onBodyClick); for (var button in plyr.buttons) { var element = plyr.buttons[button]; @@ -3447,9 +3457,15 @@ // Replace the container with the original element provided plyr.container.parentNode.replaceChild(original, plyr.container); + // Free container in order for GC to remove it and prevent memory leaks due to added events + plyr.container = null; + // Allow overflow (set on fullscreen) document.body.style.overflow = ""; + //remove events + _off(document.body, 'click', onBodyClick); + // Event _triggerEvent(original, "destroyed", true); } |