Completed
Pull Request — master (#1653)
by Aristeides
05:30 queued 02:53
created

controls/js/src/sortable.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 66
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 2
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 11
mnd 1
bc 11
fnc 8
bpm 1.375
cpm 1.375
noi 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A wp.customize.Control.extend.ready 0 13 3
B wp.customize.Control.extend.initKirkiControl 0 30 1
A wp.customize.Control.extend.updateValue 0 14 1
1
/* global kirkiControlLoader */
2
wp.customize.controlConstructor['kirki-sortable'] = wp.customize.Control.extend({
3
4
	// When we're finished loading continue processing
5
	ready: function() {
6
7
		'use strict';
8
9
		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...
10
11
		// Init the control.
12
		if ( ! _.isUndefined( window.kirkiControlLoader ) && _.isFunction( kirkiControlLoader ) ) {
13
			kirkiControlLoader( control );
14
		} else {
15
			control.initKirkiControl();
16
		}
17
	},
18
19
	initKirkiControl: function() {
20
21
		'use strict';
22
23
		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...
24
25
		control.container.find( '.kirki-controls-loading-spinner' ).hide();
26
27
		// Set the sortable container.
28
		control.sortableContainer = control.container.find( 'ul.sortable' ).first();
29
30
		// Init sortable.
31
		control.sortableContainer.sortable({
32
33
			// Update value when we stop sorting.
34
			stop: function() {
35
				control.updateValue();
36
			}
37
		}).disableSelection().find( 'li' ).each( function() {
38
39
			// Enable/disable options when we click on the eye of Thundera.
40
			jQuery( this ).find( 'i.visibility' ).click( function() {
41
				jQuery( this ).toggleClass( 'dashicons-visibility-faint' ).parents( 'li:eq(0)' ).toggleClass( 'invisible' );
42
			});
43
		}).click( function() {
44
45
			// Update value on click.
46
			control.updateValue();
47
		});
48
	},
49
50
	/**
51
	 * Updates the sorting list
52
	 */
53
	updateValue: function() {
54
55
		'use strict';
56
57
		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...
58
		    newValue = [];
59
60
		this.sortableContainer.find( 'li' ).each( function() {
61
			if ( ! jQuery( this ).is( '.invisible' ) ) {
62
				newValue.push( jQuery( this ).data( 'value' ) );
63
			}
64
		});
65
		control.setting.set( newValue );
66
	}
67
});
68