Completed
Push — master ( bef6ca...7e2933 )
by Fernando
03:32
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
var filter_item_width;
2
3
jQuery(document).ready(function($) {
4
	var $window = $(window),
5
		windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
6
		windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
7
8
	$window.resize(function() {
9
		windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
		windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
11
	});
12
13
	if ( $("header.banner").hasClass("navbar-static-top") ) {
14
		$("body").addClass("top-menu-fixed");
15
	}
16
	
17
	if($('li.menu-item-language-current.dropdown').length){
18
		$('li.menu-item-language-current.dropdown').find('a:first').append('<span class="caret"></span>');
19
	}
20
21
	if ($('.wp-pagenavi').children().length == 0) {
22
		$('.wp-pagenavi').remove();
23
	} else {
24
		$('.wp-pagenavi').wrap('<div class="wp-pagenavi-wrapper"></div>');
25
		$('<div class="lsx-breaker"></div>').prependTo( ".wp-pagenavi-wrapper" );
26
	}
27
28
	var sidebarExists = document.getElementById("secondary");
29
	if (sidebarExists) {
30
		$('body').addClass('has-sidebar');
31
	}
32
33
	if ( $('header.banner .container form').hasClass('search-form') ) {
34
		$('body').addClass('has-header-search');
35
	}
36
37
	var neg_margin = $('.portfolio-title').height();
38
	if (neg_margin > 40) {
39
		$('.portfolio-title').css('margin-top', -neg_margin);
40
	} else {
41
		$('.portfolio-title').css('margin-top', -neg_margin/2);
42
	}
43
44
	$('header.banner .search-toggle').remove();
45
46
	filter_item_width = jQuery('.filter-items-container').width();
47
	if(jQuery('.filter-items-container .filter-item').hasClass('column-1')){
48
		filter_item_width = 750;
49
	}else if(jQuery('.filter-items-container .filter-item').hasClass('column-2')){
50
		filter_item_width = filter_item_width/2;
51
	}else if(jQuery('.filter-items-container .filter-item').hasClass('column-3')){
52
		filter_item_width = filter_item_width/3;
53
	}else if(jQuery('.filter-items-container .filter-item').hasClass('column-4')){
54
		filter_item_width = filter_item_width/4;
55
	}else if(jQuery('.filter-items-container .filter-item').hasClass('column-5')){
56
		filter_item_width = filter_item_width/5;
57
	}else if(jQuery('.filter-items-container .filter-item').hasClass('column-6')){
58
		filter_item_width = filter_item_width/6;
59
	}
60
	
61
	if(windowWidth <= 768 && windowWidth > 400){
62
		filter_item_width = jQuery('.filter-items-container').width()/2;
63
		
64
		jQuery('.filter-items-container .filter-item').each(function(){
65
			jQuery(this).removeClass('column-1 column-2 column-3 column-4 column-5 column-6');
66
			jQuery(this).addClass('column-2');
67
		});
68
	}
69
70
	if(windowWidth <= 400){
71
		filter_item_width = jQuery('.filter-items-container').width();
72
		jQuery('.filter-items-container .filter-item').each(function(){
73
			jQuery(this).removeClass('column-1 column-2 column-3 column-4 column-5 column-6');
74
			jQuery(this).addClass('column-1');
75
		});
76
	}	
77
	
78
	$('table#wp-calendar').addClass('table');
79
80
	$('.dropdown-menu').on('touchstart.dropdown.data-api', function(e){
81
	    e.stopPropagation();
82
	});
83
84
	$window.scroll(function(){
85
	    if ( $window.scrollTop() > 250 && windowWidth > 768 ) {
86
	        $('#top-menu.top-menu-fixed:not(.top-menu-always-visible)').slideUp();
87
	        $('header.banner.navbar-static-top:not(.scrolled)').addClass('scrolled');
88
	    } else {
89
	        $('#top-menu.top-menu-fixed:not(.top-menu-always-visible)').slideDown();
90
	        $('header.banner.navbar-static-top.scrolled').removeClass('scrolled');
91
	    }
92
	});
93
	
94
	$window.resize(function () {
95
		if ( $window.scrollTop() > 250 && windowWidth > 768 ) {
96
	        $('#top-menu.top-menu-fixed:not(.top-menu-always-visible)').slideUp();
97
	        $('header.banner.navbar-static-top:not(.scrolled)').addClass('scrolled');
98
	    } else {
99
	        $('#top-menu.top-menu-fixed:not(.top-menu-always-visible)').slideDown();
100
	        $('header.banner.navbar-static-top.scrolled').removeClass('scrolled');
101
	    }
102
103
		var neg_margin = $('.portfolio-title').height();
104
		if (neg_margin > 40) {
105
			$('.portfolio-title').css('margin-top', -neg_margin);
106
		} else {
107
			$('.portfolio-title').css('margin-top', -neg_margin/2);
108
		}
109
	});
110
111
	// Disabling homepage slider, background image area on mobile
112
	$window.resize(function () {
113
	    if (windowWidth < 768) {
114
	        $(".home-bg-image").hide();
115
	        $(".home-bg-image-footer").hide();
116
	    } else {
117
	    	$(".home-bg-image-footer").show();
118
	        $(".home-bg-image").show();
119
	    }
120
	});
121
122
	// Sticky Info Box widget
123
	var spacing = 0;
124
	if ($('body').hasClass('logged-in')) {
125
		spacing = 125;
126
	} else {
127
		spacing = 93;
128
	}
129
130
	$(".info-box-sticky").sticky({ 
131
		topSpacing: spacing,
132
		bottomSpacing: 670,
133
		getWidthFrom: '#secondary',
134
		responsiveWidth: true,
135
		responsiveBreakpoint: 992
136
	});
137
138
	// Sticky Book Now widget
139
	$(".sticky-book").sticky({ 
140
		topSpacing: spacing,
141
		bottomSpacing: 520,
142
		getWidthFrom: '#secondary',
143
		responsiveWidth: true,
144
		responsiveBreakpoint: 992
145
	});
146
147
	// Sticky Enquire Now widget
148
	$(".sticky-enquire").sticky({ 
149
		topSpacing: spacing,
150
		bottomSpacing: 2000,
151
		getWidthFrom: '#secondary',
152
		responsiveWidth: true,
153
		responsiveBreakpoint: 992
154
	});
155
156
    $window.load(function() {
157
		// The sorter for the portfolio.
158
    	var has_filter = $('#filterNav');
159
    	if('undefined' !== has_filter){
160
			$('#main').imagesLoaded( function(){
161
				lsxProjectThumbInit();
162
				lsxProjectFilterInit();
163
	
164
				jQuery('#main').css('opacity', '1' );
165
		    });			
166
    	}
167
    	
168
    	//Portfolio Hover Class
169
		if(lsx_params.is_portfolio){
0 ignored issues
show
Bug introduced by
The variable lsx_params seems to be never declared. If this is a global, consider adding a /** global: lsx_params */ 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...
170
			$('.portfolio-content-wrapper').hover(function() {
171
		        $(this).addClass('active');
172
		    }, function() {
173
		        $(this).removeClass('active');
174
		    });
175
		}
176
    	
177
		$('.masonry > article').hover(function() {
178
	        $(this).addClass('active');
179
	    }, function() {
180
	        $(this).removeClass('active');
181
	    });
182
183
		// Bootstrat Menu
184
185
		if (1199 < windowWidth) {
186
			$('.navbar-nav li.dropdown a, #top-menu li.dropdown a').each(function() {
187
				$(this).removeClass('dropdown-toggle');
188
				$(this).removeAttr('data-toggle');
189
			});
190
		}
191
		
192
		$('.dropdown').on('show.bs.dropdown', function() {
193
			if (1200 > windowWidth) {
194
				$(this).siblings('.open').removeClass('open').find('a.dropdown-toggle').attr('data-toggle', 'dropdown');
195
				$(this).find('a.dropdown-toggle').removeAttr('data-toggle');
196
			}
197
		});
198
199
		$window.resize(function() {
200
			if (1199 < windowWidth) {
201
				$('.navbar-nav li.dropdown a').each(function() {
202
					$(this).removeClass('dropdown-toggle');
203
					$(this).removeAttr('data-toggle');
204
				});
205
			} else {
206
				$('.navbar-nav li.dropdown a').each(function() {
207
					$(this).addClass('dropdown-toggle');
208
					$(this).attr('data-toggle','dropdown');
209
				});				
210
			}
211
		});
212
213
		// Grandchild Menu
214
215
		var fixDropdownPosition = function() {
216
			$('.navbar-nav > .menu-item:last-child').each(function() {
217
				if ($(this).hasClass('menu-item-has-children')) {
218
					var $firstMenuItem = $(this),
219
						$dropdown = $firstMenuItem.children('.dropdown-menu'),
220
						$dropdownItem = $dropdown.children('.menu-item-has-children'),
221
						dropdownWidth,
222
						firstMenuItemRight;
223
224
					//if ($dropdownItem.length > 0) {
225
						dropdownWidth = $dropdown.outerWidth(),
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
226
						firstMenuItemRight = (windowWidth - ($firstMenuItem.offset().left + $firstMenuItem.outerWidth()));
227
228
						if (firstMenuItemRight < dropdownWidth) {
229
							$dropdown.addClass('pull-right');
230
							$dropdownItem.addClass('dropdown-menu-left');
231
						}
232
					//}
233
				}
234
			});
235
		};
236
237
		if (1199 < windowWidth) {
238
			fixDropdownPosition();
239
		} else {
240
			$('.dropdown .dropdown > a').on("click", function(e) {
241
				if (!$(this).hasClass('open')) {
242
					$(this).addClass('open');
243
					$(this).next('.dropdown-menu').toggle();
244
					e.stopPropagation();
245
					e.preventDefault();
246
				}
247
			});
248
		}
249
250
		// Search menu (in mobile)
251
252
		jQuery(document).on('click', 'header.banner #searchform button.search-submit', function(e) {
253
			if (1200 > windowWidth) {
254
				e.preventDefault();
255
				var form = jQuery(this).closest('form');
256
257
				if (form.hasClass('hover')) {
258
					form.submit();
259
				} else {
260
					form.addClass('hover');
261
					form.find('.search-field').focus();
262
				}
263
			}
264
		});
265
266
		jQuery(document).on('blur', 'header.banner #searchform .search-field', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e 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...
267
			if (1200 > windowWidth) {
268
				var form = jQuery(this).closest('form');
269
				form.removeClass('hover');
270
			}
271
		});
272
273
		// Parallax Effect on Banners
274
275
		var $banner,
276
			$bannerImage,
277
			$bannerContainer,
278
			bannerHeight = 0,
279
			bannerContainerBaseSize = 0,
280
			bannerParallax = function() {
281
				if ($window.scrollTop() <= windowHeight) {
282
					var scrolled = $window.scrollTop() / windowHeight * 100,
283
						paddingTop = (4 * scrolled),
284
						base = -130,
285
						top = base + (3 * scrolled),
286
						bottom = base - (3 * scrolled),
287
						breakpoint = bannerContainerBaseSize + paddingTop;
288
289
					$bannerImage.css('top', top + 'px');
290
					$bannerImage.css('bottom', bottom + 'px');
291
292
					if (breakpoint < bannerHeight) {
293
						$bannerContainer.css('padding-top', paddingTop + 'px');
294
					}
295
				}
296
			}
297
298
		if (991 < windowWidth) {
299
			$banner = $('.page-banner:not(.gmap-banner)');
300
301
			if ($banner.length > 0) {
302
				$bannerImage = $banner.children('.page-banner-image');
303
				$bannerContainer = $banner.children('.container');
304
305
				if ($bannerContainer.length > 0) {
306
					bannerHeight = $banner.height();
307
					bannerContainerBaseSize = $bannerContainer.height() + 
308
												parseInt(($bannerContainer.css('margin-top')).replace('px', '')) + 
309
												parseInt(($bannerContainer.css('margin-bottom')).replace('px', '')) + 
310
												parseInt(($bannerContainer.css('padding-bottom')).replace('px', ''));
311
					bannerParallax();
312
313
					$window.resize(function() {
314
						bannerHeight = $banner.height();
315
						bannerContainerBaseSize = $bannerContainer.height() + 
316
													parseInt(($bannerContainer.css('margin-top')).replace('px', '')) + 
317
													parseInt(($bannerContainer.css('margin-bottom')).replace('px', '')) + 
318
													parseInt(($bannerContainer.css('padding-bottom')).replace('px', ''));
319
					});
320
321
					$window.scroll(function(){
322
						bannerParallax();
323
					});
324
				}
325
			}
326
		}
327
328
		// Comments anchor
329
330
		if (document.location.hash == '#comments') {
331
			var margin = jQuery('body').hasClass('top-menu-fixed') ? jQuery('header.banner').height() : 0;
332
			margin += jQuery('body').hasClass('admin-bar') ? jQuery('#wpadminbar').height() : 0;
333
334
			jQuery('html, body').animate({
335
				scrollTop: jQuery('.comments-link').offset().top - margin
336
			}, 500, function() {
337
				jQuery('.comments-link').trigger('click');
338
			});
339
		}
340
341
		if ((new RegExp("#comment-", "gi")).test(document.location.hash)) {
342
			var margin = jQuery('body').hasClass('top-menu-fixed') ? jQuery('header.banner').height() : 0;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable margin already seems to be declared on line 331. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
343
			margin += jQuery('body').hasClass('admin-bar') ? jQuery('#wpadminbar').height() : 0;
344
345
			jQuery('html, body').animate({
346
				scrollTop: jQuery('.comments-link').offset().top - margin
347
			}, 500, function() {
348
				jQuery('.comments-link').trigger('click');
349
350
				jQuery('html, body').animate({
351
					scrollTop: jQuery(document.location.hash).offset().top - margin
352
				}, 500);
353
			});
354
		}
355
356
		// Sensei breadcrumb
357
		if ($('body').hasClass('sensei')) {
358
			if ($('header.archive-header').length > 0) {
359
				$('.woocommerce-breadcrumb').insertAfter('.archive-header');
360
361
				if ($('.woocommerce-breadcrumb').length > 1) {
362
					$('.woocommerce-breadcrumb').slice(1).remove();
363
				}
364
			}
365
		}
366
367
		//Lazy Load //Envira Gallery FIX
368
		var enviraIsotopUpdateLayout = function() {
369
			jQuery('.envira-gallery-wrap').each(function() {
370
				var id = jQuery(this).attr('id');
371
				id = id.replace('envira-gallery-wrap-', '');
372
373
				if (typeof envira_isotopes[id] == 'object') {
0 ignored issues
show
Bug introduced by
The variable envira_isotopes seems to be never declared. If this is a global, consider adding a /** global: envira_isotopes */ 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...
374
					envira_isotopes[id].enviratope('layout');
375
				}
376
			});
377
		};
378
379
		if (jQuery('.lazyload, .lazyloaded').length > 0) {
380
			if (typeof envira_isotopes == 'object') {
381
				$window.scroll(function(){
382
					enviraIsotopUpdateLayout();
383
				});
384
			}
385
		}
386
387
		//Final load - LAST CODE TO EXECUTE
388
		$('body.preloader-content-enable').addClass('html-loaded');
389
	});
390
});
391
392
393
///////////////////////////////
394
//Project thumbs
395
///////////////////////////////
396
397
function lsxProjectThumbInit() {
398
	
399
	if( jQuery(".filter-items-container .filter-item").length ){
400
		jQuery('.filter-items-container').imagesLoaded( function() {
401
			
402
			jQuery('.filter-items-container').masonry({
403
				resizable: true,
404
				columnWidth: filter_item_width,
405
				itemSelector: '.filter-item'
406
			});		
407
		});	
408
	}
409
}
410
411
412
///////////////////////////////
413
//Project Filtering
414
///////////////////////////////
415
416
function lsxProjectFilterInit() {
417
	
418
	jQuery('#filterNav a').click(function(){
419
		var selector = jQuery(this).attr('data-filter');
420
		selector = selector.replace('.','');
421
		
422
		jQuery('.filter-items-container .filter-item').each(function(){
423
			
424
			if(jQuery(this).hasClass(selector) || '*' === selector){
425
				jQuery(this).show();
426
			}else{
427
				jQuery(this).hide();
428
			}
429
			
430
		});
431
		
432
		jQuery('.filter-items-container').masonry({
433
			resizable: true,
434
			columnWidth: filter_item_width,
435
			itemSelector: '.filter-item'
436
				
437
		});
438
		
439
		jQuery(window).trigger('resize');
440
441
		if ( !jQuery(this).hasClass('selected') ) {
442
			jQuery(this).parents('#filterNav').find('.selected').removeClass('selected');
443
			jQuery(this).addClass('selected');
444
		}
445
446
		return false;
447
	});	
448
}