Feature request: allow sidr.js callback execution from outside Drupal.Sidr

Created on 23 February 2021, over 3 years ago
Updated 18 May 2024, about 1 month ago

Problem/Motivation

I needed to execute my own code when Drupal.Sidr fires it's onOpen and onCloseEnd events that are configured in sidr/sidr.js @ Drupal.behaviors.sidr_trigger.

Steps to reproduce

N/A

Proposed resolution

I've patched modules/contrib/sidr/sidr.js to allow extension of Drupal.Sidr with a "cb" property. The Drupal.Sidr.cb property is an object that defines one or more of the following callbacks: onOpen, onOpenEnd, onClose, onCloseEnd.

Each callback that you define is passed the sidr trigger (it's jQuery~fied dom node) as it's first argument and the triggers settings (a js object) as it's second argument.

Here's an example defining two callbacks: onOpen and onCloseEnd:

_.extend(Drupal.Sidr,{ cb: {
  onOpen: function(trigger,settings){ 
    console.log({'@':'onOpen', trigger: trigger, settings: settings}); 
  },
  onCloseEnd: function(trigger,settings){ 
    console.log({'@':'onCloseEnd', trigger: trigger, settings: settings}); 
  },
}});

I've attached the patch file for sidr v3.1.0 → and my patched version of the sidr.js file → (remove the _.txt extension)

Usage Notes:

The above example could be placed anywhere that has Drupal.Sidr already defined, and since it's using underscore.js (included in core) to splice the cb property into Drupal.Sidr, also has _ defined.

Let’s say the above _.extend() is placed in the file: your_module/sidr-callbacks.js. To make sure that you had Drupal.Sidr and _ already defined, your libraries file (your_module/your_module.libraries.yml) would look something like:

your_library:
  js:
    'sidr-callbacks.js': {}
  dependencies:
    - core/underscore
    - sidr/behaviors

Remaining tasks

??

User interface changes

N/A

API changes

N/A

Data model changes

N/A

✨ Feature request
Status

Closed: won't fix

Version

3.1

Component

Code

Created by

🇺🇸United States perfectcu.be

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024