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.element.roles.js
2018-11-23 12:29:20 +00:00

40 lines
1.1 KiB
JavaScript

/**
* @file
* JavaScript behaviors for roles element integration.
*/
(function ($, Drupal) {
'use strict';
/**
* Enhance roles element.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformRoles = {
attach: function (context) {
$(context).find('.js-webform-roles-role[value="authenticated"]').once('webform-roles').each(function () {
var $authenticated = $(this);
var $checkboxes = $authenticated.parents('.form-checkboxes').find('.js-webform-roles-role').filter(function () {
return ($(this).val() !== 'anonymous' && $(this).val() !== 'authenticated');
});
$authenticated.on('click', function () {
if ($authenticated.is(':checked')) {
$checkboxes.prop('checked', true).attr('disabled', true);
}
else {
$checkboxes.prop('checked', false).removeAttr('disabled');
}
});
if ($authenticated.is(':checked')) {
$checkboxes.prop('checked', true).attr('disabled', true);
}
});
}
};
})(jQuery, Drupal);