Total Complexity | 48 |
Complexity/F | 1.6 |
Lines of Code | 248 |
Function Count | 30 |
Duplicated Lines | 248 |
Ratio | 100 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like tests/demo/site/js/main.js 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 | View Code Duplication | ;(function () { |
|
|
|||
2 | |||
3 | 'use strict'; |
||
4 | |||
5 | |||
6 | |||
7 | // iPad and iPod detection |
||
8 | var isiPad = function(){ |
||
9 | return (navigator.platform.indexOf("iPad") != -1); |
||
10 | }; |
||
11 | |||
12 | var isiPhone = function(){ |
||
13 | return ( |
||
14 | (navigator.platform.indexOf("<i></i>Phone") != -1) || |
||
15 | (navigator.platform.indexOf("iPod") != -1) |
||
16 | ); |
||
17 | }; |
||
18 | |||
19 | // OffCanvass |
||
20 | var offCanvass = function() { |
||
21 | $('body').on('click', '.js-fh5co-menu-btn, .js-fh5co-offcanvass-close', function(){ |
||
22 | $('#fh5co-offcanvass').toggleClass('fh5co-awake'); |
||
23 | }); |
||
24 | }; |
||
25 | |||
26 | |||
27 | // Click outside of offcanvass |
||
28 | var mobileMenuOutsideClick = function() { |
||
29 | |||
30 | $(document).click(function (e) { |
||
31 | var container = $("#fh5co-offcanvas, .js-fh5co-close-offcanvas"); |
||
32 | if (!container.is(e.target) && container.has(e.target).length === 0) { |
||
33 | |||
34 | if ( $('#fh5co-offcanvass').hasClass('fh5co-awake') ) { |
||
35 | $('#fh5co-offcanvass').removeClass('fh5co-awake'); |
||
36 | } |
||
37 | |||
38 | $(window).scroll(function(){ |
||
39 | if ( $(window).scrollTop() > 500 ) { |
||
40 | if ( $('#fh5co-offcanvass').hasClass('fh5co-awake') ) { |
||
41 | $('#fh5co-offcanvass').removeClass('fh5co-awake'); |
||
42 | } |
||
43 | } |
||
44 | }); |
||
45 | |||
46 | if ( $('#fh5co-offcanvas').hasClass('animated fadeInLeft') ) { |
||
47 | |||
48 | $('#fh5co-offcanvas').addClass('animated fadeOutLeft'); |
||
49 | setTimeout(function(){ |
||
50 | $('#fh5co-offcanvas').css('display', 'none'); |
||
51 | $('#fh5co-offcanvas').removeClass('animated fadeOutLeft fadeInLeft'); |
||
52 | }, 1000); |
||
53 | $('.js-fh5co-nav-toggle').removeClass('active'); |
||
54 | |||
55 | } |
||
56 | |||
57 | |||
58 | } |
||
59 | }); |
||
60 | |||
61 | $('body').on('click', '.js-fh5co-close-offcanvas', function(event){ |
||
62 | |||
63 | |||
64 | $('#fh5co-offcanvas').addClass('animated fadeOutLeft'); |
||
65 | setTimeout(function(){ |
||
66 | $('#fh5co-offcanvas').css('display', 'none'); |
||
67 | $('#fh5co-offcanvas').removeClass('animated fadeOutLeft fadeInLeft'); |
||
68 | }, 1000); |
||
69 | $('.js-fh5co-nav-toggle').removeClass('active'); |
||
70 | |||
71 | event.preventDefault(); |
||
72 | |||
73 | }); |
||
74 | |||
75 | }; |
||
76 | |||
77 | // Magnific Popup |
||
78 | |||
79 | var magnifPopup = function() { |
||
80 | $('.image-popup').magnificPopup({ |
||
81 | type: 'image', |
||
82 | removalDelay: 300, |
||
83 | mainClass: 'mfp-with-zoom', |
||
84 | titleSrc: 'title', |
||
85 | gallery:{ |
||
86 | enabled:true |
||
87 | }, |
||
88 | zoom: { |
||
89 | enabled: true, // By default it's false, so don't forget to enable it |
||
90 | |||
91 | duration: 300, // duration of the effect, in milliseconds |
||
92 | easing: 'ease-in-out', // CSS transition easing function |
||
93 | |||
94 | // The "opener" function should return the element from which popup will be zoomed in |
||
95 | // and to which popup will be scaled down |
||
96 | // By defailt it looks for an image tag: |
||
97 | opener: function(openerElement) { |
||
98 | // openerElement is the element on which popup was initialized, in this case its <a> tag |
||
99 | // you don't need to add "opener" option if this code matches your needs, it's defailt one. |
||
100 | return openerElement.is('img') ? openerElement : openerElement.find('img'); |
||
101 | } |
||
102 | } |
||
103 | }); |
||
104 | }; |
||
105 | |||
106 | var animateBoxWayPoint = function() { |
||
107 | |||
108 | if ($('.animate-box').length > 0) { |
||
109 | $('.animate-box').waypoint( function( direction ) { |
||
110 | |||
111 | if( direction === 'down' && !$(this).hasClass('animated') ) { |
||
112 | $(this.element).addClass('bounceIn animated'); |
||
113 | } |
||
114 | |||
115 | } , { offset: '75%' } ); |
||
116 | } |
||
117 | |||
118 | }; |
||
119 | |||
120 | // Burger Menu |
||
121 | var burgerMenu = function() { |
||
122 | |||
123 | $('body').on('click', '.js-fh5co-nav-toggle', function(event){ |
||
124 | |||
125 | var $this = $(this); |
||
126 | |||
127 | $('#fh5co-offcanvas').css('display', 'block'); |
||
128 | setTimeout(function(){ |
||
129 | $('#fh5co-offcanvas').addClass('animated fadeInLeft'); |
||
130 | }, 100); |
||
131 | |||
132 | // $('body').toggleClass('fh5co-overflow offcanvas-visible'); |
||
133 | $this.toggleClass('active'); |
||
134 | event.preventDefault(); |
||
135 | |||
136 | }); |
||
137 | |||
138 | }; |
||
139 | |||
140 | var scrolledWindow = function() { |
||
141 | |||
142 | $(window).scroll(function(){ |
||
143 | |||
144 | var header = $('#fh5co-header'), |
||
145 | scrlTop = $(this).scrollTop(); |
||
146 | |||
147 | |||
148 | $('#fh5co-home .flexslider .fh5co-overlay').css({ |
||
149 | 'opacity' : (.5)+(scrlTop/2000) |
||
150 | }); |
||
151 | |||
152 | if ( $('body').hasClass('offcanvas-visible') ) { |
||
153 | $('body').removeClass('offcanvas-visible'); |
||
154 | $('.js-fh5co-nav-toggle').removeClass('active'); |
||
155 | } |
||
156 | |||
157 | }); |
||
158 | |||
159 | $(window).resize(function() { |
||
160 | if ( $('body').hasClass('offcanvas-visible') ) { |
||
161 | $('body').removeClass('offcanvas-visible'); |
||
162 | $('.js-fh5co-nav-toggle').removeClass('active'); |
||
163 | } |
||
164 | }); |
||
165 | |||
166 | }; |
||
167 | |||
168 | |||
169 | |||
170 | |||
171 | // Page Nav |
||
172 | var clickMenu = function() { |
||
173 | var topVal = ( $(window).width() < 769 ) ? 0 : 58; |
||
174 | |||
175 | $(window).resize(function(){ |
||
176 | topVal = ( $(window).width() < 769 ) ? 0 : 58; |
||
177 | }); |
||
178 | |||
179 | if ( $(this).attr('href') != "#") { |
||
180 | $('#fh5co-main-nav a:not([class="external"]), #fh5co-offcanvas a:not([class="external"])').click(function(event){ |
||
181 | var section = $(this).data('nav-section'); |
||
182 | |||
183 | |||
184 | if ( $('div[data-section="' + section + '"]').length ) { |
||
185 | |||
186 | $('html, body').animate({ |
||
187 | scrollTop: $('div[data-section="' + section + '"]').offset().top - topVal |
||
188 | }, 500); |
||
189 | |||
190 | } |
||
191 | event.preventDefault(); |
||
192 | |||
193 | }); |
||
194 | } |
||
195 | |||
196 | |||
197 | |||
198 | |||
199 | }; |
||
200 | |||
201 | |||
202 | var contentWayPoint = function() { |
||
203 | var i = 0; |
||
204 | $('.animate-box').waypoint( function( direction ) { |
||
205 | |||
206 | if( direction === 'down' && !$(this.element).hasClass('animated') ) { |
||
207 | |||
208 | i++; |
||
209 | |||
210 | $(this.element).addClass('item-animate'); |
||
211 | setTimeout(function(){ |
||
212 | |||
213 | $('body .animate-box.item-animate').each(function(k){ |
||
214 | var el = $(this); |
||
215 | setTimeout( function () { |
||
216 | el.addClass('fadeInUp animated'); |
||
217 | el.removeClass('item-animate'); |
||
218 | }, k * 200, 'easeInOutExpo' ); |
||
219 | }); |
||
220 | |||
221 | }, 100); |
||
222 | |||
223 | } |
||
224 | |||
225 | } , { offset: '85%' } ); |
||
226 | |||
227 | |||
228 | }; |
||
229 | |||
230 | |||
231 | // Document on load. |
||
232 | $(function(){ |
||
233 | |||
234 | mobileMenuOutsideClick(); |
||
235 | burgerMenu(); |
||
236 | scrolledWindow(); |
||
237 | |||
238 | // Animations |
||
239 | contentWayPoint(); |
||
240 | magnifPopup(); |
||
241 | offCanvass(); |
||
242 | //animateBoxWayPoint(); |
||
243 | |||
244 | |||
245 | }); |
||
246 | |||
247 | |||
248 | }()); |