Remove jQuery dependency from the once feature

Created on 15 November 2023, about 1 year ago
Updated 29 November 2023, 12 months ago

Problem/Motivation

Remove jQuery dependency from the once feature

https://www.drupal.org/node/3158256

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

5.1

Component

Code

Created by

🇪🇸Spain carles.zapater

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

Merge Requests

Comments & Activities

  • Issue created by @carles.zapater
  • 🇪🇸Spain carles.zapater

    Errors:

    bootstrap_barrio.libraries.yml

    ...
    - 43: - core/.jquery.once
    + 43: - core/once
    ...
    

    js/affix.js
    29: $('[data-toggle="affix"]').once().each(function () {

    
    Console error:
    
    $(...).once is not a function
    
    
  • Assigned to chetan 11
  • Merge request !71fixed → (Merged) created by chetan 11
  • Open on Drupal.org →
    Core: 10.1.0-alpha1 + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India chetan 11

    Hi,
    I have fixed the above error on my local, please check the attached MR.
    Thanks.

  • 🇪🇸Spain carles.zapater

    Please fix file 'js/affix.js'

    Console error: $(...).once is not a function

  • 🇪🇸Spain carles.zapater

    You can see the 5.5.14 branch code:

    /**
     * @file
     * Affix for Bootstrap 5.
     * https://www.codeply.com/users/skelly
     *
     */
    (function ($, Drupal, once) {
    
      'use strict';
    
      Drupal.behaviors.bootstrap_barrio_affix = {
        attach: function (context, settings) {
          var toggleAffix = function (affixElement, scrollElement, wrapper) {
    
            var height = affixElement.outerHeight(),
                top = wrapper.offset().top;
    
            if (scrollElement.scrollTop() >= top){
                wrapper.height(height);
                affixElement.addClass("affix");
            }
            else {
                affixElement.removeClass("affix");
                wrapper.height('auto');
            }
    
          };
    
          once('affixed', '[data-toggle="affix"]', context).forEach((element) => {
            var ele = $(element),
                wrapper = $('<div></div>');
    
            ele.before(wrapper);
            $(window).on('scroll resize', function () {
                toggleAffix(ele, $(this), wrapper);
            });
    
            // init
            toggleAffix(ele, $(window), wrapper);
          });
        }
      }
    })(jQuery, Drupal, once);
    
    
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    4 fail
  • 🇺🇸United States joshuasosa

    This fix helped resolve JS issues when aggregated. Some things, like IMCE module, break due to this error. Thanks!

  • Status changed to Fixed 12 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024