Once not a function

Created on 15 June 2023, over 1 year ago
Updated 20 June 2023, over 1 year ago

Problem/Motivation

`flush.js` produces and error in Chrome: `Uncaught TypeError: $(...).once is not a function...` and prevents the fun flushing sound from playing.

Steps to reproduce

Install Drupal 10
Install Flush module
Clear cache
Observe browser console error message `Uncaught TypeError: $(...).once is not a function...`

Proposed resolution

Replace the code as follows:

  Drupal.behaviors.flush = {
    attach: function (context, settings) {
      $('body', context).once('flush').each(function () {
        if (settings.flushCacheCleared === 'true') {
          const flush = document.createElement('audio');
          flush.setAttribute('src', settings.flush.pathToSound);
          flush.play();
        }
      });
    },
  };

with

  Drupal.behaviors.flush = {
    attach: function (context, settings) {
      once('flush', context).forEach(function () {
        if (settings.flushCacheCleared === 'true') {
          const flush = document.createElement('audio');
          flush.setAttribute('src', settings.flush.pathToSound);
          flush.play();
        }
      });
    }
  };

Remaining tasks

Test for backwards compatibility with Drupal 9

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇺🇸United States axb

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

Comments & Activities

Production build 0.71.5 2024