scripts.js ➔ restoreZoom   F
last analyzed

Complexity

Conditions 22

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 0
c 0
b 0
f 0
cc 22

How to fix   Complexity   

Complexity

Complex classes like scripts.js ➔ restoreZoom often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*
2
Bones Scripts File
3
Author: Eddie Machado
4
5
This file should contain any js scripts you want to add to the site.
6
Instead of calling it in the header or throwing it inside wp_head()
7
this file will be called automatically in the footer so as not to
8
slow the page load.
9
10
*/
11
12
// IE8 ployfill for GetComputed Style (for Responsive Script below)
13
if (!window.getComputedStyle) {
14
    window.getComputedStyle = function(el, pseudo) {
0 ignored issues
show
Unused Code introduced by
The parameter pseudo 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...
15
        this.el = el;
16
        this.getPropertyValue = function(prop) {
17
            var re = /(\-([a-z]){1})/g;
18
            if (prop == 'float') prop = 'styleFloat';
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...
19
            if (re.test(prop)) {
20
                prop = prop.replace(re, function () {
21
                    return arguments[2].toUpperCase();
22
                });
23
            }
24
            return el.currentStyle[prop] ? el.currentStyle[prop] : null;
25
        }
26
        return this;
27
    }
28
}
29
30
// as the page loads, call these scripts
31
jQuery(document).ready(function($) {
32
33
    /*
34
    Responsive jQuery is a tricky thing.
35
    There's a bunch of different ways to handle
36
    it, so be sure to research and find the one
37
    that works for you best.
38
    */
39
    
40
    /* getting viewport width */
41
    var responsive_viewport = $(window).width();
42
    
43
    /* if is below 481px */
44
    if (responsive_viewport < 481) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
45
    
46
    } /* end smallest screen */
47
    
48
    /* if is larger than 481px */
49
    if (responsive_viewport > 481) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
50
        
51
    } /* end larger than 481px */
52
    
53
    /* if is above or equal to 768px */
54
    if (responsive_viewport >= 768) {
55
    
56
        /* load gravatars */
57
        $('.comment img[data-gravatar]').each(function(){
58
            $(this).attr('src',$(this).attr('data-gravatar'));
59
        });
60
        
61
    }
62
    
63
    /* off the bat large screen actions */
64
    if (responsive_viewport > 1030) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
65
        
66
    }
67
    
68
	
69
	// add all your scripts here
70
    
71
    $('.scroll-contact').on('click',function () {
72
	    var contact = $('.b-container');
73
	    $('html,body').animate({scrollTop: contact.offset().top}, 1500);
74
	});
75
76
	var wi = $(window).width();
77
	
78
	if(wi <= 980){
79
		$('#header').addClass('fixed');
80
	}	
81
82
	$(window).scroll(function() {
83
		if($(window).scrollTop() > 0) {
84
			$('#header').addClass('fixed');
85
		}else{
86
			$('#header').removeClass('fixed');
87
		}
88
	});
89
 
90
 
91
}); /* end of as page load scripts */
92
93
94
/*! A fix for the iOS orientationchange zoom bug.
95
 Script by @scottjehl, rebound by @wilto.
96
 MIT License.
97
*/
98
(function(w){
99
	// This fix addresses an iOS bug, so return early if the UA claims it's something else.
100
	if( !( /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ){ return; }
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ 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...
101
    var doc = w.document;
102
    if( !doc.querySelector ){ return; }
103
    var meta = doc.querySelector( "meta[name=viewport]" ),
104
        initialContent = meta && meta.getAttribute( "content" ),
105
        disabledZoom = initialContent + ",maximum-scale=1",
106
        enabledZoom = initialContent + ",maximum-scale=10",
107
        enabled = true,
108
		x, y, z, aig;
109
    if( !meta ){ return; }
110
    function restoreZoom(){
111
        meta.setAttribute( "content", enabledZoom );
112
        enabled = true; }
113
    function disableZoom(){
114
        meta.setAttribute( "content", disabledZoom );
115
        enabled = false; }
116
    function checkTilt( e ){
117
		aig = e.accelerationIncludingGravity;
118
		x = Math.abs( aig.x );
119
		y = Math.abs( aig.y );
120
		z = Math.abs( aig.z );
121
		// If portrait orientation and in one of the danger zones
122
        if( !w.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
123
			if( enabled ){ disableZoom(); } }
124
		else if( !enabled ){ restoreZoom(); } }
125
	w.addEventListener( "orientationchange", restoreZoom, false );
126
	w.addEventListener( "devicemotion", checkTilt, false );
127
})( this );