Use once to avoid attaching behavior multiple times

Created on 25 October 2023, 11 months ago
Updated 5 September 2024, 23 days ago

Problem/Motivation

The current code at `/js/disclaimer.js` is attaching multiple times on the page. This is annoying when there are ajax calls as it will cause the page to scroll to the top of the page due to this code:

            if (gadget) {
              // Focus on the link. I don't know why we need delay but something
              // keeps the focus from happening without it.
              window.setTimeout(() => gadget.focus(), 500);

              // Found the gadget, end the MutationObserver.
              obs.disconnect();
              return;
            }

Steps to reproduce

Several ways to reproduce, easiest one is create a view that use ajax filters. Set it in a way that you can scroll a lot. After applying filters, confirm that you are taken to the translate block.

Proposed resolution

Use once https://www.drupal.org/node/3158256 β†’

πŸ› Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡·Costa Rica alemadlei

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alemadlei
  • @alemadlei opened merge request.
  • Status changed to Postponed: needs info 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jenna.tollerson Atlanta, Georgia, USA

    Hi there, thank you for your report. I am having trouble reproducing this bug.

    1. I created a view page display with an exposed filter and checked "Use AJAX" under the advanced options.
    2. With the Translator block placed near the top of the page, I clicked on the text to show the Google widget, accepted the disclaimer, and chose a language.
    3. With the page translated, I scrolled down so the translator block was out of view.
    4. I made a new selection on the exposed filter and applied it.
    5. I was not taken back to the top of the page. The filtered content loaded as expected.

    Can you still reproduce this issue in the 2.x branch?

  • πŸ‡ΊπŸ‡ΈUnited States j-barnes

    @jenny.tollerson / @alemadlei - Our team was running into the same issue using the "Views Infinite Scroll" pager in a view with ajax enabled. After the user clicks the "Load More" it jump back up to the top of the page after a minor delay. We have the translate block attached to the top of the page via block layout. Adding this has cured the problem for us, thanks for the patch!

  • Status changed to Needs review 23 days ago
  • πŸ‡ΊπŸ‡ΈUnited States j-barnes
Production build 0.71.5 2024