This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/modules/contrib/webform/js/webform.confirmation.modal.js
2018-11-23 12:29:20 +00:00

51 lines
1.5 KiB
JavaScript

/**
* @file
* JavaScript behaviors for confirmation modal.
*/
(function ($, Drupal) {
'use strict';
// @see http://api.jqueryui.com/dialog/
Drupal.webform = Drupal.webform || {};
Drupal.webform.confirmationModal = Drupal.webform.confirmationModal || {};
Drupal.webform.confirmationModal.options = Drupal.webform.confirmationModal.options || {};
/**
* Display confirmation message in a modal.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformConfirmationModal = {
attach: function (context) {
$('.js-webform-confirmation-modal', context).once('webform-confirmation-modal').each(function () {
var $element = $(this);
var $dialog = $element.find('.webform-confirmation-modal--content');
var options = {
dialogClass: 'webform-confirmation-modal',
minWidth: 600,
resizable: false,
title: $element.find('.webform-confirmation-modal--title').text(),
close: function (event) {
Drupal.dialog(event.target).close();
Drupal.detachBehaviors(event.target, null, 'unload');
$(event.target).remove();
}
};
options = $.extend(options, Drupal.webform.confirmationModal.options);
var dialog = Drupal.dialog($dialog, options);
// Use setTimeout to prevent dialog.position.js
// Uncaught TypeError: Cannot read property 'settings' of undefined
setTimeout(function () {dialog.showModal();}, 1);
});
}
};
})(jQuery, Drupal);