Unverified Commit 213a5659 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3207782 by nod_, bnjmnm, jptaranto: Add BC layer between @drupal/once and jQuery.once

parent 167686b8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -528,6 +528,16 @@ jquery.once:
    assets/vendor/jquery-once/jquery.once.min.js: { weight: -19, minified: true }
  dependencies:
    - core/jquery
    - core/jquery.once.bc

jquery.once.bc:
  version: VERSION
  js:
    misc/jquery.once.bc.js: { weight: -19 }
  dependencies:
    - core/jquery
    - core/once
    - core/drupal.object.assign

jquery.ui:
  version: &jquery_ui_version 1.12.1
+33 −0
Original line number Diff line number Diff line
/**
 * @file
 * This file allows calls to `once()` and `once.remove()` to also populate the
 * jQuery.once registry.
 *
 * It allows contributed code still using jQuery.once to behave as expected:
 * @example
 * once('core-once-call', 'body');
 *
 * // The following will work in a contrib module still using jQuery.once:
 * $('body').once('core-once-call'); // => returns empty object
 */

(($, once) => {
  // We'll replace the whole library so keep a version in cache for later.
  const drupalOnce = once;

  // When calling once(), also populate jQuery.once registry.
  function augmentedOnce(id, selector, context) {
    $(selector, context).once(id);
    return drupalOnce(id, selector, context);
  }

  // When calling once.remove(), also remove it from jQuery.once registry.
  function remove(id, selector, context) {
    $(selector, context).removeOnce(id);
    return drupalOnce.remove(id, selector, context);
  }

  // Expose the rest of @drupal/once API and replace @drupal/once library with
  // the version augmented with jQuery.once calls.
  window.once = Object.assign(augmentedOnce, drupalOnce, { remove });
})(jQuery, once);
+24 −0
Original line number Diff line number Diff line
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

(function ($, once) {
  var drupalOnce = once;

  function augmentedOnce(id, selector, context) {
    $(selector, context).once(id);
    return drupalOnce(id, selector, context);
  }

  function remove(id, selector, context) {
    $(selector, context).removeOnce(id);
    return drupalOnce.remove(id, selector, context);
  }

  window.once = Object.assign(augmentedOnce, drupalOnce, {
    remove: remove
  });
})(jQuery, once);
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
name: 'JS once Test'
type: module
description: 'Module for the jsOnceTest.'
package: Testing
version: VERSION
+14 −0
Original line number Diff line number Diff line
js_once_test:
  path: '/js_once_test'
  defaults:
    _controller: '\Drupal\js_once_test\Controller\JsOnceTestController::onceTest'
    _title: 'OnceTest'
  requirements:
    _access: 'TRUE'
js_once_test.with_bc:
  path: '/js_once_with_bc_test'
  defaults:
    _controller: '\Drupal\js_once_test\Controller\JsOnceTestController::onceBcTest'
    _title: 'OnceBcTest'
  requirements:
    _access: 'TRUE'
Loading