[WV2] Persist state in URL

This commit is contained in:
Emi Matchu 2025-11-02 08:55:17 +00:00
parent 58fabad3c2
commit f96569b2bf
2 changed files with 47 additions and 38 deletions

View file

@ -205,10 +205,19 @@ function morphWithOutfitLayers(currentElement, newElement) {
}, },
}); });
} }
addEventListener("turbo:before-frame-render", (event) => {
function onTurboRender(event) {
// Rather than enforce Idiomorph must be loaded, let's just be resilient // Rather than enforce Idiomorph must be loaded, let's just be resilient
// and only bother if we have it. (Replacing content is not *that* bad!) // and only bother if we have it. (Replacing content is not *that* bad!)
if (typeof Idiomorph !== "undefined") { if (typeof Idiomorph !== "undefined") {
event.detail.render = (a, b) => morphWithOutfitLayers(a, b); event.detail.render = (a, b) => morphWithOutfitLayers(a, b);
} }
}); }
// On most pages, we only apply this to Turbo frames, to be conservative. (Morphing the whole page is hard!)
addEventListener("turbo:before-frame-render", onTurboRender);
// But on pages that opt into it (namely the wardrobe), we do it for the full page too.
if (document.querySelector('meta[name=outfit-viewer-morph-mode][value=full-page]') !== null) {
addEventListener("turbo:before-render", onTurboRender);
}

View file

@ -10,14 +10,14 @@
= stylesheet_link_tag "application/hanger-spinner" = stylesheet_link_tag "application/hanger-spinner"
= stylesheet_link_tag "application/outfit-viewer" = stylesheet_link_tag "application/outfit-viewer"
= page_stylesheet_link_tag "outfits/new_v2" = page_stylesheet_link_tag "outfits/new_v2"
= csrf_meta_tags
= javascript_include_tag "application", async: true = javascript_include_tag "application", async: true
= javascript_include_tag "idiomorph", async: true = javascript_include_tag "idiomorph", async: true
= javascript_include_tag "outfit-viewer", async: true = javascript_include_tag "outfit-viewer", async: true
= javascript_include_tag "species-color-picker", async: true = javascript_include_tag "species-color-picker", async: true
= javascript_include_tag "outfits/new_v2", async: true = javascript_include_tag "outfits/new_v2", async: true
= csrf_meta_tags
%meta{name: 'outfit-viewer-morph-mode', value: 'full-page'}
%body.wardrobe-v2 %body.wardrobe-v2
= turbo_frame_tag "outfit-editor" do
.wardrobe-container .wardrobe-container
.outfit-preview-section .outfit-preview-section
- if @pet_type.nil? - if @pet_type.nil?