PageSourceSearch

https://www.ncdor.gov/modules/contrib/webform/js/webform.dialog.js?v=10.6.15

js ncdor.gov collected 2026-09-24 08:29:27 UTC 3,450 bytes, 97 lines download raw bytes

1/**
2 * @file
3 * JavaScript behaviors for webform dialogs.
4 */
5
6(function ($, Drupal, drupalSettings, once) {
7
8  'use strict';
9
10  // @see http://api.jqueryui.com/dialog/
11  Drupal.webform = Drupal.webform || {};
12  Drupal.webform.dialog = Drupal.webform.dialog || {};
13  Drupal.webform.dialog.options = Drupal.webform.dialog.options || {};
14
15  /**
16   * Programmatically open a webform (or page) in a dialog.
17   *
18   * @param {string} url
19   *   Webform URL.
20   * @param {string} type
21   *   Webform dialog type defined via /admin/structure/webform/config.
22   */
23  Drupal.webformOpenDialog = function (url, type) {
24    // Create a div with link but don't attach it to the page.
25    var $div = $('<div><a href="' + url + '" class="webform-dialog ' + type + '"></a></div>');
26    // Init the webform dialog behavior.
27    Drupal.behaviors.webformDialog.attach($div.get(0));
28    // Trigger the link.
29    $div.find('a').trigger('click');
30  };
31
32  /**
33   * Open webform dialog using preset options.
34   *
35   * @type {Drupal~behavior}
36   */
37  Drupal.behaviors.webformDialog = {
38    attach: function (context) {
39      $(once('webform-dialog', 'a.webform-dialog', context)).each(function () {
40        var $a = $(this);
41
42        // Get default options.
43        var options = $.extend({}, Drupal.webform.dialog.options);
44
45        // Get preset dialog options.
46        if ($a.attr('class').match(/webform-dialog-([a-z0-9_]+)/)) {
47          var dialogOptionsName = RegExp.$1;
48          if (drupalSettings.webform.dialog.options[dialogOptionsName]) {
49            options = drupalSettings.webform.dialog.options[dialogOptionsName];
50
51            // Unset title.
52            delete options.title;
53          }
54        }
55
56        // Get custom dialog options.
57        if ($(this).data('dialog-options')) {
58          $.extend(options, $(this).data('dialog-options'));
59        }
60
61        var href = $a.attr('href');
62
63        // Replace ENTITY_TYPE and ENTITY_ID placeholders and update the href.
64        // @see webform_page_attachments()
65        if (href.indexOf('?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID') !== -1) {
66          if (drupalSettings.webform.dialog.entity_type && drupalSettings.webform.dialog.entity_id) {
67            href = href.replace('ENTITY_TYPE', encodeURIComponent(drupalSettings.webform.dialog.entity_type));
68            href = href.replace('ENTITY_ID', encodeURIComponent(drupalSettings.webform.dialog.entity_id));
69          }
70          else {
71            href = href.replace('?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID', '');
72          }
73          $a.attr('href', href);
74        }
75
76        // Append _webform_dialog=1 to href to trigger Ajax support.
77        // @see \Drupal\webform\WebformSubmissionForm::setEntity
78        href += (href.indexOf('?') === -1 ? '?' : '&') + '_webform_dialog=1';
79
80        var element_settings = {};
81        element_settings.progress = {type: 'fullscreen'};
82        element_settings.url = href;
83        element_settings.event = 'touchstart click';
84        element_settings.dialogType = $a.data('dialog-type') || 'modal';
85        element_settings.dialog = options;
86        element_settings.element = this;
87        element_settings.error = function error(xmlhttp, uri) {
88          if (xmlhttp.status === 403) {
89            window.location.replace(href.split('?')[0]);
90          }
91        };
92        Drupal.ajax(element_settings);
93      });
94    }
95  };
96
97})(jQuery, Drupal, drupalSettings, once);

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.