PageSourceSearch

https://www.cognacfestival.fr/wp-content/themes/vegadays/fw/js/core.init.js

js cognacfestival.fr collected 2026-10-08 09:23:21 UTC 55,951 bytes, 1,598 lines download raw bytes

1/* global jQuery:false */
2/* global VEGADAYS_STORAGE:false */
3
4jQuery(document).ready(function() {
5	"use strict";
6	VEGADAYS_STORAGE['theme_init_counter'] = 0;
7	vegadays_init_actions();
8});
9
10jQuery(window).on('beforeunload', function() {
11	"use strict";
12	// Show preloader
13    if (jQuery.browser && !jQuery.browser.safari) jQuery('#page_preloader').css({display: 'block', opacity: 0}).animate({opacity:0.8}, 300);
14});
15
16
17// Theme init actions
18function vegadays_init_actions() {
19	"use strict";
20
21	if (VEGADAYS_STORAGE['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length==0 && VEGADAYS_STORAGE['theme_init_counter']++ < 30) {
22		setTimeout(vegadays_init_actions, 200);
23		return;
24	}
25	
26	// Hide preloader
27	jQuery('#page_preloader').animate({opacity:0}, 500, function() { jQuery(this).css({display: 'none'}); });
28
29	// Check for Retina display
30	if (vegadays_is_retina()) {
31		vegadays_set_cookie('vegadays_retina', 1, 365);
32	}
33
34	vegadays_ready_actions();
35
36	// Add resize handlers after VC row stretch handlers on('resize.vcRowBehaviour', ...)
37	setTimeout(function() {
38		jQuery(window).on('resize.vegadays', function() {
39			vegadays_resize_actions();
40			vegadays_scroll_actions()
41		}).trigger('resize.vegadays');
42	}, 10);
43
44	// Scroll handlers
45	jQuery(window).on('scroll.vegadays', function() {
46		"use strict";
47		vegadays_scroll_actions();
48	});
49}
50
51
52
53// Theme first load actions
54//==============================================
55function vegadays_ready_actions() {
56	"use strict";
57
58	// Call theme specific action (if exists)
59    //----------------------------------------------
60	if (window.vegadays_theme_ready_actions) vegadays_theme_ready_actions();
61
62
63	// Widgets decoration
64    //----------------------------------------------
65
66	// Decorate nested lists in widgets and side panels
67	jQuery('.widget ul > li').each(function() {
68		if (jQuery(this).find('ul').length > 0) {
69			jQuery(this).addClass('has_children');
70		}
71	});
72
73
74	// Archive widget decoration
75	jQuery('.widget_archive a').each(function() {
76		var val = jQuery(this).html().split(' ');
77		if (val.length > 1) {
78			val[val.length-1] = '<span>' + val[val.length-1] + '</span>';
79			jQuery(this).html(val.join(' '))
80		}
81	});
82
83
84	// Navigate on category change
85	jQuery('.widget_subcategories').on('change', 'select', function() {
86		var dropdown = jQuery(this).get(0);
87		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
88			location.href = VEGADAYS_STORAGE['site_url'] + "/?cat="+dropdown.options[dropdown.selectedIndex].value;
89		}
90	});
91
92	
93	// Calendar handlers - change months
94	jQuery('.widget_calendar, .wp-calendar').on('click', '.month_prev a, .month_next a, .month_next a, .month_prev a', function(e) {
95		"use strict";
96		var calendar = jQuery(this).parents('.wp-calendar');
97		var m = jQuery(this).data('month');
98		var y = jQuery(this).data('year');
99		var l = jQuery(this).data('letter');
100		var pt = jQuery(this).data('type');
101		jQuery.post(VEGADAYS_STORAGE['ajax_url'], {
102			action: 'calendar_change_month',
103			nonce: VEGADAYS_STORAGE['ajax_nonce'],
104			letter: l,
105			month: m,
106			year: y,
107			post_type: pt
108		}).done(function(response) {
109			var rez = {};
110			try {
111				rez = JSON.parse(response);
112			} catch (e) {
113				rez = { error: VEGADAYS_STORAGE['ajax_error'] };
114				console.log(response);
115			}
116			if (rez.error === '') {
117				calendar.parent().fadeOut(200, function() {
118					jQuery(this).find('.wp-calendar').remove();
119					jQuery(this).append(rez.data).fadeIn(200);
120				});
121			}
122		});
123		e.preventDefault();
124		return false;
125	});
126
127
128	// Media setup
129    //----------------------------------------------
130
131	// Video background init
132	jQuery('.video_background').each(function() {
133		var youtube = jQuery(this).data('youtube-code');
134		if (youtube) {
135			jQuery(this).tubular({videoId: youtube});
136		}
137	});
138
139
140	// Main slider
141    //----------------------------------------------
142	jQuery('.slider_over_button,.slider_over_close').on('click', function(e) {
143		jQuery(this).parent().toggleClass('opened');
144		e.preventDefault();
145		return false;
146	});
147
148
149
150	// Menu
151    //----------------------------------------------
152
153	// Clone side menu for responsive
154	if (jQuery('ul#menu_side').length > 0) {
155		jQuery('ul#menu_side').clone().removeAttr('id').removeClass('menu_side_nav').addClass('menu_side_responsive').insertAfter('ul#menu_side');
156		vegadays_show_current_menu_item(jQuery('.menu_side_responsive'), jQuery('.sidebar_outer_menu_responsive_button'));
157	}
158	
159	// hide header mobile
160	if (jQuery('.header_mobile').length > 0) {
161		jQuery('.header_mobile .menu_main_nav a').each(function (){
162			"use strict";
163			var href = jQuery(this).attr('href');
164			if (href===undefined) return;
165			var aHref = jQuery(this).attr('href').indexOf("#");
166			if ( (aHref >= 0) && (href.length >1) ) {
167				jQuery(this).addClass('anchorClose');
168			}
169		});
170	}
171	
172	if (jQuery('.header_mobile').length > 0) {
173		jQuery('.header_mobile .menu_main_nav_area ul#menu_main').removeAttr('id');
174		jQuery('.header_mobile .menu_button').on('click', function(){
175			jQuery('.header_mobile .side_wrap').toggleClass('open');
176			jQuery('.header_mobile .mask').toggleClass('show');
177			jQuery('html').toggleClass('menu_mobile_open');
178			// Fix for Safari
179			if (vegadays_browser_is_ios() && jQuery('body').hasClass('menu_mobile')) {
180				jQuery('body').toggleClass('ios_fixed');
181			}
182		});
183		jQuery('.header_mobile .mask, .header_mobile .side_wrap .close, .anchorClose').on('click', function(){
184			jQuery('.header_mobile .side_wrap').removeClass('open');
185			jQuery('.header_mobile .mask').removeClass('show');
186			jQuery('html').removeClass('menu_mobile_open');
187			// Fix for Safari
188			if (vegadays_browser_is_ios() && jQuery('body').hasClass('menu_mobile')) {
189				jQuery('body').removeClass('ios_fixed');
190			}
191		});
192	}
193
194	// Push menu button
195	jQuery('.menu_pushy_button').on('click', function(e){
196		"use strict";
197		jQuery('body').addClass('pushy-active').css('overflow', 'hidden');
198		jQuery('.site-overlay').fadeIn('fast');
199		e.preventDefault();
200		return false;
201	});
202	jQuery('.pushy .close-pushy,.site-overlay').on('click', function(e){
203		jQuery('body').removeClass('pushy-active').css('overflow', 'visible');
204		jQuery('.site-overlay').fadeOut('fast');
205		e.preventDefault();
206		return false;
207	});
208	
209	// Side menu widgets button
210	jQuery('.sidebar_outer_widgets_button').on('click', function(e){
211		"use strict";
212		jQuery('.sidebar_outer_widgets').slideToggle();
213		e.preventDefault();
214		return false;
215	});
216
217	// Add arrows in responsive menu
218	jQuery('.header_mobile .menu_main_nav .menu-item-has-children > a, .menu_side_responsive .menu-item-has-children > a, .menu_pushy_nav_area .menu-item-has-children > a, body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories ul.product-categories .has_children > a').prepend('<span class="open_child_menu"></span>');
219
220	// Submenu click handler for the responsive menu
221	jQuery('.header_mobile .menu_main_nav, .menu_side_responsive, .menu_pushy_nav_area, body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories').on('click', 'li a,li a .open_child_menu, ul.product-categories.plain li a .open_child_menu', function(e) {
222		"use strict";
223		var is_menu_main = jQuery(this).parents('.menu_main_nav').length > 0;
224		var $a = jQuery(this).hasClass('open_child_menu') ? jQuery(this).parent() : jQuery(this);
225		if ((!is_menu_main || jQuery('body').hasClass('menu_mobile')) && ($a.parent().hasClass('menu-item-has-children') || $a.parent().hasClass('has_children'))) {
226			if ($a.siblings('ul:visible').length > 0)
227				$a.siblings('ul').slideUp().parent().removeClass('opened');
228			else {
229				jQuery(this).parents('li').siblings('li').find('ul:visible').slideUp().parent().removeClass('opened');
230				$a.siblings('ul').slideDown().parent().addClass('opened');
231			}
232		}
233		// Ignore link for parent menu items
234		if (jQuery(this).hasClass('open_child_menu') || $a.attr('href')=='#') {
235			e.preventDefault();
236			return false;
237		}
238	});
239	
240	// Init superfish menus
241	vegadays_init_sfmenu('.menu_main_nav_area ul#menu_main, ul#menu_user, ul#menu_side, body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories ul.product-categories');
242
243	// Slide effect for main menu
244	if (VEGADAYS_STORAGE['menu_hover']=='slide_line' || VEGADAYS_STORAGE['menu_hover']=='slide_box') {
245		setTimeout(function() {
246			"use strict";
247			jQuery('#menu_main').spasticNav({
248				style: VEGADAYS_STORAGE['menu_hover']=='slide_line' ? 'line' : 'box',
249				color: VEGADAYS_STORAGE['accent1_hover'],
250				colorOverride: false
251			});
252		}, 500);
253	}
254
255	// Show table of contents for the current page
256	if (VEGADAYS_STORAGE['toc_menu'] != 'hide' && VEGADAYS_STORAGE['toc_menu'] != 'no') {
257		vegadays_build_page_toc();
258	}
259
260	// One page mode for menu links (scroll to anchor)
261	jQuery('#toc, ul#menu_main li, ul#menu_user li, ul#menu_side li, ul#menu_footer li, ul#menu_pushy li').on('click', 'a', function(e) {
262		"use strict";
263		var href = jQuery(this).attr('href');
264		if (href===undefined) return;
265		var pos = href.indexOf('#');
266		if (pos < 0 || href.length == 1) return;
267		if (jQuery(href.substr(pos)).length > 0) {
268			var loc = window.location.href;
269			var pos2 = loc.indexOf('#');
270			if (pos2 > 0) loc = loc.substring(0, pos2);
271			var now = pos==0;
272			if (!now) now = loc == href.substring(0, pos);
273			if (now) {
274				vegadays_document_animate_to(href.substr(pos));
275				vegadays_document_set_location(pos==0 ? loc + href : href);
276				e.preventDefault();
277				return false;
278			}
279		}
280	});
281	
282	
283	// Store height of the top and side panels
284	VEGADAYS_STORAGE['top_panel_height'] = 0;	//Math.max(0, jQuery('.top_panel_wrap').height());
285	VEGADAYS_STORAGE['side_panel_height'] = 0;
286
287
288	// Pagination
289    //----------------------------------------------
290
291	// Page navigation (style slider)
292	jQuery('.pager_cur').on('click', function(e) {
293		"use strict";
294		jQuery('.pager_slider').slideDown(300, function() {
295			vegadays_sc_init(jQuery('.pager_slider').eq(0));
296		});
297		e.preventDefault();
298		return false;
299	});
300
301
302	// View More button
303	jQuery('#viewmore_link').on('click', function(e) {
304		"use strict";
305		if (!VEGADAYS_STORAGE['viewmore_busy'] && !jQuery(this).hasClass('viewmore_empty')) {
306			jQuery(this).parent().addClass('loading');
307			VEGADAYS_STORAGE['viewmore_busy'] = true;
308			jQuery.post(VEGADAYS_STORAGE['ajax_url'], {
309				action: 'view_more_posts',
310				nonce: VEGADAYS_STORAGE['ajax_nonce'],
311				page: VEGADAYS_STORAGE['viewmore_page']+1,
312				data: VEGADAYS_STORAGE['viewmore_data'],
313				vars: VEGADAYS_STORAGE['viewmore_vars']
314			}).done(function(response) {
315				"use strict";
316				var rez = {};
317				try {
318					rez = JSON.parse(response);
319				} catch (e) {
320					rez = { error: VEGADAYS_STORAGE['ajax_error'] };
321					console.log(response);
322				}
323				jQuery('#viewmore_link').parent().removeClass('loading');
324				VEGADAYS_STORAGE['viewmore_busy'] = false;
325				if (rez.error === '') {
326					var posts_container = jQuery('.content').eq(0);
327					if (posts_container.find('.isotope_wrap').length > 0) posts_container = posts_container.find('.isotope_wrap').eq(0);
328					if (posts_container.hasClass('isotope_wrap')) {
329						posts_container.data('last-width', 0).append(rez.data);
330						VEGADAYS_STORAGE['isotope_init_counter'] = 0;
331						vegadays_init_appended_isotope(posts_container, rez.filters);
332					} else
333						jQuery('#viewmore').before(rez.data);
334
335					VEGADAYS_STORAGE['viewmore_page']++;
336					if (rez.no_more_data==1) {
337						jQuery('#viewmore_link').addClass('viewmore_empty').parent().hide();
338					}
339
340					vegadays_init_post_formats();
341					vegadays_sc_init(posts_container);
342					vegadays_scroll_actions();
343				}
344			});
345		}
346		e.preventDefault();
347		return false;
348	});
349
350
351	// WooCommerce
352    //----------------------------------------------
353
354	// Change display mode
355	jQuery('.woocommerce,.woocommerce-page').on('click', '.mode_buttons a', function(e) {
356		"use strict";
357		var mode = jQuery(this).hasClass('woocommerce_thumbs') ? 'thumbs' : 'list';
358		vegadays_set_cookie('vegadays_shop_mode', mode, 365);
359		jQuery(this).siblings('input').val(mode).parents('form').get(0).submit();
360		e.preventDefault();
361		return false;
362	});
363	// Added to cart
364	jQuery('body').bind('added_to_cart', function() {
365		"use strict";
366		// Update amount on the cart button
367		var total = jQuery('.widget_shopping_cart').eq(0).find('.total .amount').text();
368		if (total != undefined) {
369			jQuery('.top_panel_cart_button .cart_summa').text(total);
370		}
371		// Update count items on the cart button
372		var cnt = 0;
373		jQuery('.widget_shopping_cart_content').eq(0).find('.cart_list li').each(function() {
374			var q = jQuery(this).find('.quantity').html().split(' ', 2);
375			if (!isNaN(q[0]))
376				cnt += Number(q[0]);
377		});
378		var items = jQuery('.top_panel_cart_button .cart_items').eq(0).text().split(' ', 2);
379		items[0] = cnt;
380		jQuery('.top_panel_cart_button .cart_items').text(items[0]+' '+items[1]);
381		// Update data-attr on button
382		jQuery('.top_panel_cart_button').data({
383			'items': cnt ? cnt : 0,
384			'summa': total ? total : 0
385		});
386	});
387	// Show cart 
388	jQuery('.top_panel_middle .top_panel_cart_button, .header_mobile .top_panel_cart_button').on('click', function(e) {
389		"use strict";
390		jQuery(this).siblings('.sidebar_cart').slideToggle();
391		e.preventDefault();
392		return false;
393	});
394
395// Increment arrows on number input
396    vegadays_wooc_style_arrows();
397    jQuery( document.body ).on( 'updated_cart_totals', function () {
398        vegadays_wooc_style_arrows();
399    });
400	// Add stretch behaviour to WooC tabs area
401	jQuery('.single-product .woocommerce-tabs')
402		.addClass('trx-stretch-width scheme_light')
403		.after('<div class="trx-stretch-width-original"></div>');
404	vegadays_stretch_width();
405
406
407	// Popup login and register windows
408    //----------------------------------------------
409	jQuery('.popup_link,.popup_login_link,.popup_register_link').addClass('inited').on('click', function(e){
410		var popup = jQuery(jQuery(this).attr('href'));
411		if (popup.length === 1) {
412			vegadays_hide_popup(jQuery(popup.hasClass('popup_login') ? '.popup_registration' : '.popup_login' ));
413			vegadays_show_popup(popup);
414		}
415		e.preventDefault();
416		return false;
417	});
418	jQuery('.popup_wrap').on('click', '.popup_close', function(e){
419		var popup = jQuery(this).parent();
420		if (popup.length === 1) {
421			vegadays_hide_popup(popup);
422		}
423		e.preventDefault();
424		return false;
425	});
426
427
428	// Bookmarks
429    //----------------------------------------------
430
431	// Add bookmark
432	jQuery('.bookmarks_add').on('click', function(e) {
433		"use strict";
434		var title = window.document.title.split('|')[0];
435		var url = window.location.href;
436		var list = vegadays_get_cookie('vegadays_bookmarks');
437		var exists = false;
438		if (list) {
439			try {
440				list = JSON.parse(list);
441			} catch (e) {}
442			if (list.length) {
443				for (var i=0; i<list.length; i++) {
444					if (list[i].url == url) {
445						exists = true;
446						break;
447					}
448				}
449			}
450		} else
451			list = new Array();
452		if (!exists) {
453			var message_popup = vegadays_message_dialog('<label for="bookmark_title">'+VEGADAYS_STORAGE['strings']['bookmark_title']+'</label><br><input type="text" id="bookmark_title" name="bookmark_title" value="'+title+'">', VEGADAYS_STORAGE['strings']['bookmark_add'], null,
454				function(btn, popup) {
455					"use strict";
456					if (btn != 1) return;
457					title = message_popup.find('#bookmark_title').val();
458					list.push({title: title, url: url});
459					jQuery('.bookmarks_list').append('<li><a href="'+url+'" class="bookmarks_item">'+title+'<span class="bookmarks_delete icon-cancel" title="'+VEGADAYS_STORAGE['strings']['bookmark_del']+'"></span></a></li>');
460					vegadays_set_cookie('vegadays_bookmarks', JSON.stringify(list), 365);
461					setTimeout(function () {vegadays_message_success(VEGADAYS_STORAGE['strings']['bookmark_added'], VEGADAYS_STORAGE['strings']['bookmark_add']);}, VEGADAYS_STORAGE['message_timeout']/4);
462				});
463		} else
464			vegadays_message_warning(VEGADAYS_STORAGE['strings']['bookmark_exists'], VEGADAYS_STORAGE['strings']['bookmark_add']);
465		e.preventDefault();
466		return false;
467	});
468
469	// Delete bookmark
470	jQuery('.bookmarks_list').on('click', '.bookmarks_delete', function(e) {
471		"use strict";
472		var idx = jQuery(this).parent().index();
473		var list = vegadays_get_cookie('vegadays_bookmarks');
474		if (list) {
475			try {
476				list = JSON.parse(list);
477			} catch (e) {}
478			if (list.length) {
479				list.splice(idx, 1);
480				vegadays_set_cookie('vegadays_bookmarks', JSON.stringify(list), 365);
481			}
482		}
483		jQuery(this).parent().remove();
484		e.preventDefault();
485		return false;
486	});
487
488    // Comments
489    //------------------------------------
490
491    // Checkbox with "I agree..."
492    if (jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited)').length > 0) {
493        jQuery('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited),input[type="checkbox"][name="gdpr_terms"]:not(.inited),input[type="checkbox"][name="wpgdprc"]:not(.inited)')
494            .addClass('inited')
495            .on('change', function(e) {
496                if (jQuery(this).get(0).checked)
497                    jQuery(this).parents('form').find('button,input[type="submit"]').removeAttr('disabled');
498                else
499                    jQuery(this).parents('form').find('button,input[type="submit"]').attr('disabled', 'disabled');
500            }).trigger('change');
501    }
502
503
504
505    // Other settings
506    //------------------------------------
507
508	// Scroll to top button
509	jQuery('.scroll_to_top').on('click', function(e) {
510		"use strict";
511		jQuery('html,body').animate({
512			scrollTop: 0
513		}, 'slow');
514		e.preventDefault();
515		return false;
516	});
517
518	// AJAX views counter
519	if (VEGADAYS_STORAGE['ajax_views_counter'] !== undefined) {
520		setTimeout(function(){
521			jQuery.post(VEGADAYS_STORAGE['ajax_url'], {
522				action: 'post_counter',
523				nonce: VEGADAYS_STORAGE['ajax_nonce'],
524				post_id: VEGADAYS_STORAGE['ajax_views_counter']['post_id'],
525				views: VEGADAYS_STORAGE['ajax_views_counter']['post_views']
526			});
527			}, 10);
528	}
529
530    // Show system message
531	vegadays_show_system_message();
532
533	// Init post format specific scripts
534	vegadays_init_post_formats();
535
536	// Call sc init action (if exists)
537	if (window.vegadays_sc_init_actions) vegadays_sc_init_actions();
538
539	// Init hidden elements (if exists)
540	if (window.vegadays_init_hidden_elements) vegadays_init_hidden_elements(jQuery('body').eq(0));
541
542    // Increment arrows on number input
543    function vegadays_wooc_style_arrows() {
544        "use strict";
545        // Add buttons to quantity
546        jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').append('<span class="q_inc"></span><span class="q_dec"></span>');
547        jQuery('.woocommerce div.quantity').on('click', '>span', function(e) {
548            var f = jQuery(this).siblings('input');
549            if (jQuery(this).hasClass('q_inc')) {
550                f.val( ( f.val() == '' ? 0 : parseInt( f.val(), 10 ) ) + 1 ).trigger( 'change' );
551            } else {
552                f.val( Math.max( 0, ( f.val() == '' ? 0 : parseInt( f.val(), 10 ) ) - 1 ) ).trigger( 'change' );
553            }
554            f.trigger('change');
555            jQuery( '.woocommerce-cart-form :input[name="update_cart"]' ).prop( 'disabled', false );
556            e.preventDefault();
557            return false;
558        });
559    }
560
561	 	// Contact Form 7 popup message
562	vegadays_rental_cf7_init();
563	
564} //end ready
565
566// Contact Form 7 popup message
567function vegadays_rental_cf7_init(e, container) {
568	if (container === undefined) container = jQuery('body');
569	if (container.length === undefined || container.length === 0) return;
570	
571	container.find('.wpcf7:not(.alert_inited)').each( function() {
572		var $form = jQuery(this);
573		// Decorate messages
574		$form
575			.addClass('alert_inited')
576			.on('wpcf7:submit wpcf7submit', function(e, details) {
577				var response = $form.find('.wpcf7-response-output');
578				if ( response.length ) {
579					response
580						.addClass('vegadays_rental_message_box')
581						.removeClass('vegadays_rental_message_box_info vegadays_rental_message_box_error vegadays_rental_message_box_success');
582					if ( typeof e == 'object' && typeof e.detail == 'object' && typeof e.detail.status != 'undefined' ) {
583						if ( e.detail.status == 'validation_failed' ) {
584							response.addClass('vegadays_rental_message_box_error');
585						} else if ( e.detail.status == 'mail_sent' ) {
586							response.addClass('vegadays_rental_message_box_success');
587						} else {
588							response.addClass('vegadays_rental_message_box_info');
589						}
590					}
591					response.fadeIn();
592				}
593			})
594			.on('click keypress change', function() {
595				$form.find('.wpcf7-response-output:visible').fadeOut();
596			} );
597		// Remove validation tip and class on any key pressed in the field
598		$form
599			.on('change', 'input,select,textarea', function() {
600				var $self = jQuery(this),
601					$wrap = $self.parents('.wpcf7-not-valid');
602				if ( $self.val() !== '' ) {
603					if ( $self.hasClass( 'wpcf7-not-valid' ) ) {
604						$self.removeClass('wpcf7-not-valid');
605					} else if ( $wrap.length > 0 ) {
606						$wrap.removeClass('wpcf7-not-valid');
607					}
608				}
609			});
610	} );
611}
612
613
614// Scroll actions
615//==============================================
616
617// Do actions when page scrolled
618function vegadays_scroll_actions() {
619	"use strict";
620	
621	// Call theme specific action (if exists)
622    //----------------------------------------------
623	if (window.vegadays_theme_scroll_actions) vegadays_theme_scroll_actions();
624
625	var scroll_offset = jQuery(window).scrollTop();
626	var scroll_to_top_button = jQuery('.scroll_to_top');
627	var adminbar_height = Math.max(0, jQuery('#wpadminbar').height());
628
629	if (VEGADAYS_STORAGE['top_panel_height'] < 1) {
630		VEGADAYS_STORAGE['top_panel_height'] = Math.max(0, jQuery('.top_panel_wrap').height());
631	}
632	
633	// Scroll to top button show/hide
634	if (scroll_offset > VEGADAYS_STORAGE['top_panel_height'])
635		scroll_to_top_button.addClass('show');
636	else
637		scroll_to_top_button.removeClass('show');
638	
639	// Fix/unfix top panel
640	if (!jQuery('body').hasClass('menu_mobile') && VEGADAYS_STORAGE['menu_fixed']) {
641		var slider_height = 0;
642		if (jQuery('.top_panel_below .slider_wrap').length > 0) {
643			slider_height = jQuery('.top_panel_below .slider_wrap').height();
644			if (slider_height < 10) {
645				slider_height = jQuery('.slider_wrap').hasClass('.slider_fullscreen') ? jQuery(window).height() : VEGADAYS_STORAGE['slider_height'];
646			}
647		}
648		if (scroll_offset <= slider_height + VEGADAYS_STORAGE['top_panel_height']) {
649			if (jQuery('body').hasClass('top_panel_fixed')) {
650				jQuery('body').removeClass('top_panel_fixed');
651			}
652		} else if (scroll_offset > slider_height + VEGADAYS_STORAGE['top_panel_height']) {
653			if (!jQuery('body').hasClass('top_panel_fixed') && jQuery(document).height() > jQuery(window).height()*1.5) {
654				jQuery('.top_panel_fixed_wrap').height(VEGADAYS_STORAGE['top_panel_height']);
655				jQuery('.top_panel_wrap').css('marginTop', '-150px').animate({'marginTop': 0}, 500);
656				jQuery('body').addClass('top_panel_fixed');
657			}
658		}
659	}
660	
661	// Fix/unfix side panel
662	if (jQuery('.sidebar_outer').length > 0) {
663		if (VEGADAYS_STORAGE['side_panel_height'] == 0)	
664			VEGADAYS_STORAGE['side_panel_height'] = jQuery('.sidebar_outer_logo_wrap').outerHeight() + jQuery('.sidebar_outer_menu').outerHeight() + jQuery('.sidebar_outer_widgets').outerHeight();
665		if (scroll_offset + jQuery(window).height() > VEGADAYS_STORAGE['side_panel_height'] + 100) {
666			if (jQuery('.sidebar_outer').css('position')!=='fixed') {
667				jQuery('.sidebar_outer').css({
668					'position': 'fixed',
669					'top': Math.min(0, jQuery(window).height() - VEGADAYS_STORAGE['side_panel_height'] - 100) + 'px',
670				});
671			}
672		} else {
673			if (jQuery('.sidebar_outer').css('position')=='fixed') {
674				jQuery('.sidebar_outer').css({
675					'position': 'absolute',
676					'top': 0
677				});
678			}
679		}
680	}
681
682	// TOC current items
683	jQuery('#toc .toc_item').each(function() {
684		"use strict";
685		var id = jQuery(this).find('a').attr('href');
686		var pos = id.indexOf('#');
687		if (pos < 0 || id.length == 1) return;
688		var loc = window.location.href;
689		var pos2 = loc.indexOf('#');
690		if (pos2 > 0) loc = loc.substring(0, pos2);
691		var now = pos==0;
692		if (!now) now = loc == href.substring(0, pos);
693		if (!now) return;
694		var off = jQuery(id).offset().top;
695		var id_next  = jQuery(this).next().find('a').attr('href');
696		var off_next = id_next ? jQuery(id_next).offset().top : 1000000;
697		if (off < scroll_offset + jQuery(window).height()*0.8 && scroll_offset + VEGADAYS_STORAGE['top_panel_height'] < off_next)
698			jQuery(this).addClass('current');
699		else
700			jQuery(this).removeClass('current');
701	});
702	
703	// Infinite pagination
704	vegadays_infinite_scroll()
705	
706	// Parallax scroll
707	vegadays_parallax_scroll();
708
709	// Call sc scroll actions (if exists)
710	if (window.vegadays_sc_scroll_actions) vegadays_sc_scroll_actions();
711}
712
713
714// Infinite Scroll
715function vegadays_infinite_scroll() {
716	"use strict";
717	if (VEGADAYS_STORAGE['viewmore_busy']) return;
718	var infinite = jQuery('#viewmore.pagination_infinite');
719	if (infinite.length > 0) {
720		var viewmore = infinite.find('#viewmore_link:not(.viewmore_empty)');
721		if (viewmore.length > 0) {
722			if (jQuery(window).scrollTop() + jQuery(window).height() + 100 >= infinite.offset().top) {
723				viewmore.eq(0).trigger('click');
724			}
725		}
726	}
727}
728
729// Parallax scroll
730function vegadays_parallax_scroll(){
731    "use strict";
732	jQuery('.sc_parallax').each(function(){
733		var windowHeight = jQuery(window).height();
734		var scrollTops = jQuery(window).scrollTop();
735		var offsetPrx = Math.max(jQuery(this).offset().top, windowHeight);
736		if ( offsetPrx <= scrollTops + windowHeight ) {
737			var speed  = Number(jQuery(this).data('parallax-speed'));
738			var xpos   = jQuery(this).data('parallax-x-pos');  
739			var ypos   = Math.round((offsetPrx - scrollTops - windowHeight) * speed + (speed < 0 ? windowHeight*speed : 0));
740			jQuery(this).find('.sc_parallax_content').css('backgroundPosition', xpos+' '+ypos+'px');
741			// Uncomment next line if you want parallax video (else - video position is static)
742			jQuery(this).find('div.sc_video_bg').css('top', ypos+'px');
743		} 
744	});
745}
746
747
748
749
750
751// Resize actions
752//==============================================
753
754// Do actions when page scrolled
755function vegadays_resize_actions() {
756	"use strict";
757
758	// Call theme specific action (if exists)
759    //----------------------------------------------
760	if (window.vegadays_theme_resize_actions) vegadays_theme_resize_actions();
761
762	// Reset stored value
763	VEGADAYS_STORAGE['top_panel_height'] = 0;
764
765	vegadays_responsive_menu();
766	vegadays_vc_row_fullwidth_to_boxed();
767	vegadays_video_dimensions();
768	vegadays_resize_video_background();
769	vegadays_resize_fullscreen_slider();
770	vegadays_resize_alter_portfolio();
771	vegadays_stretch_width();
772
773	// Call sc resize actions (if exists)
774	if (window.vegadays_sc_resize_actions) vegadays_sc_resize_actions();
775}
776
777// Stretch area to full window width
778function vegadays_stretch_width() {
779	"use strict";
780	jQuery('.trx-stretch-width').each(function() {
781		var $el = jQuery(this);
782		var $el_full = $el.next('.trx-stretch-width-original');
783		var el_margin_left = parseInt( $el.css( 'margin-left' ), 10 );
784		var el_margin_right = parseInt( $el.css( 'margin-right' ), 10 );
785		var offset = 0 - $el_full.offset().left - el_margin_left;
786		var width = jQuery( window ).width();
787		if (!$el.hasClass('inited')) {
788			$el.addClass('inited invisible');
789			$el.css({
790				'position': 'relative',
791				'box-sizing': 'border-box'
792			});
793		}
794		$el.css({
795			'left': offset,
796			'width': jQuery( window ).width()
797		});
798		if ( !$el.hasClass('trx-stretch-content') ) {
799			var padding = Math.max(0, -1*offset);
800			var paddingRight = Math.max(0, width - padding - $el_full.width() + el_margin_left + el_margin_right);
801			$el.css( { 'padding-left': padding + 'px', 'padding-right': paddingRight + 'px' } );
802		}
803		$el.removeClass('invisible');
804	});
805}
806
807// Width vc_row when content boxed
808function vegadays_vc_row_fullwidth_to_boxed(){
809	"use strict";
810   if (jQuery('body').hasClass('body_style_boxed')) {
811       var width_body = jQuery('body').width();
812       var width_content = jQuery('.page_wrap').width();
813       var width_content_wrap = jQuery('.page_content_wrap  .content_wrap').width();
814       var indent = ( width_content - width_content_wrap ) / 2;
815	   if ( width_body > width_content ){
816		   jQuery('.vc_row[data-vc-full-width="true"]').each( function() {
817				"use strict";
818				var mrg = parseInt(jQuery(this).css('marginLeft'));
819				jQuery(this).css({
820					'width': width_content,
821					'left': -indent-mrg,
822					'padding-left': indent+mrg,
823					'padding-right': indent+mrg
824				});
825				if (jQuery(this).attr('data-vc-stretch-content')) {
826				   jQuery(this).css({
827					   'padding-left': 0,
828					   'padding-right': 0
829				   });
830				}
831		   });
832	   }
833   }
834}
835
836// Check window size and do responsive menu
837function vegadays_responsive_menu() {
838	"use strict";
839	if (vegadays_is_responsive_need(VEGADAYS_STORAGE['menu_mobile'])) {
840		if (!jQuery('body').hasClass('menu_mobile')) {
841			jQuery('body').removeClass('top_panel_fixed').addClass('menu_mobile');
842			jQuery('header.top_panel_wrap ').hide();
843			jQuery('.header_mobile').show();
844			
845			jQuery('header #popup_login').attr('id', 'popup_login_1');
846			jQuery('header #popup_registration').attr('id', 'popup_registration_1');
847			jQuery('.header_mobile #popup_login_1').attr('id', 'popup_login');
848			jQuery('.header_mobile #popup_registration_1').attr('id', 'popup_registration');
849		}
850	} else {
851		if (jQuery('body').hasClass('menu_mobile')) {
852			jQuery('body').removeClass('menu_mobile');
853			jQuery('header.top_panel_wrap ').show();
854			jQuery('.header_mobile').hide();
855			
856			jQuery('header #popup_login_1').attr('id', 'popup_login');
857			jQuery('header #popup_registration_1').attr('id', 'popup_registration');
858			jQuery('.header_mobile #popup_login').attr('id', 'popup_login_1');
859			jQuery('.header_mobile #popup_registration').attr('id', 'popup_registration_1');
860		}
861	}
862	
863	if (jQuery(window).width() < 640) {
864		var pass = jQuery('.header_mobile .popup_wrap.popup_registration .registration_form > .form_right');
865		if(pass.length > 0){ 
866			jQuery('.header_mobile .popup_wrap.popup_registration .form_left .popup_form_field.email_field').after(pass);
867		}
868	}
869	else{
870		var pass = jQuery('.header_mobile .popup_wrap.popup_registration .form_left > .form_right');
871		if(pass.length > 0){ 
872			jQuery('.header_mobile .popup_wrap.popup_registration .registration_form').append(pass);
873		}
874	}
875
876	if (!jQuery('.top_panel_wrap').hasClass('menu_show')) jQuery('.top_panel_wrap').addClass('menu_show');
877	// Show widgets block on the sidebar outer (if sidebar not responsive and widgets are hidden)
878	if (jQuery('.sidebar_outer').length > 0 && jQuery('.sidebar_outer').css('position')=='absolute' && jQuery('.sidebar_outer_widgets:visible').length==0) 
879		jQuery('.sidebar_outer_widgets').show();
880	// Switch popup menu / hierarchical list on product categories list placed in sidebar
881	var cat_menu = jQuery('body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories ul.product-categories');
882	var sb = cat_menu.parents('.widget_area');
883	if (sb.length > 0 && cat_menu.length > 0) {
884		if (sb.width() == sb.parents('.content_wrap').width()) {
885			if (cat_menu.hasClass('inited')) {
886				cat_menu.removeClass('inited').addClass('plain').superfish('destroy');
887				cat_menu.find('ul.animated').removeClass('animated').addClass('no_animated');
888			}
889		} else {
890			if (!cat_menu.hasClass('inited')) {
891				cat_menu.removeClass('plain').addClass('inited');
892				cat_menu.find('ul.no_animated').removeClass('no_animated').addClass('animated');
893				vegadays_init_sfmenu('body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories ul.product-categories');
894			}
895		}
896	}
897}
898
899
900// Check if responsive menu need
901function vegadays_is_responsive_need(max_width) {
902	"use strict";
903	var rez = false;
904	if (max_width > 0) {
905		var w = window.innerWidth;
906		if (w == undefined) {
907			w = jQuery(window).width()+(jQuery(window).height() < jQuery(document).height() || jQuery(window).scrollTop() > 0 ? 16 : 0);
908		}
909		rez = max_width > w;
910	}
911	return rez;
912}
913
914
915// Fit video frames to document width
916function vegadays_video_dimensions() {
917    "use strict";
918	jQuery('.sc_video_frame').each(function() {
919		"use strict";
920		if (jQuery(this).parents('div:hidden,article:hidden').length > 0) return;
921		var frame  = jQuery(this).eq(0);
922		var player = frame.parent();
923		var ratio = (frame.data('ratio') ? frame.data('ratio').split(':') : (frame.find('[data-ratio]').length>0 ? frame.find('[data-ratio]').data('ratio').split(':') : [16,9]));
924		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
925		var w_attr = frame.data('width');
926		var h_attr = frame.data('height');
927		if (!w_attr || !h_attr) return;
928		var percent = (''+w_attr).substr(-1)=='%';
929		w_attr = parseInt(w_attr);
930		h_attr = parseInt(h_attr);
931		var w_real = Math.min(percent || frame.parents('.columns_wrap').length>0 ? 10000 : w_attr, frame.parents('div,article').width()), //player.width();
932			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
933		if (parseInt(frame.attr('data-last-width'))==w_real) return;
934		if (percent) {
935			frame.height(h_real);
936		} else {
937			frame.css({'width': w_real+'px', 'height': h_real+'px'});
938		}
939		frame.attr('data-last-width', w_real);
940	});
941	jQuery('video.sc_video,video.wp-video-shortcode').each(function() {
942		"use strict";
943		if (jQuery(this).parents('div:hidden,article:hidden').length > 0) return;
944		var video = jQuery(this).eq(0);
945		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
946		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
947		var mejs_cont = video.parents('.mejs-video');
948		var frame = video.parents('.sc_video_frame');
949		var w_attr = frame.length>0 ? frame.data('width') : video.data('width');
950		var h_attr = frame.length>0 ? frame.data('height') : video.data('height');
951		if (!w_attr || !h_attr) {
952			w_attr = video.attr('width');
953			h_attr = video.attr('height');
954			if (!w_attr || !h_attr) return;
955			video.data({'width': w_attr, 'height': h_attr});
956		}
957		var percent = (''+w_attr).substr(-1)=='%';
958		w_attr = parseInt(w_attr);
959		h_attr = parseInt(h_attr);
960		var w_real = Math.round(mejs_cont.length > 0 ? Math.min(percent ? 10000 : w_attr, mejs_cont.parents('div,article').width()) : video.width()),
961			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
962		if (parseInt(video.attr('data-last-width'))==w_real) return;
963		if (mejs_cont.length > 0 && mejs) {
964			vegadays_set_mejs_player_dimensions(video, w_real, h_real);
965		}
966		if (percent) {
967			video.height(h_real);
968		} else {
969			video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'});
970		}
971		video.attr('data-last-width', w_real);
972	});
973	jQuery('video.sc_video_bg').each(function() {
974		"use strict";
975		if (jQuery(this).parents('div:hidden,article:hidden').length > 0) return;
976		var video = jQuery(this).eq(0);
977		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
978		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
979		var mejs_cont = video.parents('.mejs-video');
980		var container = mejs_cont.length>0 ? mejs_cont.parent() : video.parent();
981		var w = container.width();
982		var h = container.height();
983		var w1 = Math.ceil(h*ratio);
984		var h1 = Math.ceil(w/ratio);
985		if (video.parents('.sc_parallax').length > 0) {
986			var windowHeight = jQuery(window).height();
987			var speed = Number(video.parents('.sc_parallax').data('parallax-speed'));
988			var h_add = Math.ceil(Math.abs((windowHeight-h)*speed));
989			if (h1 < h + h_add) {
990				h1 = h + h_add;
991				w1 = Math.ceil(h1 * ratio);
992			}
993		}
994		if (h1 < h) {
995			h1 = h;
996			w1 = Math.ceil(h1 * ratio);
997		}
998		if (w1 < w) { 
999			w1 = w;
1000			h1 = Math.ceil(w1 / ratio);
1001		}
1002		var l = Math.round((w1-w)/2);
1003		var t = Math.round((h1-h)/2);
1004		if (parseInt(video.attr('data-last-width'))==w1) return;
1005		if (mejs_cont.length > 0) {
1006			vegadays_set_mejs_player_dimensions(video, w1, h1);
1007			mejs_cont.css({
1008				//'left': -l+'px',
1009				'top': -t+'px'
1010			});
1011		} else
1012			video.css({
1013				//'left': -l+'px',
1014				'top': -t+'px'
1015			});
1016		video.attr({'width': w1, 'height': h1, 'data-last-width':w1}).css({'width':w1+'px', 'height':h1+'px'});
1017		if (video.css('opacity')==0) video.animate({'opacity': 1}, 3000);
1018	});
1019	jQuery('iframe').each(function() {
1020		"use strict";
1021		if (jQuery(this).parents('div:hidden,article:hidden').length > 0) return;
1022		var iframe = jQuery(this).eq(0);
1023		var ratio = (iframe.data('ratio')!=undefined ? iframe.data('ratio').split(':') : (iframe.find('[data-ratio]').length>0 ? iframe.find('[data-ratio]').data('ratio').split(':') : [16,9]));
1024		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
1025		var w_attr = iframe.attr('width');
1026		var h_attr = iframe.attr('height');
1027		var frame = iframe.parents('.sc_video_frame');
1028		if (frame.length > 0) {
1029			w_attr = frame.data('width');
1030			h_attr = frame.data('height');
1031		}
1032		if (!w_attr || !h_attr) {
1033			return;
1034		}
1035		var percent = (''+w_attr).substr(-1)=='%';
1036		w_attr = parseInt(w_attr);
1037		h_attr = parseInt(h_attr);
1038		var w_real = frame.length > 0 ? frame.width() : iframe.width(),
1039			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
1040		if (parseInt(iframe.attr('data-last-width'))==w_real) return;
1041		iframe.css({'width': w_real+'px', 'height': h_real+'px'});
1042	});
1043}
1044
1045// Resize fullscreen video background
1046function vegadays_resize_video_background() {
1047	"use strict";
1048	var bg = jQuery('.video_bg');
1049	if (bg.length < 1) 
1050		return;
1051	if (VEGADAYS_STORAGE['media_elements_enabled'] && bg.find('.mejs-video').length == 0)  {
1052		setTimeout(vegadays_resize_video_background, 100);
1053		return;
1054	}
1055	var video = bg.find('video');
1056	var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
1057	ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
1058	var w = bg.width();
1059	var h = bg.height();
1060	var w1 = Math.ceil(h*ratio);
1061	var h1 = Math.ceil(w/ratio);
1062	if (h1 < h) {
1063		h1 = h;
1064		w1 = Math.ceil(h1 * ratio);
1065	}
1066	if (w1 < w) { 
1067		w1 = w;
1068		h1 = Math.ceil(w1 / ratio);
1069	}
1070	var l = Math.round((w1-w)/2);
1071	var t = Math.round((h1-h)/2);
1072	if (bg.find('.mejs-container').length > 0) {
1073		vegadays_set_mejs_player_dimensions(bg.find('video'), w1, h1);
1074		bg.find('.mejs-container').css({'left': -l+'px', 'top': -t+'px'});
1075	} else
1076		bg.find('video').css({'left': -l+'px', 'top': -t+'px'});
1077	bg.find('video').attr({'width': w1, 'height': h1}).css({'width':w1+'px', 'height':h1+'px'});
1078}
1079
1080// Set Media Elements player dimensions
1081function vegadays_set_mejs_player_dimensions(video, w, h) {
1082	"use strict";
1083	if (mejs) {
1084		for (var pl in mejs.players) {
1085			if (mejs.players[pl].media.src == video.attr('src')) {
1086				if (mejs.players[pl].media.setVideoSize) {
1087					mejs.players[pl].media.setVideoSize(w, h);
1088				}
1089				mejs.players[pl].setPlayerSize(w, h);
1090				mejs.players[pl].setControlsSize();
1091			}
1092		}
1093	}
1094}
1095
1096// Resize Fullscreen Slider
1097function vegadays_resize_fullscreen_slider() {
1098	"use strict";
1099	var slider_wrap = jQuery('.slider_wrap.slider_fullscreen');
1100	if (slider_wrap.length < 1) 
1101		return;
1102	var slider = slider_wrap.find('.sc_slider_swiper');
1103	if (slider.length < 1) 
1104		return;
1105	var h = jQuery(window).height() - jQuery('#wpadminbar').height() - (jQuery('body').hasClass('top_panel_above') && !jQuery('body').hasClass('.top_panel_fixed') ? jQuery('.top_panel_wrap').height() : 0);
1106	slider.height(h);
1107}
1108
1109// Resize Alter portfolio elements
1110function vegadays_resize_alter_portfolio() {
1111	"use strict";
1112	var wrap = jQuery('.isotope_wrap.inited');
1113	if (wrap.length==0) return;
1114	wrap.each(function() {
1115		"use strict";
1116		var alter = jQuery(this).find('.post_item_alter');
1117		if (alter.length==0) return;
1118		var single = alter.find('.post_featured img[data-alter-items-w="1"]').eq(0);
1119		if (single.length != 1) return;
1120		var w_real = single.width();
1121		var h_real = single.height();
1122		var space = Number(single.data('alter-item-space'));
1123		var relayout = false;
1124		alter.find('.post_featured img').each(function() {
1125			"use strict";
1126			var items_w = Number(jQuery(this).data('alter-items-w'));
1127			var items_h = Number(jQuery(this).data('alter-items-h'));
1128			if (items_h > 1) {
1129				jQuery(this).height(Math.round(items_h*h_real+(items_h-1)*(space+1)));
1130				relayout = true;
1131			} else if (items_w > 1) {
1132				jQuery(this).height(h_real);
1133				relayout = true;
1134			}
1135		});
1136		if (relayout) {
1137			jQuery(this).isotope('layout');
1138		}
1139	});
1140}
1141
1142
1143
1144
1145
1146// Navigation
1147//==============================================
1148
1149// Init Superfish menu
1150function vegadays_init_sfmenu(selector) {
1151    "use strict";
1152	jQuery(selector).show().each(function() {
1153		if (vegadays_is_responsive_need() && (jQuery(this).attr('id')=='menu_main' || jQuery(this).attr('id')=='menu_side')) return;
1154		jQuery(this).addClass('inited').superfish({
1155			delay: 500,
1156			animation: {
1157				opacity: 'show'
1158			},
1159			animationOut: {
1160				opacity: 'hide'
1161			},
1162			speed: 		VEGADAYS_STORAGE['css_animation'] ? 500 : 200,
1163			speedOut:	VEGADAYS_STORAGE['css_animation'] ? 500 : 200,
1164			autoArrows: false,
1165			dropShadows: false,
1166			onBeforeShow: function(ul) {
1167				if (jQuery(this).parents("ul").length > 1){
1168					var w = jQuery(window).width();  
1169					var par_offset = jQuery(this).parents("ul").offset().left;
1170					var par_width  = jQuery(this).parents("ul").outerWidth();
1171					var ul_width   = jQuery(this).outerWidth();
1172					if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0)
1173						jQuery(this).addClass('submenu_left');
1174					else
1175						jQuery(this).removeClass('submenu_left');
1176				}
1177				if (VEGADAYS_STORAGE['css_animation']) {
1178					jQuery(this).removeClass('animated fast '+VEGADAYS_STORAGE['menu_animation_out']);
1179					jQuery(this).addClass('animated fast '+VEGADAYS_STORAGE['menu_animation_in']);
1180				}
1181			},
1182			onBeforeHide: function(ul) {
1183				if (VEGADAYS_STORAGE['css_animation']) {
1184					jQuery(this).removeClass('animated fast '+VEGADAYS_STORAGE['menu_animation_in']);
1185					jQuery(this).addClass('animated fast '+VEGADAYS_STORAGE['menu_animation_out']);
1186				}
1187			}
1188		});
1189	});
1190}
1191
1192
1193// Build page TOC from the tag's id
1194function vegadays_build_page_toc() {
1195	"use strict";
1196	var toc = '', toc_count = 0;
1197	jQuery('[id^="toc_"],.sc_anchor').each(function(idx) {
1198		"use strict";
1199		var obj = jQuery(this);
1200		var id = obj.attr('id');
1201		var url = obj.data('url');
1202		var icon = obj.data('icon');
1203		if (!icon) icon = 'icon-circle-dot';
1204		var title = obj.attr('title');
1205		var description = obj.data('description');
1206		var separator = obj.data('separator');
1207		toc_count++;
1208		toc += '<div class="toc_item'+(separator=='yes' ? ' toc_separator' : '')+'">'
1209			+(description ? '<div class="toc_description">'+description+'</div>' : '')
1210			+'<a href="'+(url ? url : '#'+id)+'" class="toc_icon'+(title ? ' with_title' : '')+' '+icon+'">'+(title ? '<span class="toc_title">'+title+'</span>' : '')+'</a>'
1211			+'</div>';
1212	});
1213	if (toc_count > (VEGADAYS_STORAGE['toc_menu_home'] ? 1 : 0) + (VEGADAYS_STORAGE['toc_menu_top'] ? 1 : 0)) {
1214		if (jQuery('#toc').length > 0)
1215			jQuery('#toc .toc_inner').html(toc);
1216		else
1217			jQuery('body').append('<div id="toc" class="toc_'+VEGADAYS_STORAGE['toc_menu']+'"><div class="toc_inner">'+toc+'</div></div>');
1218	}
1219}
1220
1221
1222// Show current page title on the responsive menu button
1223function vegadays_show_current_menu_item(menu, button) {
1224	"use strict";
1225	menu.find('a').each(function () {
1226		var menu_link = jQuery(this);
1227		if (menu_link.text() == "") {
1228			return;
1229		}
1230		if (menu_link.attr('href') == window.location.href)
1231			button.text(menu_link.text());
1232	});
1233}
1234
1235
1236
1237// Isotope
1238//=====================================================
1239
1240// First init isotope containers
1241function vegadays_init_isotope() {
1242	"use strict";
1243
1244	var all_images_complete = true;
1245
1246	// Check if all images in isotope wrapper are loaded
1247	jQuery('.isotope_wrap:not(.inited)').each(function () {
1248		"use strict";
1249		all_images_complete = all_images_complete && vegadays_check_images_complete(jQuery(this));
1250	});
1251	// Wait for images loading
1252	if (!all_images_complete && VEGADAYS_STORAGE['isotope_init_counter']++ < 30) {
1253		setTimeout(vegadays_init_isotope, 200);
1254		return;
1255	}
1256
1257	// Isotope filters handler
1258	jQuery('.isotope_filters:not(.inited)').addClass('inited').on('click', 'a', function(e) {
1259		"use strict";
1260		jQuery(this).parents('.isotope_filters').find('a').removeClass('active');
1261		jQuery(this).addClass('active');
1262	
1263		var selector = jQuery(this).data('filter');
1264		jQuery(this).parents('.isotope_filters').siblings('.isotope_wrap').eq(0).isotope({
1265			filter: selector
1266		});
1267
1268		if (selector == '*')
1269			jQuery('#viewmore_link').fadeIn();
1270		else
1271			jQuery('#viewmore_link').fadeOut();
1272
1273		e.preventDefault();
1274		return false;
1275	});
1276
1277	// Init isotope script
1278	jQuery('.isotope_wrap:not(.inited)').each(function() {
1279		"use strict";
1280
1281		var isotope_container = jQuery(this);
1282
1283		// Init shortcodes
1284		vegadays_sc_init(isotope_container);
1285
1286		// If in scroll container - no init isotope
1287		if (isotope_container.parents('.sc_scroll').length > 0) {
1288			isotope_container.addClass('inited').find('.isotope_item').animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
1289			return;
1290		}
1291		
1292		// Init isotope with timeout
1293		setTimeout(function() {
1294			isotope_container.addClass('inited').isotope({
1295				itemSelector: '.isotope_item',
1296				animationOptions: {
1297					duration: 750,
1298					easing: 'linear',
1299					queue: false
1300				}
1301			});
1302	
1303			// Show elements
1304			isotope_container.find('.isotope_item').animate({opacity: 1}, 200, function () { 
1305				jQuery(this).addClass('isotope_item_show'); 
1306			});
1307			
1308			// Resize Alter portfolio elements
1309			vegadays_resize_alter_portfolio();
1310			
1311		}, 500);
1312
1313	});		
1314}
1315
1316function vegadays_init_appended_isotope(posts_container, filters) {
1317	"use strict";
1318	
1319	if (posts_container.parents('.sc_scroll_horizontal').length > 0) return;
1320	
1321	if (!vegadays_check_images_complete(posts_container) && VEGADAYS_STORAGE['isotope_init_counter']++ < 30) {
1322		setTimeout(function() { vegadays_init_appended_isotope(posts_container, filters); }, 200);
1323		return;
1324	}
1325	// Add filters
1326	var flt = posts_container.siblings('.isotope_filter');
1327	for (var i in filters) {
1328		if (flt.find('a[data-filter=".flt_'+i+'"]').length == 0) {
1329			flt.append('<a href="#" class="isotope_filters_button" data-filter=".flt_'+i+'">'+filters[i]+'</a>');
1330		}
1331	}
1332	// Init shortcodes in added elements
1333	vegadays_sc_init(posts_container);
1334	// Get added elements
1335	var elems = posts_container.find('.isotope_item:not(.isotope_item_show)');
1336	// Notify isotope about added elements with timeout
1337	setTimeout(function() {
1338		posts_container.isotope('appended', elems);
1339		// Show appended elements
1340		elems.animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
1341	}, 500);
1342}
1343
1344
1345
1346// Post formats init
1347//=====================================================
1348
1349function vegadays_init_post_formats() {
1350	"use strict";
1351
1352	// Call theme specific action (if exists)
1353	if (window.vegadays_theme_init_post_formats) vegadays_theme_init_post_formats();
1354
1355	// MediaElement init
1356	vegadays_init_media_elements(jQuery('body'));
1357	
1358	// Isotope first init
1359	if (jQuery('.isotope_wrap:not(.inited)').length > 0) {
1360		VEGADAYS_STORAGE['isotope_init_counter'] = 0;
1361		vegadays_init_isotope();
1362	}
1363
1364	// Hover Effect 'Dir'
1365	if (jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').length > 0) {
1366		jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').each(function() {
1367			jQuery(this).addClass('inited').hoverdir();
1368		});
1369	}
1370
1371	// Popup init
1372	if (VEGADAYS_STORAGE['popup_engine'] == 'pretty') {
1373		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'prettyPhoto[slideshow]');
1374		var images = jQuery("a[rel*='prettyPhoto']:not(.inited):not(.esgbox):not([data-rel*='pretty']):not([rel*='magnific']):not([data-rel*='magnific'])").addClass('inited');
1375		try {
1376			images.prettyPhoto({
1377				social_tools: '',
1378				theme: 'facebook',
1379				deeplinking: false
1380			});
1381		} catch (e) {};
1382	} else if (VEGADAYS_STORAGE['popup_engine']=='magnific') {
1383		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'magnific');
1384		var images = jQuery("a[rel*='magnific']:not(.inited):not(.esgbox):not(.prettyphoto):not([rel*='pretty']):not([data-rel*='pretty'])").addClass('inited');
1385		try {
1386			images.magnificPopup({
1387				type: 'image',
1388				mainClass: 'mfp-img-mobile',
1389				closeOnContentClick: true,
1390				closeBtnInside: true,
1391				fixedContentPos: true,
1392				midClick: true,
1393				//removalDelay: 500, 
1394				preloader: true,
1395				tLoading: VEGADAYS_STORAGE['strings']['magnific_loading'],
1396				gallery:{
1397					enabled: true
1398				},
1399				image: {
1400					tError: VEGADAYS_STORAGE['strings']['magnific_error'],
1401					verticalFit: true
1402				}
1403			});
1404		} catch (e) {};
1405	}
1406
1407
1408	// Add hover icon to products thumbnails
1409	jQuery(".post_item_product .product .images a.woocommerce-main-image:not(.hover_icon)").addClass('hover_icon hover_icon_view');
1410
1411
1412	// Likes counter
1413	if (jQuery('.post_counters_likes:not(.inited)').length > 0) {
1414		jQuery('.post_counters_likes:not(.inited)')
1415			.addClass('inited')
1416			.on('click', function(e) {
1417				var button = jQuery(this);
1418				var inc = button.hasClass('enabled') ? 1 : -1;
1419				var post_id = button.data('postid');
1420				var likes = Number(button.data('likes'))+inc;
1421				var cookie_likes = vegadays_get_cookie('vegadays_likes');
1422				if (cookie_likes === undefined || cookie_likes===null) cookie_likes = '';
1423				jQuery.post(VEGADAYS_STORAGE['ajax_url'], {
1424					action: 'post_counter',
1425					nonce: VEGADAYS_STORAGE['ajax_nonce'],
1426					post_id: post_id,
1427					likes: likes
1428				}).done(function(response) {
1429					var rez = {};
1430					try {
1431						rez = JSON.parse(response);
1432					} catch (e) {
1433						rez = { error: VEGADAYS_STORAGE['ajax_error'] };
1434						console.log(response);
1435					}
1436					if (rez.error === '') {
1437						if (inc == 1) {
1438							var title = button.data('title-dislike');
1439							button.removeClass('enabled').addClass('disabled');
1440							cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ',';
1441						} else {
1442							var title = button.data('title-like');
1443							button.removeClass('disabled').addClass('enabled');
1444							cookie_likes = cookie_likes.replace(','+post_id+',', ',');
1445						}
1446						button.data('likes', likes).attr('title', title).find('.post_counters_number').html(likes);
1447						vegadays_set_cookie('vegadays_likes', cookie_likes, 365);
1448					} else {
1449						vegadays_message_warning(VEGADAYS_STORAGE['strings']['error_like']);
1450					}
1451				});
1452				e.preventDefault();
1453				return false;
1454			});
1455	}
1456
1457	// Social share links
1458	if (jQuery('.sc_socials_share:not(.inited)').length > 0) {
1459		jQuery('.sc_socials_share:not(.inited)').each(function() {
1460			"use strict";
1461			jQuery(this).addClass('inited').on('click', '.social_item_popup > a.social_icons', function(e) {
1462				"use strict";
1463				var url = jQuery(this).data('link');
1464				window.open(url, '_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=480, height=400, toolbar=0, status=0');
1465				e.preventDefault();
1466				return false;
1467			});
1468		});
1469	}
1470
1471	// Add video on thumb click
1472	if (jQuery('.sc_video_play_button:not(.inited)').length > 0) {
1473		jQuery('.sc_video_play_button:not(.inited)').each(function() {
1474			"use strict";
1475			jQuery(this)
1476				.addClass('inited')
1477				.animate({opacity: 1}, 1000)
1478				.on('click', function (e) {
1479					"use strict";
1480					if (!jQuery(this).hasClass('sc_video_play_button')) return;
1481					var video = jQuery(this).removeClass('sc_video_play_button hover_icon hover_icon_play').data('video');
1482					if (video!=='') {
1483						jQuery(this).empty().html(video);
1484						vegadays_video_dimensions();
1485						var video_tag = jQuery(this).find('video');
1486						var w = video_tag.width();
1487						var h = video_tag.height();
1488						vegadays_init_media_elements(jQuery(this));
1489						// Restore WxH attributes, because Chrome broke it!
1490						jQuery(this).find('video').css({'width':w, 'height': h}).attr({'width':w, 'height': h});
1491					}
1492					e.preventDefault();
1493					return false;
1494				});
1495		});
1496	}
1497}
1498
1499
1500function vegadays_init_media_elements(cont) {
1501    "use strict";
1502	if (VEGADAYS_STORAGE['media_elements_enabled'] && cont.find('audio,video').length > 0) {
1503		if (window.mejs) {
1504            if (typeof window.mejs.MepDefaults != 'undefined') window.mejs.MepDefaults.enableAutosize = false;
1505            if (typeof window.mejs.MediaElementDefaults != 'undefined') window.mejs.MediaElementDefaults.enableAutosize = false;
1506			cont.find('audio:not(.wp-audio-shortcode),video:not(.wp-video-shortcode)').each(function() {
1507                if (jQuery(this).parents('.mejs-mediaelement').length == 0
1508                    && !jQuery(this).parent().hasClass('wp-playlist')
1509						  && jQuery(this).parents('figure.wp-block-media-text__media').length == 0					
1510                    && jQuery( this ).parents( '.wp-block-video' ).length == 0
1511                    && ! jQuery( this ).hasClass( 'wp-block-cover__video-background' )) {
1512					var media_tag = jQuery(this);
1513					var settings = {
1514						enableAutosize: true,
1515						videoWidth: -1,		// if set, overrides <video width>
1516						videoHeight: -1,	// if set, overrides <video height>
1517						audioWidth: '100%',	// width of audio player
1518						audioHeight: 30,	// height of audio player
1519						success: function(mejs) {
1520							var autoplay, loop;
1521							if ( 'flash' === mejs.pluginType ) {
1522								autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
1523								loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
1524								autoplay && mejs.addEventListener( 'canplay', function () {
1525									mejs.play();
1526								}, false );
1527								loop && mejs.addEventListener( 'ended', function () {
1528									mejs.play();
1529								}, false );
1530							}
1531							media_tag.parents('.sc_audio,.sc_video').addClass('inited sc_show');
1532						}
1533					};
1534					jQuery(this).mediaelementplayer(settings);
1535				}
1536			});
1537		} else
1538			setTimeout(function() { vegadays_init_media_elements(cont); }, 400);
1539	}
1540}
1541
1542
1543
1544
1545
1546
1547// Popups and system messages
1548//==============================================
1549
1550// Show system message (bubble from previous page)
1551function vegadays_show_system_message() {
1552    "use strict";
1553	if (VEGADAYS_STORAGE['system_message'] && VEGADAYS_STORAGE['system_message']['message']) {
1554		if (VEGADAYS_STORAGE['system_message']['status'] == 'success')
1555			vegadays_message_success(VEGADAYS_STORAGE['system_message']['message'], VEGADAYS_STORAGE['system_message']['header']);
1556		else if (VEGADAYS_STORAGE['system_message']['status'] == 'info')
1557			vegadays_message_info(VEGADAYS_STORAGE['system_message']['message'], VEGADAYS_STORAGE['system_message']['header']);
1558		else if (VEGADAYS_STORAGE['system_message']['status'] == 'error' || VEGADAYS_STORAGE['system_message']['status'] == 'warning')
1559			vegadays_message_warning(VEGADAYS_STORAGE['system_message']['message'], VEGADAYS_STORAGE['system_message']['header']);
1560	}
1561}
1562
1563// Toggle popups
1564function vegadays_toggle_popup(popup) {
1565    "use strict";
1566	if (popup.css('display')!='none')
1567		vegadays_hide_popup(popup);
1568	else
1569		vegadays_show_popup(popup);
1570}
1571
1572// Show popups
1573function vegadays_show_popup(popup) {
1574    "use strict";
1575	if (popup.css('display')=='none') {
1576		if (false && VEGADAYS_STORAGE['css_animation'])
1577			popup.show().removeClass('animated fast '+VEGADAYS_STORAGE['menu_animation_out']).addClass('animated fast '+VEGADAYS_STORAGE['menu_animation_in']);
1578		else
1579			popup.slideDown();
1580	}
1581}
1582
1583// Hide popups
1584function vegadays_hide_popup(popup) {
1585    "use strict";
1586	if (popup.css('display')!='none') {
1587		if (false && VEGADAYS_STORAGE['css_animation'])
1588			popup.removeClass('animated fast '+VEGADAYS_STORAGE['menu_animation_in']).addClass('animated fast '+VEGADAYS_STORAGE['menu_animation_out']).delay(500).hide();
1589		else
1590			popup.fadeOut();
1591	}
1592}
1593
1594//Open new windows in new tab
1595jQuery('a').filter(function() {
1596    "use strict";
1597    return this.hostname && this.hostname !== location.hostname;
1598}).attr('target','_blank');

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.