PageSourceSearch

https://www.teaconnect.org/sites/default/files/js/optimized/js_GrQ…qU7ynv-AJYk96ibcwcZViw4n2Ceaabs.js?v=10.5.4

js teaconnect.org collected 2026-09-24 18:52:30 UTC 3,785 bytes, 126 lines download raw bytes

1/* Source and licensing information for the line(s) below can be found at https://www.teaconnect.org/core/misc/dialog/dialog.js. */
2/**
3 * @file
4 * Dialog API inspired by HTML5 dialog element.
5 *
6 * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#the-dialog-element
7 */
8
9class DrupalDialogEvent extends Event {
10  constructor(type, dialog, settings = null) {
11    super(`dialog:${type}`, { bubbles: true });
12    this.dialog = dialog;
13    this.settings = settings;
14  }
15}
16
17(function ($, Drupal, drupalSettings, bodyScrollLock) {
18  /**
19   * Default dialog options.
20   *
21   * @type {object}
22   *
23   * @prop {boolean} [autoOpen=true]
24   * @prop {string} [dialogClass='']
25   * @prop {string} [buttonClass='button']
26   * @prop {string} [buttonPrimaryClass='button--primary']
27   * @prop {function} close
28   */
29  drupalSettings.dialog = {
30    autoOpen: true,
31    dialogClass: '',
32    // Drupal-specific extensions: see dialog.jquery-ui.js.
33    buttonClass: 'button',
34    buttonPrimaryClass: 'button--primary',
35    // When using this API directly (when generating dialogs on the client
36    // side), you may want to override this method and do
37    // `jQuery(event.target).remove()` as well, to remove the dialog on
38    // closing.
39    close(event) {
40      Drupal.dialog(event.target).close();
41      Drupal.detachBehaviors(event.target, null, 'unload');
42    },
43  };
44
45  /**
46   * @typedef {object} Drupal.dialog~dialogDefinition
47   *
48   * @prop {boolean} open
49   *   Is the dialog open or not.
50   * @prop {*} returnValue
51   *   Return value of the dialog.
52   * @prop {function} show
53   *   Method to display the dialog on the page.
54   * @prop {function} showModal
55   *   Method to display the dialog as a modal on the page.
56   * @prop {function} close
57   *   Method to hide the dialog from the page.
58   */
59
60  /**
61   * Polyfill HTML5 dialog element with jQueryUI.
62   *
63   * @param {HTMLElement} element
64   *   The element that holds the dialog.
65   * @param {object} options
66   *   jQuery UI options to be passed to the dialog.
67   *
68   * @return {Drupal.dialog~dialogDefinition}
69   *   The dialog instance.
70   */
71  Drupal.dialog = function (element, options) {
72    let undef;
73
74    const $element = $(element);
75    const domElement = $element.get(0);
76
77    const dialog = {
78      open: false,
79      returnValue: undef,
80    };
81
82    function openDialog(settings) {
83      settings = $.extend({}, drupalSettings.dialog, options, settings);
84      // Trigger a global event to allow scripts to bind events to the dialog.
85      const event = new DrupalDialogEvent('beforecreate', dialog, settings);
86      domElement.dispatchEvent(event);
87      $element.dialog(event.settings);
88      dialog.open = true;
89
90      // Locks the body scroll only when it opens in modal.
91      if (event.settings.modal) {
92        // Locks the body when the dialog opens.
93        bodyScrollLock.lock(domElement);
94      }
95
96      domElement.dispatchEvent(
97        new DrupalDialogEvent('aftercreate', dialog, event.settings),
98      );
99    }
100
101    function closeDialog(value) {
102      domElement.dispatchEvent(new DrupalDialogEvent('beforeclose', dialog));
103
104      // Unlocks the body when the dialog closes.
105      bodyScrollLock.clearBodyLocks();
106
107      $element.dialog('close');
108      dialog.returnValue = value;
109      dialog.open = false;
110
111      domElement.dispatchEvent(new DrupalDialogEvent('afterclose', dialog));
112    }
113
114    dialog.show = () => {
115      openDialog({ modal: false });
116    };
117    dialog.showModal = () => {
118      openDialog({ modal: true });
119    };
120    dialog.close = closeDialog;
121
122    return dialog;
123  };
124})(jQuery, Drupal, drupalSettings, bodyScrollLock);
125
126/* Source and licensing information for the above line(s) can be found at https://www.teaconnect.org/core/misc/dialog/dialog.js. */

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.