Completed
Push — master ( e77289...d72873 )
by Fernando
02:50
created

js/customizer-colour.js   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 56
rs 9.7251
c 1
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A api.Control.extend.ready 0 21 2
A _.each 0 5 1
A customizer-colour.js ➔ updateCSS 0 19 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * Add a listener to the Color Scheme control to update other color controls to new values/defaults.
3
 * Also trigger an update of the Color Scheme CSS when a color is changed.
4
 */
5
6
( function( api ) {
7
	var cssTemplate = wp.template( 'lsx-color-scheme' ),
0 ignored issues
show
Bug introduced by
The variable wp seems to be never declared. If this is a global, consider adding a /** global: wp */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
		skipUpdateCss = false;
9
10
	api.controlConstructor.select = api.Control.extend( {
11
		ready: function() {
12
			if ( 'color_scheme' === this.id ) {
13
				this.setting.bind( 'change', function( _value ) {
14
					skipUpdateCss = true;
15
16
					var _colors = colorScheme[_value].colors;
0 ignored issues
show
Bug introduced by
The variable colorScheme seems to be never declared. If this is a global, consider adding a /** global: colorScheme */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
17
18
					_.each( _colors, function( _color, _setting ) {
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19
						if ('function' === typeof api( _setting )) {
20
							api( _setting ).set( _color );
21
							api.control( _setting ).container.find( '.color-picker-hex' )
22
								.data( 'data-default-color', _color )
23
								.wpColorPicker( 'defaultColor', _color );
24
						}
25
					} );
26
27
					skipUpdateCss = false;
28
					updateCSS();
29
				} );
30
			}
31
		}
32
	} );
33
34
	// Generate the CSS for the current Color Scheme.
35
	function updateCSS() {
36
		if (skipUpdateCss) {
37
			return;
38
		}
39
40
		var __scheme = api( 'color_scheme' )(),
41
			__css,
42
			__colors = colorScheme[ __scheme ].colors;
0 ignored issues
show
Bug introduced by
The variable colorScheme seems to be never declared. If this is a global, consider adding a /** global: colorScheme */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
43
44
		// Merge in color scheme overrides.
45
		_.each( colorSchemeKeys, function( __setting ) {
0 ignored issues
show
Bug introduced by
The variable colorSchemeKeys seems to be never declared. If this is a global, consider adding a /** global: colorSchemeKeys */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
			if ('function' === typeof api( __setting )) {
47
				__colors[ __setting ] = api( __setting )();
48
			}
49
		} );
50
51
		__css = cssTemplate( __colors );
52
		api.previewer.send( 'update-color-scheme-css', __css );
53
	}
54
55
	// Update the CSS whenever a color setting is changed.
56
	_.each( colorSchemeKeys, function( __setting ) {
0 ignored issues
show
Bug introduced by
The variable colorSchemeKeys seems to be never declared. If this is a global, consider adding a /** global: colorSchemeKeys */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
57
		api( __setting, function( __setting ) {
58
			__setting.bind( updateCSS );
59
		} );
60
	} );
61
} )( wp.customize );
0 ignored issues
show
Bug introduced by
The variable wp seems to be never declared. If this is a global, consider adding a /** global: wp */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
62