audiojs icon indicating copy to clipboard operation
audiojs copied to clipboard

Teardown method

Open brendon opened this issue 9 years ago • 1 comments

Hi there, just wondering if there's already 'teardown' type method that reverts an 'upgraded' audio element back to its original state (i.e. just the audio tag)? I've checked the code but didn't notice anything obvious.

I'm using Turbolinks 5 and while with the latest audio.js code, audio elements aren't being drawn every time the back navigation is clicked (resulting in multiple instances of the player on the screen), the single player restored from the cache has no functionality as the cloning process in Turbolinks removes the event listeners, and createAll doesn't bother reinitialising already supposedly initialised audio elements.

I guess the solution is to either tear them all down before the page is cached, or make the check in createAll more sophisticated so that it checks for the existence of the event listeners.

Any pointers would be appreciated.

brendon avatar Oct 06 '16 10:10 brendon

I came up with the following as a teardown:

$(audiojs_instances).each(function() {
  $(this.wrapper).replaceWith(this.element);
});

jQuery of course but the idea is basically to replace the wrapper with the element when the page is unloaded.

brendon avatar Oct 07 '16 10:10 brendon