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.buttons.js
2017-03-16 15:29:07 +00:00

36 lines
1 KiB
JavaScript

/**
* @file
* Javascript behaviors for jQuery UI buttons element integration.
*/
(function ($, Drupal) {
'use strict';
/**
* Create jQuery UI buttons element.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformButtons = {
attach: function (context) {
$(context).find('.js-webform-buttons [type="radio"]').commonAncestor().once('webform-buttons').each(function () {
var $input = $(this);
// Remove all div and classes around radios and labels.
$input.html($input.find('input[type="radio"], label').removeClass());
// Create buttonset.
$input.buttonset();
// Disable buttonset.
$input.buttonset('option', 'disabled', $input.find('input[type="radio"]:disabled').length);
// Turn buttonset off/on when the input is disabled/enabled.
// @see webform.states.js
$input.on('webform:disabled', function () {
$input.buttonset('option', 'disabled', $input.find('input[type="radio"]:disabled').length);
});
});
}
};
})(jQuery, Drupal);