From fff68e1d160b9b95d7693ffd0b34eac71dec79e5 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 31 Mar 2021 22:10:04 -0500 Subject: [PATCH] ruffle: fix issue with ruffle falsely triggering keyboard shortcuts. Fix issue mentioned in 55980c6fb with Javascript spazzing out on Flash posts and randomly triggering keyboard shortcuts. The bug was calling `javascript_pack_tag` twice. This caused the runtime Javascript chunk to be loaded twice, caused a lot of Javascript errors that somehow resulted in keyboard shortcuts being triggered. The fix is to combine both calls into `javascript_pack_tag "application", "flash"`. hxxps://github.com.rails.webpacker.issues.2932 --- app/javascript/src/javascripts/posts.js.erb | 14 ++++++++++++++ app/views/layouts/default.html.erb | 9 ++++++++- app/views/posts/partials/show/_flash.html.erb | 7 +------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index 06beaf231..ee193ea92 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -35,6 +35,7 @@ Post.initialize_all = function() { this.initialize_post_image_resize_links(); this.initialize_recommended(); this.initialize_ugoira_player(); + this.initialize_ruffle_player(); } if ($("#c-posts #a-show, #c-uploads #a-new").length) { @@ -380,6 +381,19 @@ 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); +}; + Post.resize_ugoira_controls = function() { var $img = $("#image"); var width = Math.max($img.width(), 350); diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 163367c77..6346e1ed2 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -16,7 +16,14 @@ <% if CurrentUser.user.blacklisted_tags.present? %> "> <% end %> - <%= javascript_pack_tag "application" %> + + <%# XXX hack to only load Ruffle on Flash posts %> + <% if controller_name == "posts" && action_name == "show" && @post.is_flash? %> + <%= javascript_pack_tag "application", "flash" %> + <% else %> + <%= javascript_pack_tag "application" %> + <% end %> + <%= stylesheet_pack_tag "application" %> <% if CurrentUser.user.custom_style.present? && params.fetch(:css, "true").truthy? %> <%= stylesheet_link_tag custom_style_users_path(md5: Digest::MD5.hexdigest(CurrentUser.user.custom_style)), media: "screen" %> diff --git a/app/views/posts/partials/show/_flash.html.erb b/app/views/posts/partials/show/_flash.html.erb index 4b5006197..62227298c 100644 --- a/app/views/posts/partials/show/_flash.html.erb +++ b/app/views/posts/partials/show/_flash.html.erb @@ -1,8 +1,3 @@ -<%= content_tag(:object, :width => post.image_width, :height => post.image_height) do %> - <%= tag :params, :name => "movie", :value => post.tagged_file_url %> - <%= tag :embed, :src => post.tagged_file_url, :width => post.image_width, :height => post.image_height, :allowScriptAccess => "never" %> -<% end %> +

<%= link_to "Save this flash (right click and save)", post.tagged_file_url %>

- -<%= javascript_pack_tag "flash" %>