Completed
Pull Request — master (#1710)
by Aristeides
14:05 queued 02:09
created

controls/js/src/multicheck.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 24
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 1.3333
noi 2
1
wp.customize.controlConstructor['kirki-multicheck'] = wp.customize.kirkiDynamicControl.extend({
2
3
	initKirkiControl: function() {
4
5
		var control = this;
6
7
		// Save the value
8
		control.container.on( 'change', 'input', function() {
9
			var value = [],
10
			    i = 0;
11
12
			// Build the value as an object using the sub-values from individual checkboxes.
13
			jQuery.each( control.params.choices, function( key ) {
14
				if ( control.container.find( 'input[value="' + key + '"]' ).is( ':checked' ) ) {
15
					value[ i ] = key;
16
					i++;
17
				}
18
			});
19
20
			// Update the value in the customizer.
21
			control.setting.set( value );
22
		});
23
	}
24
});
25