summaryrefslogtreecommitdiff
blob: 601f1bd7b6407f2dbd2d2c597ade0da6d4c5df11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* 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() {
			NovaCheckBoxes.inputs.first().prop( 'checked', true );
		},

		checkOne: function(/*event*/) {
			if ( $( this ).is( ':checked' ) ) {
				return NovaCheckBoxes.inputs.not( this ).prop( 'checked', false );
			} else {
				if (
					$( this )
						.closest( '#nova_menuchecklist' )
						.find( ':checked' ).length > 0
				) {
					return $( this ).prop( 'checked', false );
				}
				return NovaCheckBoxes.checkFirst();
			}
		},
	};

	$( NovaCheckBoxes.initialize );
} )( jQuery );