2017-03-16 15:29:07 +00:00
/ * *
* @ file
2018-11-23 12:29:20 +00:00
* JavaScript behaviors for jQuery UI buttons ( checkboxradio ) element integration .
2017-03-16 15:29:07 +00:00
* /
( function ( $ , Drupal ) {
'use strict' ;
2018-11-23 12:29:20 +00:00
Drupal . webform = Drupal . webform || { } ;
Drupal . webform . buttons = Drupal . webform . buttons || { } ;
Drupal . webform . buttons . selector = Drupal . webform . buttons . selector || [
// Applies to Classy, Bartik, and Seven themes.
'.js-webform-buttons .form-radios' ,
// Applies to Stable and Bootstrap themes.
'.js-webform-buttons .js-form-type-radio'
] . join ( ',' ) ;
2017-03-16 15:29:07 +00:00
/ * *
* Create jQuery UI buttons element .
*
* @ type { Drupal ~ behavior }
* /
Drupal . behaviors . webformButtons = {
attach : function ( context ) {
2018-11-23 12:29:20 +00:00
$ ( context ) . find ( Drupal . webform . buttons . selector ) . once ( 'webform-buttons' ) . each ( function ( ) {
var $buttons = $ ( this ) ;
// Remove classes around radios and labels and move to main element.
$buttons . find ( 'input[type="radio"], label' ) . each ( function ( ) {
$buttons . append ( $ ( this ) . removeAttr ( 'class' ) ) ;
} ) ;
// Remove all empty div wrappers.
$buttons . find ( 'div' ) . remove ( ) ;
// Must reset $buttons since the contents have changed.
$buttons = $ ( this ) ;
// Get radios.
var $input = $buttons . find ( 'input[type="radio"]' ) ;
// Create checkboxradio.
$input . checkboxradio ( { icon : false } ) ;
// Disable checkboxradio.
$input . checkboxradio ( 'option' , 'disabled' , $input . is ( ':disabled' ) ) ;
// Turn checkboxradio off/on when the input is disabled/enabled.
2017-03-16 15:29:07 +00:00
// @see webform.states.js
$input . on ( 'webform:disabled' , function ( ) {
2018-11-23 12:29:20 +00:00
$input . checkboxradio ( 'option' , 'disabled' , $input . is ( ':disabled' ) ) ;
2017-03-16 15:29:07 +00:00
} ) ;
} ) ;
}
} ;
} ) ( jQuery , Drupal ) ;