input-list.js (1088B)
1 ( function ( $, rwmb ) { 2 'use strict'; 3 4 function toggleTree() { 5 var $this = $( this ), 6 $children = $this.closest( 'li' ).children( 'ul' ); 7 8 if ( $this.is( ':checked' ) ) { 9 $children.removeClass( 'hidden' ); 10 } else { 11 $children.addClass( 'hidden' ).find( 'input' ).prop( 'checked', false ); 12 } 13 } 14 15 function toggleAll( e ) { 16 e.preventDefault(); 17 18 var $this = $( this ), 19 checked = $this.data( 'checked' ); 20 21 if ( undefined === checked ) { 22 checked = true; 23 } 24 25 $this.parent().siblings( '.rwmb-input-list' ).find( 'input' ).prop( 'checked', checked ).trigger( 'change' ); 26 27 checked = ! checked; 28 $this.data( 'checked', checked ); 29 } 30 31 function init( e ) { 32 $( e.target ).find( '.rwmb-input-list.rwmb-collapse input[type="checkbox"]' ).each( toggleTree ); 33 } 34 35 rwmb.$document 36 .on( 'mb_ready', init ) 37 .on( 'change', '.rwmb-input-list.rwmb-collapse input[type="checkbox"]', toggleTree ) 38 .on( 'clone', '.rwmb-input-list.rwmb-collapse input[type="checkbox"]', toggleTree ) 39 .on( 'click', '.rwmb-input-list-select-all-none', toggleAll ); 40 } )( jQuery, rwmb );