Total Complexity | 14 |
Complexity/F | 2 |
Lines of Code | 67 |
Function Count | 7 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | ;(function( window, document, undefined ) { |
||
|
|||
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(); |
||
9 | this.options = castor._extend( this.defaults, options ); |
||
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 ) |
||
54 | { |
||
55 | this.aF.request( function() { |
||
56 | if( this.el.clientHeight === 0 || window.outerWidth < 768 )return; |
||
57 | if( !this.scrolling ) { |
||
58 | this.scrolling = true; |
||
59 | this.autoHide(); |
||
60 | } |
||
61 | }.bind( this )); |
||
62 | }, |
||
63 | }; |
||
64 | |||
65 | castor.AutoHideNavigation = Plugin; |
||
66 | |||
67 | })( window, document ); |
||
68 |
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.