diff --git a/js/builder.es6.js b/js/builder.es6.js index 06d12b80e0a93d4e1d3a6b9a66b4a1e48ff85aa9..778444cf15fe8016c875d2fcb582203602f8dc61 100644 --- a/js/builder.es6.js +++ b/js/builder.es6.js @@ -486,6 +486,10 @@ // @see https://www.drupal.org/project/layout_paragraphs/issues/3216981 $(window).on('dialog:aftercreate', (event, dialog, $dialog) => { if ($dialog.attr('id').indexOf('lpb-dialog-') === 0) { + // If buttons have already been added to the buttonpane, do not continue. + if ($dialog.dialog('option', 'buttons').length > 0) { + return; + } const buttons = []; const $buttons = $dialog.find( '.layout-paragraphs-component-form > .form-actions input[type=submit], .layout-paragraphs-component-form > .form-actions a.button', @@ -518,13 +522,17 @@ // Repositions open dialogs. // @see https://www.drupal.org/project/layout_paragraphs/issues/3252978 // @see https://stackoverflow.com/questions/5456298/refresh-jquery-ui-dialog-position + let lpDialogInterval; $(window).on('dialog:aftercreate', (event, dialog, $dialog) => { if ($dialog[0].id.indexOf('lpb-dialog-') === 0) { + if (lpDialogInterval) { + clearInterval(lpDialogInterval); + } $dialog.data('lpOriginalHeight', $dialog.outerHeight()); - $dialog.data('lpDialogInterval', setInterval(repositionDialog.bind(null, $dialog), 500)); + lpDialogInterval = setInterval(repositionDialog.bind(null, $dialog), 500); } }); - $(window).on('dialog:beforeclose', (event, dialog, $dialog) => { - clearInterval($dialog.data('lpDialogInterval')); + $(window).on('dialog:beforeclose', () => { + clearInterval(lpDialogInterval); }); })(jQuery, Drupal, Drupal.debounce, dragula); diff --git a/js/builder.js b/js/builder.js index c1d3867bccd0082e402098c6364bc88eb70d3c59..d3a5dfbfadc2033c833208bfafa87a0ae79913cd 100644 --- a/js/builder.js +++ b/js/builder.js @@ -371,6 +371,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } }; $(window).on('dialog:aftercreate', function (event, dialog, $dialog) { if ($dialog.attr('id').indexOf('lpb-dialog-') === 0) { + if ($dialog.dialog('option', 'buttons').length > 0) { + return; + } + var buttons = []; var $buttons = $dialog.find('.layout-paragraphs-component-form > .form-actions input[type=submit], .layout-paragraphs-component-form > .form-actions a.button'); $buttons.each(function (_i, el) { @@ -396,13 +400,18 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } } } }); + var lpDialogInterval; $(window).on('dialog:aftercreate', function (event, dialog, $dialog) { if ($dialog[0].id.indexOf('lpb-dialog-') === 0) { + if (lpDialogInterval) { + clearInterval(lpDialogInterval); + } + $dialog.data('lpOriginalHeight', $dialog.outerHeight()); - $dialog.data('lpDialogInterval', setInterval(repositionDialog.bind(null, $dialog), 500)); + lpDialogInterval = setInterval(repositionDialog.bind(null, $dialog), 500); } }); - $(window).on('dialog:beforeclose', function (event, dialog, $dialog) { - clearInterval($dialog.data('lpDialogInterval')); + $(window).on('dialog:beforeclose', function () { + clearInterval(lpDialogInterval); }); })(jQuery, Drupal, Drupal.debounce, dragula); \ No newline at end of file