Restrict which kind of mutation events are allowed to trigger player refresh

This commit is contained in:
Tamius Han 2019-10-27 16:51:31 +01:00
parent 828ded6b29
commit 6af771e1ff

View File

@ -86,21 +86,33 @@ class VideoData {
} }
return; return;
} }
let confirmAspectRatioRestore = false;
for (let mutation of mutationList) { for (let mutation of mutationList) {
if (mutation.type === 'attributes' if (mutation.type === 'attributes') {
&& mutation.attributeName === 'class' if (mutation.attributeName === 'class') {
&& !context.video.classList.contains(this.userCssClassName) ) { if(!context.video.classList.contains(this.userCssClassName) ) {
// force the page to include our class in classlist, if the classlist has been removed // force the page to include our class in classlist, if the classlist has been removed
// while classList.add() doesn't duplicate classes (does nothing if class is already added), // while classList.add() doesn't duplicate classes (does nothing if class is already added),
// we still only need to make sure we're only adding our class to classlist if it has been // we still only need to make sure we're only adding our class to classlist if it has been
// removed. classList.add() will _still_ trigger mutation (even if classlist wouldn't change). // removed. classList.add() will _still_ trigger mutation (even if classlist wouldn't change).
// This is a problem because INFINITE RECURSION TIME, and we _really_ don't want that. // This is a problem because INFINITE RECURSION TIME, and we _really_ don't want that.
context.video.classList.add(this.userCssClassName);
context.video.classList.add(this.userCssClassName); }
break; // always trigger refresh on class changes, since change of classname might trigger change
// of the player size as well.
confirmAspectRatioRestore = true;
}
if (mutation.attributeName === 'style') {
confirmAspectRatioRestore = true;
}
} }
} }
if (!confirmAspectRatioRestore) {
return;
}
// adding player observer taught us that if element size gets triggered by a class, then // adding player observer taught us that if element size gets triggered by a class, then
// the 'style' attributes don't necessarily trigger. This means we also need to trigger // the 'style' attributes don't necessarily trigger. This means we also need to trigger
// restoreAr here, in case video size was changed this way // restoreAr here, in case video size was changed this way