Passed
Push — develop ( c6dd2a...1f8334 )
by Paul
03:38
created

assets/js/auto-hide-navigation.js   A

Complexity

Total Complexity 14
Complexity/F 2

Size

Lines of Code 67
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 4
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 14
mnd 2
bc 11
fnc 7
bpm 1.5713
cpm 2
noi 6

5 Functions

Rating   Name   Duplication   Size   Complexity  
A auto-hide-navigation.js ➔ Plugin 0 9 2
A Plugin.checkNavigation 0 11 4
A Plugin.onScroll 0 10 1
A Plugin.init 0 5 1
A Plugin.autoHide 0 7 1
1
;(function( window, document, undefined ) {
0 ignored issues
show
Unused Code introduced by
The parameter undefined 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...
2
	"use strict";
3
4
	var Plugin = function( navigationSelector, options )
5
	{
6
		this.el = document.querySelector( navigationSelector );
7
		if( this.el ) {
8
			this.aF = new AnimationFrame();
0 ignored issues
show
Bug introduced by
The variable AnimationFrame seems to be never declared. If this is a global, consider adding a /** global: AnimationFrame */ 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...
9
			this.options = castor._extend( this.defaults, options );
0 ignored issues
show
Bug introduced by
The variable castor seems to be never declared. If this is a global, consider adding a /** global: castor */ 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...
10
			this.init();
11
		}
12
	};
13
14
	Plugin.prototype =
15
	{
16
		defaults: {
17
			scrollDelta: 10,
18
			scrollOffset: 150,
19
		},
20
21
		init: function()
22
		{
23
			// this.el.querySelector( '.open-main-menu' ).addEventListener( 'click', this.onClick.bind( this ));
24
			window.addEventListener( 'scroll', this.onScroll.bind( this ));
25
		},
26
27
		autoHide: function()
28
		{
29
			var currentTop = window.pageYOffset;
30
			this.checkNavigation( currentTop );
31
			this.previousTop = currentTop;
32
			this.scrolling = false;
33
		},
34
35
		checkNavigation: function( currentTop )
36
		{
37
			// scrolling up
38
			if( this.previousTop - currentTop > this.options.scrollDelta ) {
39
				this.el.classList.remove( 'is-hidden' );
40
			}
41
			// scrolling down
42
			else if( currentTop - this.previousTop > this.options.scrollDelta && currentTop > this.options.scrollOffset ) {
43
				this.el.classList.add( 'is-hidden' );
44
			}
45
		},
46
47
		// onClick: function( ev )
48
		// {
49
		// 	ev.preventDefault();
50
		// 	this.el.classlist.toggle( 'nav-open' );
51
		// },
52
53
		onScroll: function( ev )
0 ignored issues
show
Unused Code introduced by
The parameter ev 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...
54
		{
55
			this.aF.request( function() {
56
				if( this.el.clientHeight === 0 || window.outerWidth < 768 )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
57
				if( !this.scrolling ) {
58
					this.scrolling = true;
59
					this.autoHide();
60
				}
61
			}.bind( this ));
62
		},
63
	};
64
65
	castor.AutoHideNavigation = Plugin;
0 ignored issues
show
Bug introduced by
The variable castor seems to be never declared. If this is a global, consider adding a /** global: castor */ 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...
66
67
})( window, document );
68