2 * @file paragraphs.modal.js
6 (function ($, Drupal, drupalSettings) {
11 * Click handler for click "Add" button between paragraphs.
15 Drupal.behaviors.paragraphsModalAdd = {
16 attach: function (context) {
17 $('.paragraph-type-add-modal-button', context)
18 .once('add-click-handler')
19 .on('click', function (event) {
20 var $button = $(this);
21 var $add_more_wrapper = $button.parent().siblings('.paragraphs-add-dialog');
22 Drupal.paragraphsAddModal.openDialog($add_more_wrapper, $button.val());
24 // Stop default execution of click event.
25 event.preventDefault();
26 event.stopPropagation();
32 * Namespace for modal related javascript methods.
36 Drupal.paragraphsAddModal = {};
39 * Open modal dialog for adding new paragraph in list.
41 * @param {Object} $context
42 * jQuery element of form wrapper used to submit request for adding new
43 * paragraph to list. Wrapper also contains dialog template.
44 * @param {string} title
45 * The title of the modal form window.
47 Drupal.paragraphsAddModal.openDialog = function ($context, title) {
55 var $dialog = $(this);
57 // Destroy dialog object.
58 $dialog.dialog('destroy');
62 // Close the dialog after a button was clicked.
63 $('.field-add-more-submit', $context)
65 // Use mousedown event, because we are using ajax in the modal add mode
66 // which explicitly suppresses the click event.
67 $(this).on('mousedown', function () {
69 $this.closest('div.ui-dialog-content').dialog('close');
74 }(jQuery, Drupal, drupalSettings));