balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

button-group.js (1009B)


      1 ( function ( $, rwmb ) {
      2 	'use strict';
      3 
      4 	function setActiveClass() {
      5 		var $this = $( this ),
      6 			$input = $this.find( 'input' ),
      7 			$label = $input.parent();
      8 
      9 		if ( $input.prop( 'checked' ) ) {
     10 			$label.addClass( 'selected' );
     11 		} else {
     12 			$label.removeClass( 'selected' );
     13 		}
     14 	}
     15 
     16 	function clickHandler() {
     17 		var $this = $( this ),
     18 			$input = $this.find( 'input' ),
     19 			$label = $input.parent(),
     20 			type = $input.attr( 'type' ),
     21 			$allLabels = $this.parent().find( 'label' );
     22 		if ( ! $input.prop( 'checked' ) ) {
     23 			$label.removeClass( 'selected' );
     24 			return;
     25 		}
     26 		$label.addClass( 'selected' );
     27 
     28 		if ( 'radio' === type ) {
     29 			$allLabels.removeClass( 'selected' );
     30 			$label.addClass( 'selected' );
     31 		}
     32 	}
     33 
     34 	function init( e ) {
     35 		$( e.target ).find( '.rwmb-button-input-list li' ).each( setActiveClass );
     36 	}
     37 
     38 	rwmb.$document
     39 		.on( 'mb_ready', init )
     40 		.on( 'click', '.rwmb-button-input-list li', clickHandler )
     41 		.on( 'clone', '.rwmb-button-input-list li', setActiveClass );
     42 } )( jQuery, rwmb );