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) { |
||
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
|
|||
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) { |
||
45 | |||
46 | } /* end smallest screen */ |
||
47 | |||
48 | /* if is larger than 481px */ |
||
49 | if (responsive_viewport > 481) { |
||
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) { |
||
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; } |
||
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 ); |
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 you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.