Completed
Pull Request — master (#1710)
by Aristeides
18:06 queued 08:13
created

controls/js/src/preset.js   A

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5
mnd 1
bc 5
fnc 4
bpm 1.25
cpm 1.25
noi 1
1
/* global kirkiSetSettingValue */
2
wp.customize.controlConstructor['kirki-preset'] = wp.customize.kirkiDynamicControl.extend({
3
4
	initKirkiControl: function() {
5
6
		var control = this,
7
		    selectValue;
8
9
		// Trigger a change
10
		this.container.on( 'change', 'select', function() {
11
12
			// Get the control's value
13
			selectValue = jQuery( this ).val();
14
15
			// Update the value using the customizer API and trigger the "save" button
16
			control.setting.set( selectValue );
17
18
			// We have to get the choices of this control
19
			// and then start parsing them to see what we have to do for each of the choices.
20
			jQuery.each( control.params.choices, function( key, value ) {
21
22
				// If the current value of the control is the key of the choice,
23
				// then we can continue processing, Otherwise there's no reason to do anything.
24
				if ( selectValue === key ) {
25
26
					// Each choice has an array of settings defined in it.
27
					// We'll have to loop through them all and apply the changes needed to them.
28
					jQuery.each( value.settings, function( presetSetting, presetSettingValue ) {
29
						kirkiSetSettingValue.set( presetSetting, presetSettingValue );
30
					});
31
				}
32
			});
33
			wp.customize.previewer.refresh();
34
		});
35
	}
36
});
37