PageSourceSearch

https://lums.edu.pk/core/misc/dialog/dialog.js?v=10.2.12

js lums.edu.pk collected 2026-09-24 09:03:20 UTC 3,178 bytes, 107 lines download raw bytes

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

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.