Test Setup Failed
Pull Request — master (#1653)
by Aristeides
02:23
created

controls/js/src/dimensions.js   A

Complexity

Total Complexity 14
Complexity/F 1.4

Size

Lines of Code 91
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 14
mnd 1
bc 15
fnc 10
bpm 1.5
cpm 1.4
noi 5

4 Functions

Rating   Name   Duplication   Size   Complexity  
A wp.customize.kirkiDynamicControl.extend.saveValue 0 11 1
B wp.customize.kirkiDynamicControl.extend.kirkiNotifications 0 32 1
A wp.customize.kirkiDynamicControl.extend.initKirkiControl 0 19 2
A wp.customize.kirkiDynamicControl.extend.updateDimensionsValue 0 14 1
1
/* global dimensionskirkiL10n */
2
wp.customize.controlConstructor['kirki-dimensions'] = 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
		    subControls = control.params.choices.controls,
8
		    value       = {},
9
		    subsArray   = [],
10
		    i;
11
12
		_.each( subControls, function( v, i ) {
13
			if ( true === v ) {
14
				subsArray.push( i );
15
			}
16
		} );
17
18
		for ( i = 0; i < subsArray.length; i++ ) {
19
			value[ subsArray[ i ] ] = control.setting._value[ subsArray[ i ] ];
20
			control.updateDimensionsValue( subsArray[ i ], value );
21
		}
22
	},
23
24
	/**
25
	 * Updates the value.
26
	 */
27
	updateDimensionsValue: function( context, value ) {
28
29
		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...
30
31
		control.container.on( 'change keyup paste', '.' + context + ' input', function() {
32
			value[ context ] = jQuery( this ).val();
33
34
			// Notifications.
35
			control.kirkiNotifications();
36
37
			// Save the value
38
			control.saveValue( value );
39
		});
40
	},
41
42
	/**
43
	 * Saves the value.
44
	 */
45
	saveValue: function( value ) {
46
47
		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...
48
		    newValue = {};
49
50
		_.each( value, function( newSubValue, i ) {
51
			newValue[ i ] = newSubValue;
52
		});
53
54
		control.setting.set( newValue );
55
	},
56
57
	/**
58
	 * Handles notifications.
59
	 */
60
	kirkiNotifications: function() {
61
62
		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...
63
64
		wp.customize( control.id, function( setting ) {
65
			setting.bind( function( value ) {
66
				var code = 'long_title',
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...
67
				    subs = {},
68
				    message;
69
70
				setting.notifications.remove( code );
71
72
				_.each( value, function( val, direction ) {
73
					if ( false === control.kirkiValidateCSSValue( val ) ) {
74
						subs[ direction ] = val;
75
					} else {
76
						delete subs[ direction ];
77
					}
78
				} );
79
80
				if ( ! _.isEmpty( subs ) ) {
81
					message = dimensionskirkiL10n['invalid-value'] + ' (' + _.values( subs ).toString() + ') ';
82
					setting.notifications.add( code, new wp.customize.Notification( code, {
83
						type: 'warning',
84
						message: message
85
					} ) );
86
					return;
87
				}
88
				setting.notifications.remove( code );
89
			} );
90
		} );
91
	}
92
});
93