You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1018 B
43 lines
1018 B
( function ( $, rwmb ) {
|
|
'use strict';
|
|
|
|
function setActiveClass() {
|
|
var $this = $( this ),
|
|
$input = $this.find( 'input' ),
|
|
$label = $input.parent();
|
|
|
|
if ( $input.prop( 'checked' ) ) {
|
|
$label.addClass( 'selected' );
|
|
} else {
|
|
$label.removeClass( 'selected' );
|
|
}
|
|
}
|
|
|
|
function clickHandler() {
|
|
var $this = $( this ),
|
|
$input = $this.find( 'input' ),
|
|
$label = $input.parent(),
|
|
type = $input.attr( 'type' ),
|
|
$allLabels = $this.parent().find( 'label' );
|
|
if ( ! $input.prop( 'checked' ) ) {
|
|
$label.removeClass( 'selected' );
|
|
return;
|
|
}
|
|
$label.addClass( 'selected' );
|
|
|
|
if ( 'radio' === type ) {
|
|
$allLabels.removeClass( 'selected' );
|
|
$label.addClass( 'selected' );
|
|
}
|
|
}
|
|
|
|
function init( e ) {
|
|
$( e.target ).find( '.rwmb-button-input-list label' ).each( setActiveClass );
|
|
}
|
|
|
|
rwmb.$document
|
|
.on( 'mb_ready', init )
|
|
.on( 'click', '.rwmb-button-input-list label', clickHandler )
|
|
.on( 'clone', '.rwmb-button-input-list label', setActiveClass );
|
|
} )( jQuery, rwmb );
|