
| Current Path : /var/www/html/strat/web/modules/contrib/webform/js/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/strat/web/modules/contrib/webform/js/webform.element.terms_of_service.js |
/**
* @file
* JavaScript behaviors for terms of service.
*/
(function ($, Drupal, once) {
'use strict';
// @see http://api.jqueryui.com/dialog/
Drupal.webform = Drupal.webform || {};
Drupal.webform.termsOfServiceModal = Drupal.webform.termsOfServiceModal || {};
Drupal.webform.termsOfServiceModal.options = Drupal.webform.termsOfServiceModal.options || {};
/**
* Initialize terms of service element.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformTermsOfService = {
attach: function (context) {
$(once('webform-terms-of-service', '.js-form-type-webform-terms-of-service', context)).each(function () {
var $element = $(this);
var $a = $element.find('label a');
var $details = $element.find('.webform-terms-of-service-details');
var type = $element.attr('data-webform-terms-of-service-type');
// Initialize the modal.
if (type === 'modal') {
// Move details title to attribute.
var $title = $element.find('.webform-terms-of-service-details--title');
if ($title.length) {
$details.attr('title', $title.text());
$title.remove();
}
var options = $.extend({
modal: true,
autoOpen: false,
minWidth: 600,
maxWidth: 800
}, Drupal.webform.termsOfServiceModal.options);
$details.dialog(options);
}
// Add aria-* attributes.
if (type !== 'modal') {
$a.attr({
'aria-expanded': false,
'aria-controls': $details.attr('id')
});
}
// Set event handlers.
$a.on('click', openDetails)
.on('keydown', function (event) {
// Space or Return.
if (event.which === 32 || event.which === 13) {
openDetails(event);
}
});
function openDetails(event) {
if (type === 'modal') {
$details.dialog('open');
}
else {
var expanded = ($a.attr('aria-expanded') === 'true');
// Toggle `aria-expanded` attributes on link.
$a.attr('aria-expanded', !expanded);
// Toggle details.
$details[expanded ? 'slideUp' : 'slideDown']();
}
event.preventDefault();
}
});
}
};
})(jQuery, Drupal, once);