Completed
Pull Request — master (#1653)
by Aristeides
05:59 queued 03:54
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 Function

Rating   Name   Duplication   Size   Complexity  
B wp.customize.kirkiDynamicControl.extend.initKirkiControl 0 32 1
1
/* global kirkiSetSettingValue */
2
wp.customize.controlConstructor['kirki-preset'] = wp.customize.kirkiDynamicControl.extend({
3
4
	initKirkiControl: function() {
5
6
		var control = this,
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
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