posts: fix JS errors on non-flash posts when using Ruffle extension.

Fix https://github.com/danbooru/danbooru/issues/4783#issuecomment-912426739:

    Spoke too soon. It works in flash posts, but not in non-flash posts.

    Here's the full trace that happens by trying the Shift-E shortcut
    (tested on https://danbooru.donmai.us/posts/4749304 with the latest
    ruffle for chrome at https://ruffle.rs/#downloads):

    4749304:7 Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')
        at Object.initialize_ruffle_player (application-237cebbe071cb34ce095.js:1)
        at Object.initialize_all (application-237cebbe071cb34ce095.js:1)
        at HTMLDocument.<anonymous> (application-237cebbe071cb34ce095.js:1)
        at f (857-ff5115a2d6ceb23b4291.js:2)
        at p (857-ff5115a2d6ceb23b4291.js:2)
        at nrWrapper (4749304?q=status%3Aany:7)

Caused by trying to initialize the Ruffle player on non-Flash posts,
because we checked for the existence of the `window.RufflePlayer` object
to tell if we were on a Flash post, but when using the Ruffle browser
extension the RufflePlayer object will always exist.
This commit is contained in:
evazion
2021-09-03 05:33:11 -05:00
parent d441739ab2
commit 440d2c807f

View File

@@ -382,16 +382,15 @@ Post.initialize_ugoira_player = function() {
};
Post.initialize_ruffle_player = function() {
if (!window.RufflePlayer) {
return;
}
let ruffle = window.RufflePlayer.newest();
let player = ruffle.createPlayer();
let $container = $(".ruffle-container[data-swf]");
let src = $container.attr("data-swf");
$container.get(0).appendChild(player);
player.load(src);
if ($container.length) {
let ruffle = window.RufflePlayer.newest();
let player = ruffle.createPlayer();
let src = $container.attr("data-swf");
$container.get(0).appendChild(player);
player.load(src);
}
};
Post.resize_ugoira_controls = function() {