This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Omphaloskepsis/plugins/jetpack/modules/custom-post-types/js/menu-checkboxes.js
2018-03-21 18:19:20 +00:00

50 lines
1.1 KiB
JavaScript

/* jshint onevar: false, smarttabs: true, devel: true */
(function($) {
var NovaCheckBoxes = {
inputs: null,
popInputs: null,
initialize: function() {
NovaCheckBoxes.popInputs = $( '#nova_menuchecklist-pop' ).find( ':checkbox' );
NovaCheckBoxes.inputs = $( '#nova_menuchecklist' )
.find( ':checkbox' )
.change( NovaCheckBoxes.checkOne )
.change( NovaCheckBoxes.syncPop );
if ( !NovaCheckBoxes.isChecked() ) {
NovaCheckBoxes.checkFirst();
}
NovaCheckBoxes.syncPop();
},
syncPop: function() {
NovaCheckBoxes.popInputs.each( function() {
var $this = $( this );
$this.prop( 'checked', $( '#in-nova_menu-' + $this.val() ).is( ':checked' ) );
} );
},
isChecked: function() {
return NovaCheckBoxes.inputs.is( ':checked' );
},
checkFirst: function() {
console.log( 'first!' );
NovaCheckBoxes.inputs.first().prop( 'checked', true );
},
checkOne: function( /*event*/ ) {
if ( $( this ).is( ':checked' ) ) {
return NovaCheckBoxes.inputs.not( this ).prop( 'checked', false );
} else {
return NovaCheckBoxes.checkFirst();
}
}
};
$( NovaCheckBoxes.initialize );
})(jQuery);