Passed
Push — develop ( 34ae61...ee5e63 )
by Paul
02:54
created

+/main.js   A

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 36
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 4
dl 0
loc 36
rs 10
wmc 9
mnd 1
bc 7
fnc 6
bpm 1.1666
cpm 1.5
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A main.js ➔ jQuery 0 13 1
A pollux.metabox.setVisibility 0 6 2
A pollux.metabox.onChangeValue 0 4 1
A pollux.metabox.hasValue 0 6 2
1
var pollux = {
2
	metabox: {},
3
};
4
5
pollux.metabox.hasValue = function( el ) {
6
	if( el.type === 'checkbox' ) {
7
		return el.checked === true;
8
	}
9
	return el.value !== '';
10
};
11
12
pollux.metabox.onChangeValue = function( el )
13
{
14
	pollux.metabox.setVisibility( el );
15
};
16
17
pollux.metabox.setVisibility = function( el )
18
{
19
	var dependency = document.getElementById( el.getAttribute( 'data-depends' ));
20
	el.closest( '.rwmb-field' ).style.display = pollux.metabox.hasValue( dependency ) ? '' : 'none';
21
	return dependency;
22
};
23
24
jQuery(function(x) {
0 ignored issues
show
Unused Code introduced by
The parameter x is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
25
26
	var depends = document.querySelectorAll( '.rwmb-input [data-depends]' );
27
28
	[].forEach.call( depends, function( el ) {
29
		var dependency = pollux.metabox.setVisibility( el );
30
		var event = dependency.type === 'checkbox' ? 'change' : 'keyup';
31
		dependency.addEventListener( event, function() {
32
			pollux.metabox.onChangeValue( el );
33
		}, false );
34
	});
35
36
});
37