PageSourceSearch

https://snobahn.com/wp-content/themes/snowy/js/init.js?reload=1956148845

js snobahn.com collected 2026-10-05 05:53:03 UTC 94,154 bytes, 2,735 lines download raw bytes

1/* global jQuery, SNOWY_STORAGE */
2
3jQuery( document ).ready( function() {
4
5	"use strict";
6
7	var ready_busy = true;
8
9	var theme_init_counter = 0;
10
11	var $window   = jQuery( window ),
12		$document = jQuery( document ),
13		$body     = jQuery( 'body' );
14
15	var $body_wrap,
16		$page_wrap,
17		$header,
18		$footer,
19		$menu_side_wrap,
20		$menu_side_logo;
21
22	var _header_height = 0,
23		_footer_height = 0;
24
25	var $page_content_wrap,
26		$content,
27		$sidebar,
28		cur_page_title_selector,
29		$cur_page_title_tag,
30		// Single post parts
31		$single_nav_links_fixed,
32		$single_post_info_fixed,
33		$single_post_scrollers,
34		$stretch_width;
35
36	var $nav_link_infinite;
37
38
39	// Update links after the new post added
40	$document.on( 'action.new_post_added', update_jquery_links );
41	$document.on( 'action.got_ajax_response', update_jquery_links );
42	$document.on( 'action.init_hidden_elements', update_jquery_links );
43	var first_run = true;
44	function update_jquery_links(e) {
45		if ( first_run && e && e.namespace == 'init_hidden_elements' ) {
46			first_run = false;
47			return; 
48		}
49		$body_wrap              = jQuery( '.body_wrap' ),
50		$page_wrap              = jQuery( '.page_wrap' ),
51		$header                 = jQuery( '.top_panel' ),
52		_header_height          = $header.length === 0 ? 0 : $header.height(),
53		$footer                 = jQuery( '.footer_wrap' ),
54		_footer_height          = $footer.length === 0 ? 0 : $footer.height(),
55		$menu_side_wrap         = jQuery( '.menu_side_wrap' ),
56		$menu_side_logo         = $menu_side_wrap.find( '.sc_layouts_logo' );
57		$page_content_wrap      = jQuery( '.page_content_wrap' );
58		$content                = jQuery( '.content' );
59		$sidebar                = jQuery( '.sidebar:not(.sidebar_fixed_placeholder)' );
60		cur_page_title_selector = snowy_apply_filters( 'snowy_filter_page_title_selector', '.sc_layouts_title_caption, head title' );
61		$cur_page_title_tag     = jQuery( cur_page_title_selector ).eq(0);
62		$nav_link_infinite      = jQuery( '.nav-links-infinite' );
63		// Single post parts
64		$single_nav_links_fixed = jQuery( '.nav-links-single.nav-links-fixed' );
65		$single_post_info_fixed = jQuery( '.post_info_vertical.post_info_vertical_fixed' );
66		$single_post_scrollers  = jQuery( '.nav-links-single-scroll' );
67		$stretch_width          = jQuery( '.trx-stretch-width' );
68	}
69	update_jquery_links();
70
71
72	// Init actions
73	//-----------------------------------
74
75	// Init intersection observer
76	snowy_intersection_observer_init();
77
78	// Init all other actions
79	snowy_init_actions();
80
81	function snowy_init_actions() {
82
83		if (SNOWY_STORAGE['vc_edit_mode'] && jQuery( '.vc_empty-placeholder' ).length === 0 && theme_init_counter++ < 30) {
84			setTimeout( snowy_init_actions, 200 );
85			return;
86		}
87
88		// Resize handlers
89		$window.on( 'resize', function() {
90			snowy_resize_actions();
91		} );
92
93		// Scroll handlers
94		SNOWY_STORAGE['scroll_busy'] = true;
95		$window.on( 'scroll', function() {
96			if (window.requestAnimationFrame) {
97				if ( ! SNOWY_STORAGE['scroll_busy']) {
98					window.requestAnimationFrame( function() {
99						snowy_scroll_actions();
100					});
101					SNOWY_STORAGE['scroll_busy'] = true;
102				}
103			} else {
104				snowy_scroll_actions();
105			}
106		} );
107
108		// Add scheme class and js support
109		document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/,'js' );
110		if (document.documentElement.className.indexOf( SNOWY_STORAGE['site_scheme'] ) == -1) {
111			document.documentElement.className += ' ' + SNOWY_STORAGE['site_scheme'];
112		}
113
114		// First call to init core actions
115		snowy_ready_actions();
116		snowy_resize_actions();
117		snowy_scroll_actions();
118
119	}   // snowy_init_actions
120
121
122	// Theme first load actions
123	//==============================================
124	function snowy_ready_actions() {
125
126		// Skip to content link
127		$body
128			.on( 'focus', 'a.snowy_skip_link', function() {
129				if ( ! $body.hasClass( 'show_outline' ) ) {
130					$body.addClass( 'show_outline' );
131				}
132			} )
133			.on( 'click', 'a.snowy_skip_link', function() {
134				var id = jQuery(this).attr('href');
135				jQuery(id).focus();
136			} );
137
138
139		// Detect the keyboard usage to show outline around links and fields
140		$body.on( 'keydown', 'a,input,textarea,select,span[tabindex]', function( e ) {
141			if ( 9 == e.which ) {
142				if ( ! $body.hasClass( 'show_outline' ) ) {
143					$body.addClass( 'show_outline' );
144				}
145			}
146		} );
147
148
149		// Menus
150		//-------------------------------------
151		$document
152			.on( 'keyup', function(e) {
153				if ( e.keyCode == 27 ) {
154					if ( jQuery( '.menu_mobile.opened' ).length == 1 ) {
155						snowy_mobile_menu_close();
156						e.preventDefault();
157						return false;
158					}
159				}
160			} )
161			.on( 'action.trx_addons_inner_links_click', function( e, link_obj, original_e ) {
162				if ( $body.hasClass( 'menu_mobile_opened' ) ) {
163					// Removing class before menu closing animations started
164					// is need to animate inner links and scrolling to the anchor
165					$body.removeClass( 'menu_mobile_opened' );
166					snowy_mobile_menu_close();
167				}
168			} );
169
170
171		// Pagination
172		//------------------------------------
173
174		// Infinite scroll in the blog streampages
175		$document.on( 'action.scroll_snowy', function(e) {
176			snowy_infinite_scroll_in_blog();
177		} );
178
179		// Infinite scroll in the single posts
180		$document.on( 'action.scroll_snowy', function(e) {
181			snowy_infinite_scroll_in_single();
182		} );
183
184		// Mark single post as readed
185		if ( $body.hasClass('single') ) {
186			snowy_add_to_read_list( jQuery('.content > article[data-post-id]').data('post-id') );
187		}
188
189		// Mark readed posts
190		$document.on( 'action.init_hidden_elements', function( e, cont ) {
191			var read_list = snowy_get_storage('snowy_post_read');
192			if ( read_list && read_list.charAt(0) == '[' ) {
193				read_list = JSON.parse( read_list );
194				for ( var p = 0; p < read_list.length; p++ ) {
195					var read_post = cont.find('[data-post-id="' + read_list[ p ] + '"]');
196					if ( ! read_post.hasClass('full_post_read') && ! read_post.parent().hasClass('content') ) {
197						read_post.addClass('full_post_read');
198					}
199				}
200			}
201		} );
202
203
204		// Comments
205		//------------------------------------
206
207		// Scroll to comments (if hidden)
208		if ( location.hash == '#comments' || location.hash == '#respond' ) {
209			var $show_comments_button = jQuery( '.show_comments_button' );
210			if ( $show_comments_button.length == 1 && ! $show_comments_button.hasClass( 'opened' ) ) {
211				$show_comments_button.trigger( 'click' );
212				snowy_document_animate_to( location.hash );
213			}
214		}
215
216		// Other settings
217		//------------------------------------
218		$document.trigger( 'action.ready_snowy' );
219
220		// Blocks with stretch width
221		//----------------------------------------------
222		// Action to prepare stretch blocks in the third-party plugins
223		$document.trigger( 'action.prepare_stretch_width' );
224		// Wrap stretch blocks
225		$stretch_width = jQuery( '.trx-stretch-width' );
226		$stretch_width.wrap( '<div class="trx-stretch-width-wrap"></div>' );
227		$stretch_width.after( '<div class="trx-stretch-width-original"></div>' );
228		snowy_stretch_width();
229
230		// Add theme-specific handlers on 'action.init_hidden_elements'
231		//---------------------------------------------------------------
232		$document.on( 'action.init_hidden_elements', snowy_init_post_formats );
233		$document.on( 'action.init_hidden_elements', snowy_add_toc_to_sidemenu );
234
235 		// Init hidden elements
236		$document.trigger( 'action.init_hidden_elements', [$body.eq(0)] );
237
238	} // snowy_ready_actions
239
240
241
242	// Post formats init
243	//=====================================================
244	function snowy_init_post_formats(e, cont) {
245
246		// Menu
247		snowy_init_menus( cont );
248
249		// Wrap select with .select_container
250		snowy_add_select_container( cont );
251
252		// Use Bideo or Tubular to play a local video
253		snowy_init_bg_video( cont );
254
255		// Tabs
256		snowy_init_tabs( cont );
257
258		// Accordion
259		snowy_init_accordion( cont );
260
261		// Sidebar open/close
262		snowy_init_sidebar_control( cont );
263
264		// Masonry posts
265		snowy_init_masonry( cont );
266
267		// Load more
268		snowy_init_load_more( cont );
269
270		// Open single post right in the blog or in the shortcode "Blogger"
271		snowy_init_load_single_post( cont );
272
273		// MediaElement init
274		snowy_init_media_elements( cont );
275
276		// Video play button
277		snowy_init_video_play_button( cont );
278
279		// Show/Hide Comments
280		snowy_init_comments_button( cont );
281
282		// Show comments block when link '#comments' or '#respond' is clicked
283		snowy_init_comments_links( cont );
284
285		// Checkbox with "I agree..."
286		snowy_init_checkbox_i_agree( cont );
287
288	}  // snowy_init_post_formats
289
290
291	// Wrap select with .select_container
292	function snowy_add_select_container( cont ) {
293		if ( SNOWY_STORAGE['select_container_disabled'] || $body.hasClass( 'wp-admin' ) || $body.hasClass( 'wp-customizer' ) ) {
294			return;
295		}
296		var selector = snowy_apply_filters(
297			'snowy_filter_select_container_selector',
298			'select:not(.esg-sorting-select):not([class*="trx_addons_attrib_"]):not(#rating)'	//:not([size])
299		);
300		if ( selector ) {
301			cont.find( selector ).each( function() {
302				var $self = jQuery( this );
303				if ( $self.css( 'display' ) != 'none'
304					&& $self.parents( '.select_container' ).length === 0
305					&& ! $self.next().hasClass( 'select2' )
306					&& ! $self.hasClass( 'select2-hidden-accessible' )
307					&& ! $self.hasClass( 'components-select-control__input' )
308				) {
309					var add_class = '';
310					if ( $self.prop( 'size' ) > 1 ) {
311						add_class += ' select_container_multirows';
312					}
313					if ( $self.prop( 'multiple' ) ) {
314						add_class += ' select_container_multiple';
315					}
316					$self.wrap( '<div class="select_container' + add_class + '"></div>' );
317					// Bubble submit() up for widget "Categories"
318					if ( $self.parents( snowy_apply_filters( 'snowy_filter_bubble_submit_form', '.widget_categories' ) ).length > 0 ) {
319						$self.parent().get(0).submit = function() {
320							jQuery(this).closest('form').eq(0).submit();
321						};
322					}
323				}
324			} );
325		}
326	}
327	// Add select_container on 'ajaxComplete'
328	$document.on( 'ajaxComplete', function(e) {
329		// Trigger event after timeout to allow other scripts add elements on the page
330		setTimeout( function() {
331			snowy_add_select_container( $body );
332		}, 100 );
333	} );
334
335
336	// Use Bideo or Tubular to play a local video
337	function snowy_init_bg_video( cont ) {
338		var $top_panel_with_bg_video = cont.find( '.top_panel.with_bg_video:not(.inited)' ).addClass( 'inited' );
339		if ( SNOWY_STORAGE['background_video'] && $top_panel_with_bg_video.length > 0 && window.Bideo ) {
340			// Waiting 10ms after mejs init
341			setTimeout(
342				function() {
343					$top_panel_with_bg_video.prepend( '<video id="background_video" loop muted></video>' );
344					var bv = new Bideo();
345					bv.init(
346						{
347							// Video element
348							videoEl: document.querySelector( '#background_video' ),
349
350							// Container element
351							container: document.querySelector( '.top_panel' ),
352
353							// Resize
354							resize: true,
355
356							// autoplay: false,
357
358							isMobile: window.matchMedia( '(max-width: 768px)' ).matches,
359
360							playButton: document.querySelector( '#background_video_play' ),
361							pauseButton: document.querySelector( '#background_video_pause' ),
362
363							// Array of objects containing the src and type
364							// of different video formats to add
365							// For example:
366							//	src: [
367							//			{	src: 'night.mp4', type: 'video/mp4' }
368							//			{	src: 'night.webm', type: 'video/webm;codecs="vp8, vorbis"' }
369							//		]
370							src: [
371							{
372								src: SNOWY_STORAGE['background_video'],
373								type: 'video/' + snowy_get_file_ext( SNOWY_STORAGE['background_video'] )
374							}
375							],
376
377							// What to do once video loads (initial frame)
378							onLoad: function () {
379								//document.querySelector('#background_video_cover').style.display = 'none';
380							}
381						}
382					);
383				}, 10
384			);
385
386			// Use Tubular to play video from Youtube
387		} else if ( jQuery.fn.tubular ) {
388			cont.find( '#background_video:not(.inited)' ).each( function() {
389				var $self = jQuery( this ).addClass( 'inited' );
390				var youtube_code = $self.data( 'youtube-code' );
391				if ( youtube_code ) {
392					$self.tubular( { videoId: youtube_code } );
393					jQuery( '#tubular-player' ).appendTo( $self ).show();
394					jQuery( '#tubular-container,#tubular-shield' ).remove();
395				}
396			} );
397		}
398	}
399
400
401	// Init media elements
402	//--------------------------------------------
403	SNOWY_STORAGE['mejs_attempts'] = 0;
404	function snowy_init_media_elements(cont) {
405		var audio_selector = snowy_apply_filters( 'snowy_filter_mediaelements_audio_selector', 'audio:not(.inited):not([src*=".ogg"])' ),
406			video_selector = snowy_apply_filters( 'snowy_filter_mediaelements_video_selector', 'video:not(.inited):not([nocontrol
406s]):not([controls="0"]):not([controls="false"]):not([controls="no"])' ),	//:not([autoplay])
407			media_selector = audio_selector + ( audio_selector && video_selector ? ',' : '') + video_selector;
408		if (SNOWY_STORAGE['use_mediaelements'] && cont.find( media_selector ).length > 0) {
409			if ( window.mejs ) {
410				if (window.mejs.MepDefaults) {
411					window.mejs.MepDefaults.enableAutosize = true;
412				}
413				if (window.mejs.MediaElementDefaults) {
414					window.mejs.MediaElementDefaults.enableAutosize = true;
415				}
416				// Disable init for video[autoplay]
417				cont.find(
418						  // Old shortcode 'wp-video'
419						  'video.wp-video-shortcode[autoplay],'
420						+ 'video.wp-video-shortcode[nocontrols],'
421						+ 'video.wp-video-shortcode[controls="0"],'
422						+ 'video.wp-video-shortcode[controls="false"],'
423						+ 'video.wp-video-shortcode[controls="no"],'
424						// New block 'video'
425						+ '.wp-block-video > video[autoplay],'
426						+ '.wp-block-video > video[nocontrols],'
427						+ '.wp-block-video > video[controls="0"],'
428						+ '.wp-block-video > video[controls="false"],'
429						+ '.wp-block-video > video[controls="no"]'
430						)
431					.removeClass('wp-video-shortcode');
432				// Init mediaelements
433				cont.find( media_selector ).each(
434					function() {
435						var $self = jQuery( this );
436						// If item now invisible or it's a video in the Revolution Slider
437						if (   $self.parents( 'div:hidden,section:hidden,article:hidden' ).length > 0
438							|| $self.parent().is( 'rs-bgvideo' )
439							|| $self.parents( 'rs-slide' ).length > 0
440						) {
441							return;
442						}
443						var not_init_in_containers = snowy_apply_filters( 'snowy_filter_mediaelements_not_init_in_containers',
444														'.mejs-mediaelement'
445														+ ',.wp-block-cover'
446														+ ',.wp-block-video'
447														+ ',.wp-block-media-text'
448														+ ',.elementor-background-video-container'
449														+ ',.elementor-widget-video'
450														+ ',.with_video_autoplay'
451														+ ',.slider-slide'
452														+ ',.sc_layouts_title'
453														// + ',.mfp-content'
454														// Uncomment the next row to 
455														// disable mediaelements init on the Elementor's video shortcode
456														// to support a video ratio, specified in a shortcode parameters
457														// + ',.elementor-fit-aspect-ratio'
458													);
459						if (   ! $self.hasClass( 'no-mejs' )
460							&& ! $self.hasClass( 'no-mediaelement' )
461							&& ! $self.hasClass( 'wp-block-cover__video-background' )
462							// && ! $self.attr( 'autoplay' )
463							&& $self.addClass( 'inited' ).parents( not_init_in_containers ).length === 0
464							&& ( SNOWY_STORAGE['init_all_mediaelements']
465								|| ( ! $self.hasClass( 'wp-audio-shortcode' )
466									&& ! $self.hasClass( 'wp-video-shortcode' )
467									&& ! $self.parent().hasClass( 'wp-playlist' )
468									)
469								)
470						) {
471							// Fix for iOS
472							if ( snowy_browser_is_ios( true ) ) {
473								// Video on the single car and property pages should be preloaded to show the poster
474								if ( $self.parents( '.cars_page_video_wrap,.properties_page_video_wrap' ).length ) {
475									$self.attr( {
476										'preload': 'auto'
477									} );
478								}
479							}
480							var settings = {
481									enableAutosize: true,
482								videoWidth:  '100%',
483								videoHeight: '100%',
484								audioWidth:  '100%',
485								audioHeight: 40,
486									success: function(mejs) {
487										if ( mejs.pluginType && 'flash' === mejs.pluginType && mejs.attributes ) {
488											mejs.attributes.autoplay
489												&& 'false' !== mejs.attributes.autoplay
490												&& mejs.addEventListener( 'canplay', function () { mejs.play(); }, false );
491											mejs.attributes.loop
492												&& 'false' !== mejs.attributes.loop
493												&& mejs.addEventListener( 'ended', function () { mejs.play(); }, false );
494										}
495									}
496								};
497
498							// If video is inside a container, get the container's width
499							if ( $self.is( 'video' ) ) {
500								var media_cont = $self.parents('.sc_layouts_popup').eq(0);
501								// If video is inside a popup
502								if ( media_cont.length ) {
503									var w_attr = $self.attr( 'width' ),
504										h_attr = $self.attr( 'height' ),
505										h_cont = snowy_window_height() * 0.75;	// This coefficient must be the less than max-height of the popup (in the layouts.scss)
506									if ( w_attr && h_attr ) {
507										settings.videoWidth  = w_attr * h_cont / h_attr;
508										settings.videoHeight = h_cont;
509										media_cont.parents( '.mfp-content' ).eq(0).css( { 'min-width': 'unset' } );
510									}
511								} else {
512									// Uncomment (remove false) to set the container's dimensions as the video's dimensions
513									// Default dimensions are set 100% width and 100% height
514									if ( false ) {
515										var media_cont = $self.parents('.post_video').eq(0);
516										if ( media_cont.length === 0 ) {
517											media_cont = $self.parents('.video_frame').eq(0);
518											if ( media_cont.length === 0 ) {
519												media_cont = $self.parent();
520											}
521										}
522										if ( media_cont.length > 0 ) {
523											settings.videoWidth = media_cont.width();
524											settings.videoHeight = media_cont.height();
525										}
526									}
527								}
528							}
529							$self.mediaelementplayer( settings );
530						}
531					}
532				);
533			} else if ( SNOWY_STORAGE['mejs_attempts']++ < 5 ) {
534				setTimeout( function() { snowy_init_media_elements( cont ); }, 400 );
535			}
536		}
537		// Init all media elements after first run
538		setTimeout( function() { SNOWY_STORAGE['init_all_mediaelements'] = true; }, 1000 );
539	}
540
541
542	// Video play button
543	function snowy_init_video_play_button( cont ) {
544		cont.find( '.post_featured.with_thumb .post_video_hover:not(.post_video_hover_popup):not(.inited)' )
545			.addClass( 'inited' )
546			.on( 'click', function(e) {
547				var $self = jQuery( this ),
548					$post_featured = $self.parents( '.post_featured' ).eq(0).addClass( 'post_video_play' );
549				// Replace a content of the container with the video player
550				if ( typeof trx_addons_insert_video_iframe === 'function' ) {
551					trx_addons_insert_video_iframe( $post_featured.find( '.post_video' ), $self.data('video') );
552				} else {
553					$post_featured.find( '.post_video' ).html( $self.data( 'video' ) );
554				}
555				$document.trigger( 'action.init_hidden_elements', [ $post_featured ] );
556				$window.trigger( 'resize' );
557				e.preventDefault();
558				return false;
559			} )
560			.parents('.post_featured')
561			.on( 'click', function(e) {
562				var $self = jQuery(this);
563				if ( ! $self.hasClass( 'post_video_play' ) && ! jQuery( e.target ).is( 'a' ) && ! jQuery( e.target ).parents( 'a' ).length ) {
564					jQuery(this).find( '.post_video_hover' ).trigger( 'click' );
565					e.preventDefault();
566					return false;
567				}
568			} );
569	}
570
571
572	// Accordion
573	function snowy_init_accordion( cont ) {
574		if (jQuery.ui && jQuery.ui.accordion) {
575			cont.find( '.snowy_accordion:not(.inited)' ).each( function () {
576				var $self = jQuery( this );
577				var headers = $self.data( 'headers' ) || '.snowy_accordion_title';
578				// Get height style
579				var height_style = $self.data( 'height-style' ) || 'content';
580				// Get collapsible
581				var collapsible = $self.data( 'collapsible' ) || false;
582				// Get initially opened tab
583				var init = $self.data( 'active' );
584				var active = false;
585				if ( isNaN( init ) ) {
586					init = 0;
587					active = $self.find( headers + '[data-active="true"]' ).eq( 0 );
588					if ( active.length > 0 ) {
589						while ( ! active.parent().hasClass( 'snowy_accordion' ) ) {
590							active = active.parent();
591						}
592						init = active.index();
593						if ( isNaN( init ) || init < 0 ) init = 0;
594					}
595				} else {
596					init = Math.max( 0, init );
597				}
598
599				// Init accordion
600				$self.addClass( 'inited' ).accordion( {
601					'active': init,
602					'collapsible': collapsible,
603					'header': headers,
604					'heightStyle': height_style,
605					'create': function( event, ui ) {
606						if ( ui.panel.length > 0 && ! ready_busy ) {
607							$document.trigger( 'action.create_accordion', [ui.panel] );
608							$document.trigger( 'action.init_hidden_elements', [ui.panel] );
609						} else if ( active !== false && active.length > 0 ) {
610							// If headers and panels wrapped into div
611							active.find( '>' + headers ).trigger( 'click' );
612						}
613					},
614					'activate': function( event, ui ) {
615						if ( ui.oldPanel.length > 0 && ! ready_busy ) {
616							$document.trigger( 'action.deactivate_accordion', [ui.oldPanel] );
617						}
618						if ( ui.newPanel.length > 0 && ! ready_busy ) {
619							$document.trigger( 'action.activate_accordion', [ui.newPanel] );
620							$document.trigger( 'action.init_hidden_elements', [ui.newPanel] );
621							$window.trigger( 'resize' );
622						}
623					}
624				} );
625			} );
626		}
627	}
628
629
630	// Tabs
631	function snowy_init_tabs( cont ) {
632		if ( jQuery.ui && jQuery.ui.tabs ) {
633			cont.find( '.snowy_tabs:not(.inited)' ).each( function () {
634				var $self = jQuery( this );
635				// Get initially opened tab
636				var init = $self.data( 'active' );
637				if ( isNaN( init ) ) {
638					init       = 0;
639					var active = $self.find( '> ul > li[data-active="true"]' ).eq( 0 );
640					if ( active.length > 0 ) {
641						init = active.index();
642						if (isNaN( init ) || init < 0) {
643							init = 0;
644						}
645					}
646				} else {
647					init = Math.max( 0, init );
648				}
649				// Init tabs
650				$self.addClass( 'inited' ).tabs( {
651					active: init,
652					show: {
653						effect: 'fadeIn',
654						duration: 300
655					},
656					hide: {
657						effect: 'fadeOut',
658						duration: 300
659					},
660					create: function( event, ui ) {
661						if ( ui.panel.length > 0 && ! ready_busy ) {
662							$document.trigger( 'action.create_tab', [ui.panel] );
663							$document.trigger( 'action.init_hidden_elements', [ui.panel] );
664						}
665					},
666					activate: function( event, ui ) {
667						if ( ui.oldPanel.length > 0 && ! ready_busy ) {
668							$document.trigger( 'action.deactivate_tab', [ui.oldPanel] );
669						}
670						if ( ui.newPanel.length > 0 && ! ready_busy ) {
671							$document.trigger( 'action.activate_tab', [ui.newPanel] );
672							$document.trigger( 'action.init_hidden_elements', [ui.newPanel] );
673							$window.trigger('resize');
674						}
675					}
676				} );
677				// AJAX loader
678				if ( $self.hasClass( 'snowy_tabs_ajax' ) ) {
679					// AJAX loader for the tabs
680					$self.on( 'tabsbeforeactivate', function( event, ui ) {
681						if ( ui.newPanel.data( 'need-content' ) ) {
682							snowy_tabs_ajax_content_loader( ui.newPanel, 1, ui.oldPanel );
683						}
684					} );
685					// AJAX loader for the pages in the tabs
686					$self.on( 'click', '.nav-links a', function(e) {
687						var $self = jQuery( this );
688						var panel = $self.parents( '.snowy_tabs_content' );
689						var page  = 1;
690						var href  = $self.attr( 'href' );
691						var pos   = -1;
692						if ( ( pos = href.lastIndexOf( '/page/' ) ) != -1 ) {
693							page = Number( href.substr( pos + 6 ).replace( "/", "" ) );
694							if ( ! isNaN( page )) {
695								page = Math.max( 1, page );
696							}
697						}
698						snowy_tabs_ajax_content_loader( panel, page );
699						e.preventDefault();
700						return false;
701					} );
702				}
703			} );
704		}
705	}
706
707
708	// Pagination and AJAX loaders
709	//==============================================
710
711	// Load the tab's content
712	function snowy_tabs_ajax_content_loader(panel, page, oldPanel) {
713		if (panel.html().replace( /\s/g, '' ) === '') {
714			var height = oldPanel === undefined ? panel.height() : oldPanel.height();
715			if (isNaN( height ) || height < 100) {
716				height = 100;
717			}
718			panel.html( '<div class="snowy_tab_holder" style="min-height:' + height + 'px;"></div>' );
719		} else {
720			panel.find( '> *' ).addClass( 'snowy_tab_content_remove' );
721		}
722		panel.data( 'need-content', false ).addClass( 'snowy_loading' );
723		jQuery.post(
724			SNOWY_STORAGE['ajax_url'], {
725				nonce: SNOWY_STORAGE['ajax_nonce'],
726				action: 'snowy_ajax_get_posts',
727				blog_template: panel.data( 'blog-template' ),
728				blog_style: panel.data( 'blog-style' ),
729				posts_per_page: panel.data( 'posts-per-page' ),
730				cat: panel.data( 'cat' ),
731				parent_cat: panel.data( 'parent-cat' ),
732				post_type: panel.data( 'post-type' ),
733				taxonomy: panel.data( 'taxonomy' ),
734				page: page
735			}
736		).done(	function( response ) {
737			panel.removeClass( 'snowy_loading' );
738			var rez = {};
739			try {
740				rez = JSON.parse( response );
741			} catch (e) {
742				rez = { error: SNOWY_STORAGE['msg_ajax_error'] };
743				console.log( response );
744			}
745			if (rez.error !== '') {
746				panel.html( '<div class="snowy_error">' + rez.error + '</div>' );
747			} else {
748				// Get inline styles and add to the page styles
749				if ( rez.css !== '' ) {
750					snowy_import_inline_styles( '<style id="snowy-inline-styles-inline-css">' + rez.css + '</style>' );
751				}
752				// Append posts
753				panel
754					.prepend( rez.data )
755					.fadeIn(
756						function() {
757//							snowy_document_animate_to('#content_skip_link_anchor');
758							$document.trigger( 'action.init_hidden_elements', [panel] );
759							$window.trigger( 'scroll' );
760							// Remove old content
761							setTimeout( function() {
762								panel
763									.find( '.snowy_tab_holder,.snowy_tab_content_remove' ).remove();
764								$window.trigger( 'scroll' );
765							}, 300 );
766						}
767					);
768				$document.trigger('action.after_add_content', [panel]);
769			}
770			$document.trigger( 'action.got_ajax_response', {
771				action: 'snowy_ajax_get_posts',
772				result: rez,
773				panel: panel
774			} );
775		} );
776	} // snowy_tabs_ajax_content_loader
777
778
779	// Load more
780	function snowy_init_load_more( cont ) {
781		cont.find( '.nav-load-more:not(.inited)' )
782			.addClass( 'inited' )
783			.on( 'click', function(e) {
784				var more = jQuery( this );
785				if ( more.data( 'load_more_link_busy' ) ) {
786					return false;
787				}
788				var page     = Number( more.data( 'page' ) );
789				var max_page = Number( more.data( 'max-page' ) );
790				if ( page >= max_page ) {
791					more.parent().addClass( 'all_items_loaded' ).hide();
792					return false;
793				}
794				more.data( 'load_more_link_busy', true )
795					.parent().addClass( 'loading' );
796
797				var panel = more.parents( '.snowy_tabs_content' );
798
799				// Load simple page content
800				if (panel.length === 0) {
801					jQuery.get(
802						location.href, {
803							paged: page + 1
804						}
805					).done(
806						function(response) {
807							// Get inline styles and add to the page styles
808							snowy_import_inline_styles( response );
809							// Get tags 'link' from response and add its to the 'head'
810							snowy_import_tags_link( response );
811							// Get new posts and append to the .posts_container
812							var $response = jQuery( response );
813							var $response_posts_container = $response.find('.content .posts_container');
814							if ( $response_posts_container.length === 0 ) {
815								$response_posts_container = $response.find('.posts_container');
816							}
817							if ( $response_posts_container.length > 0 ) {
818								snowy_loadmore_add_items(
819									$content.find( '.posts_container' ).eq( 0 ),
820									$response_posts_container.find(
821										'> .masonry_item,'
822										+ '> div[class*="column-"],'
823										+ '> article'
824									)
825								);
826							}
827							$document.trigger( 'action.got_ajax_response', {
828								action: 'load_more_next_page',
829								result: response
830							});
831						}
832					);
833
834					// Load tab's panel content
835				} else {
836					jQuery.post(
837						SNOWY_STORAGE['ajax_url'], {
838							nonce: SNOWY_STORAGE['ajax_nonce'],
839							action: 'snowy_ajax_get_posts',
840							blog_template: panel.data( 'blog-template' ),
841							blog_style: panel.data( 'blog-style' ),
842							posts_per_page: panel.data( 'posts-per-page' ),
843							cat: panel.data( 'cat' ),
844							parent_cat: panel.data( 'parent-cat' ),
845							post_type: panel.data( 'post-type' ),
846							taxonomy: panel.data( 'taxonomy' ),
847							page: page + 1
848						}
849					).done(
850						function(response) {
851							var rez = {};
852							try {
853								rez = JSON.parse( response );
854							} catch (e) {
855								rez = { error: SNOWY_STORAGE['msg_ajax_error'] };
856								console.log( response );
857							}
858							if (rez.error !== '') {
859								panel.html( '<div class="snowy_error">' + rez.error + '</div>' );
860							} else {
861								// Get inline styles and add to the page styles
862								if ( rez.css !== '' ) {
863									snowy_import_inline_styles( '<style id="snowy-inline-styles-inline-css">' + rez.css + '</style>' );
864								}
865								// Get new posts and append to the .posts_container
866								snowy_loadmore_add_items(
867									panel.find( '.posts_container' ),
868									jQuery( rez.data ).find(
869										'> .masonry_item,'
870										+ '> div[class*="column-"],'
871										+ '> article'
872									)
873								);
874							}
875							$document.trigger( 'action.got_ajax_response', {
876								action: 'snowy_ajax_get_posts',
877								result: rez,
878								panel: panel
879							});
880						}
881					);
882				}
883
884				// Append items to the container
885				function snowy_loadmore_add_items(container, items) {
886					if (container.length > 0 && items.length > 0) {
887						items.addClass( 'just_loaded_items' );
888						container.append( items );
889						$document.trigger('action.after_add_content', [container]);
890						var just_loaded_items = container.find( '.just_loaded_items' );
891						if ( container.hasClass( 'masonry_wrap' ) ) {
892							just_loaded_items.addClass( 'hidden' );
893							snowy_when_images_loaded(
894								just_loaded_items, function() {
895									just_loaded_items.removeClass( 'hidden' );
896									container.masonry( 'appended', items ).masonry();
897									// Remove TOC if exists (rebuild on init_hidden_elements)
898									jQuery( '#toc_menu' ).remove();
899									// Trigger actions to init new elements
900									SNOWY_STORAGE['init_all_mediaelements'] = true;
901									$document.trigger( 'action.init_hidden_elements', [container.parent()] );
902								}
903							);
904						} else {
905							just_loaded_items.removeClass( 'just_loaded_items hidden' );
906							// Remove TOC if exists (rebuild on init_hidden_elements)
907							jQuery( '#toc_menu' ).remove();
908							// Trigger actions to init new elements
909							SNOWY_STORAGE['init_all_mediaelements'] = true;
910							$document.trigger( 'action.init_hidden_elements', [container.parent()] );
911						}
912						more.data( 'page', page + 1 ).parent().removeClass( 'loading' );
913					}
914					if ( page + 1 >= max_page ) {
915						more.parent().addClass( 'all_items_loaded' ).hide();
916					}
917					more.data( 'load_more_link_busy', false );
918					// Fire 'window.resize'
919					$window.trigger( 'resize' );
920					// Fire 'window.scroll'
921					$window.trigger( 'scroll' );
922				}
923
924				e.preventDefault();
925				return false;
926			}
927		);
928	}
929
930
931	// Open single post right in the blog or in the shortcode "Blogger"
932	function snowy_init_load_single_post( cont ) {
933		cont.find( '.posts_container:not(.inited_open_full_post),.sc_blogger_content.sc_item_posts_container:not(.inited_open_full_post)' )
934			.addClass( 'inited_open_full_post' )
935			.on( 'click', 'a', function(e) {
936				var link = jQuery(this),
937					link_url = link.attr( 'href' ),
938					post = link.parents( '.post_item,.sc_blogger_item' ).eq(0),
939					post_url = post.find( '.post_title > a,.entry-title > a' ).attr( 'href' ),
940					posts_container = post.parents('.posts_container,.sc_item_posts_container').eq(0);
941				if ( link_url && post_url && link_url == post_url
942					&& ( posts_container.hasClass('open_full_post') || SNOWY_STORAGE['open_full_post'] )
943					&& ! posts_container.hasClass('no_open_full_post')
944					&& ! posts_container.hasClass('columns_wrap')
945					&& ! posts_container.hasClass('masonry_wrap')
946					&& posts_container.find('.sc_blogger_grid_wrap').length === 0
947					&& posts_container.find('.masonry_wrap').length === 0
948					&& posts_container.parents('.wp-block-columns').length === 0
949					&& ( posts_container.parents('.wpb_column').length === 0 || posts_container.parents('.wpb_column').eq(0).hasClass('vc_col-sm-12') )
950					&& ( posts_container.parents('.elementor-column').length === 0 || posts_container.parents('.elementor-column').eq(0).hasClass('elementor-col-100') )
951				) {
952					posts_container.find('.full_post_opened').removeClass('full_post_opened').show();
953					posts_container.find('.full_post_content').remove();
954					post.addClass('full_post_loading');
955					jQuery.get( snowy_add_to_url( post_url, { 'action': 'full_post_loading' } ) ).done( function( response ) {
956						if ( response ) {
957							var $response = jQuery( response );
958							var post_content = $response.find('.content');
959							if ( post_content.length > 0 ) {
960								// Get inline styles from response
961								var inline_styles = response.match( /<style[^>]*id="trx_addons-inline-styles-inline-css"[^>]*>([^<]*)<\/style>/ );
962								if ( inline_styles ) {
963									jQuery( '#trx_addons-inline-styles-inline-css' ).append( inline_styles[1] );
964								}
965								// Get tags 'link' from response and add its to the 'head'
966								snowy_import_tags_link( response );
967								// Animate to posts_container
968								var cs = post.offset().top - ( post.parents('.posts_container').length > 0 ? 100 : 200 );
969								snowy_document_animate_to( cs );
970								// Insert new content
971								post.after( 
972										'<div class="full_post_content">'
973											+ '<button class="full_post_close" data-post-url="' + post_url + '"></button>'
974											+ post_content.html()
975										+ '</div>'
976									)
977									.removeClass('full_post_loading')
978									.addClass('full_post_opened')
979									.hide()	// instead .slideUp('fast')
980									.next().slideDown( 'slow', function() {
981										// Trigger actions to init new elements after posts_container is shown
982										SNOWY_STORAGE['init_all_mediaelements'] = true;
983										$document.trigger( 'action.init_hidden_elements', [posts_container] );
984										$window.trigger( 'resize' );
985									} );
986								snowy_full_post_read_change_state();
987								// Close full post content on click
988								post.next().find('.full_post_close')
989									.on( 'click', function(e) {
990										var content = jQuery(this).parent(),
991											cs = content.offset().top - (content.parents('.posts_container').length > 0 ? 100 : 200),
992											post = content.prev();
993										content.remove();
994										snowy_full_post_read_change_state();
995										post
996											.removeClass('full_post_opened')
997											.slideDown();
998										snowy_document_animate_to( cs, 0 );
999										e.preventDefault();
1000										return false;
1001									} );
1002								// Remove TOC if exists (rebuild on init_hidden_elements)
1003								jQuery( '#toc_menu' ).remove();
1004							}
1005							$document.trigger( 'action.got_ajax_response', {
1006								action: 'full_post_loading',
1007								result: response
1008							} );
1009						}
1010					} );
1011					e.preventDefault();
1012					return false;
1013				}
1014			} );
1015	}
1016
1017
1018	// Infinite scroll in the blog archive page
1019	function snowy_infinite_scroll_in_blog() {
1020		if ( ! $nav_link_infinite || $nav_link_infinite.length === 0 || $nav_link_infinite.hasClass( 'all_items_loaded' ) ) {
1021			return;
1022		}
1023		var container = $content.find( '> .posts_container,> .blog_archive > .posts_container,> .snowy_tabs > .snowy_tabs_content:visible > .posts_container' ).eq( 0 );
1024		if ( container.length == 1 && container.offset().top + container.height() < snowy_window_scroll_top() + snowy_window_height() * 1.5 ) {
1025			$nav_link_infinite.find( 'a' ).trigger( 'click' );
1026		}
1027	}
1028
1029
1030	// Infinite scroll in the single post
1031	function snowy_infinite_scroll_in_single() {
1032		if ( $single_post_scrollers.length === 0 ) {
1033			return;
1034		}
1035
1036		var container      = SNOWY_STORAGE['which_block_load'] == 'article'
1037								? $content.eq( 0 )
1038								: $page_content_wrap.eq( 0 ),
1039			cur_page_link  = $single_post_scrollers.length ? $single_post_scrollers.eq(0).data( 'cur-post-link' ) : location.href,
1040			cur_page_title = $single_post_scrollers.length ? $single_post_scrollers.eq(0).data( 'cur-post-title' ) : ( $cur_page_title_tag.length ? $cur_page_title_tag.text() : '' );
1041
1042		$single_post_scrollers.each( function() {
1043			var inf  = jQuery(this),
1044				link = inf.data('post-link'),
1045				off  = inf.offset().top,
1046				st   = snowy_window_scroll_top(),
1047				wh   = snowy_window_height();
1048			
1049			// Change location url
1050			if ( inf.hasClass('nav-links-single-scroll-loaded') ) {
1051				if (link && off < st + wh / 2) {
1052					cur_page_link  = link;
1053					cur_page_title = inf.data('post-title');
1054				}
1055
1056			// Load next post
1057			} else if ( ! inf.hasClass('snowy_loading') && link && off < st + wh * 2) {
1058				snowy_add_to_read_list( container.find( '.previous_post_content:last-child > article[data-post-id]').data('post-id'));
1059				inf.addClass('snowy_loading');
1060				jQuery.get( snowy_add_to_url( link, { 'action': 'prev_post_loading' } ) ).done(
1061					function( response ) {
1062						// Get inline styles and add to the page styles
1063						snowy_import_inline_styles( response );
1064						// Get tags 'link' from response and add its to the 'head'
1065						snowy_import_tags_link( response );
1066						// Get article and add it to the page
1067						var $response = jQuery( response ),
1068							$response_page_content_wrap = $response.find( '.page_content_wrap' ),
1069							$response_content = $response.find( '.content' ),
1070							$response_sidebar = $response.find( '.sidebar' ),
1071							$response_post_content = SNOWY_STORAGE['which_block_load'] == 'article'
1072														? $response_content
1073														: $response_page_content_wrap;
1074						if ( $response_post_content.length > 0 ) {
1075							var html = $response_post_content.html(),
1076								response_body_classes = SNOWY_STORAGE['which_block_load'] == 'article'
1077														? null
1078														: response.match(/<body[^>]*class="([^"]*)"/);
1079							if ( SNOWY_STORAGE['which_block_load'] == 'wrapper' ) {
1080								if ( $response_sidebar.length === 0
1081									&& ! response_body_classes
1082									&& ! $body.hasClass( 'expand_content' )
1083									&& ! $body.hasClass( 'narrow_content' )
1084								) {
1085									$response_post_content.find( '.content' ).width( '100%' );
1086									html = $response_post_content.html();
1087								} else if ( $response_sidebar.length > 0 && $body.hasClass( 'narrow_content' ) ) {
1088									$response_post_content.find( '.post_item_single.post_type_post' ).width( '100%' );
1089									html = $response_post_content.html();
1090								}
1091							}
1092							container.append(
1093								'<div class="previous_post_content'
1094												+ ( response_body_classes
1095													? ' ' + response_body_classes[1]
1096													: '' )
1097												+ ( $response_page_content_wrap.attr( 'data-single-style' ) !== undefined
1098														? ' single_style_' + $response_page_content_wrap.attr( 'data-single-style' )
1099														: ''
1100													)
1101								+ '">'
1102									+ html
1103								+ '</div>'
1104							);
1105							inf.removeClass('snowy_loading').addClass( 'nav-links-single-scroll-loaded' );
1106							// Remove TOC if exists (rebuild on init_hidden_elements)
1107							jQuery( '#toc_menu' ).remove();
1108							// Trigger actions to init new elements
1109							SNOWY_STORAGE['init_all_mediaelements'] = true;
1110							$document
1111								.trigger( 'action.new_post_added', [container] )
1112								.trigger( 'action.init_hidden_elements', [container] );
1113							$window.trigger( 'resize' );
1114						}
1115						$document.trigger( 'action.got_ajax_response', {
1116							action: 'prev_post_loading',
1117							result: response
1118						});
1119					}
1120				);
1121			}						
1122		} );
1123		if ( cur_page_link != location.href ) {
1124			snowy_document_set_location( cur_page_link );
1125			jQuery( cur_page_title_selector ).html( cur_page_title );
1126		}
1127	}
1128
1129
1130	// Menu navigation
1131	//==============================================
1132
1133	// Init menus after the page is loaded
1134	function snowy_init_menus( cont ) {
1135
1136		// Stretch sidemenu after the logo is loaded
1137		if ( $body.hasClass( 'menu_side_present' ) && $menu_side_logo.length && ! $menu_side_logo.hasClass( 'inited_stretch' ) ) {
1138			$menu_side_logo.addClass( 'inited_stretch' );
1139			if ( ! snowy_is_images_loaded( $menu_side_logo ) ) {
1140				snowy_when_images_loaded( $menu_side_logo, function() {
1141					snowy_stretch_sidemenu();
1142				} );
1143			}
1144		}
1145
1146		var $menus = cont.find( '.sc_layouts_menu:not(.inited_kbd)' ).addClass( 'inited_kbd' );
1147		// Keyboard navigation in the menus
1148		$menus
1149			.on( 'keydown', 'li > a', function(e) {
1150				var handled = false,
1151					link = jQuery( this ),
1152					li = link.parent(),
1153					ul = li.parent(),
1154					li_parent = ul.parent().prop( 'tagName' ) == 'LI' ? ul.parent() : false,
1155					item = false;
1156				if ( 32 == e.which ) {								// Space
1157					link.trigger( 'click' );
1158					handled = true;
1159				} else if ( 27 == e.which ) {						// Esc
1160					if ( li_parent ) {
1161						item = li_parent.find( '> a' );
1162						if ( item.length > 0 ) {
1163							item.get(0).focus();
1164						}
1165					}
1166					handled = true;
1167				} else if ( 37 == e.which ) {						// Left
1168					if ( li_parent ) {
1169						item = li_parent.find( '> a' );
1170						if ( item.length > 0 ) {
1171							item.get(0).focus();
1172						}
1173					} else if ( li.index() > 0 ) {
1174						item = li.prev().find( '> a' );
1175						if ( item.length > 0 ) {
1176							item.eq(0).focus();
1177						}
1178					}
1179					handled = true;
1180				} else if ( 38 == e.which ) {						// Top
1181					if ( li.index() > 0 ) {
1182						item = li.prev().find( '> a' );
1183						if ( item.length > 0 ) {
1184							item.get(0).focus();
1185						}
1186					} else if ( li_parent ) {
1187						item = li_parent.find( '> a' );
1188						if ( item.length > 0 ) {
1189							item.get(0).focus();
1190						}
1191					}
1192					handled = true;
1193				} else if ( 39 == e.which ) {						// Right
1194					if ( li_parent ) {
1195						if ( li.find( '> ul' ).length == 1 ) {
1196							item = li.find( '> ul > li:first-child a' );
1197							if ( item.length > 0 ) {
1198								item.get(0).focus();
1199							}
1200						}
1201					} else if ( li.next().prop( 'tagName' ) == 'LI' ) {
1202						item = li.next().find( '> a' );
1203						if ( item.length > 0 ) {
1204							item.get(0).focus();
1205						}
1206					}
1207					handled = true;
1208				} else if ( 40 == e.which ) {						// Bottom
1209					if ( li_parent || li.find( '> ul' ).length === 0 ) {
1210						if ( li.next().prop( 'tagName' ) == 'LI' ) {
1211							item = li.next().find( '> a' );
1212							if ( item.length > 0 ) {
1213								item.get(0).focus();
1214							}
1215						}
1216					} else if ( li.find( '> ul' ).length == 1 ) {
1217						item = li.find( '> ul > li:first-child a' );
1218						if ( item.length > 0 ) {
1219							item.get(0).focus();
1220						}
1221					}
1222					handled = true;
1223				}
1224				if ( handled ) {
1225					if ( ! $body.hasClass( 'show_outline' ) ) {
1226						$body.addClass( 'show_outline' );
1227					}
1228					e.preventDefault();
1229					return false;
1230				}
1231				return true;
1232			} );
1233
1234		// Add images to the menu items with classes image-xxx
1235		$menus.find( 'li[class*="image-"]' ).each(
1236			function() {
1237				var $self   = jQuery( this );
1238				var classes = $self.attr( 'class' ).split( ' ' );
1239				var icon    = '';
1240				for (var i = 0; i < classes.length; i++) {
1241					if (classes[i].indexOf( 'image-' ) >= 0) {
1242						icon = classes[i].replace( 'image-', '' );
1243						break;
1244					}
1245				}
1246				if (icon) {
1247					$self.find( '>a' ).css( 'background-image', 'url(' + SNOWY_STORAGE['theme_url'] + 'trx_addons/css/icons.png/' + icon + '.png' );
1248				}
1249			}
1250		);
1251
1252		// Open/Close side menu
1253		cont.find( '.menu_side_button:not(.inited)' )
1254			.addClass( 'inited' )
1255			.on( 'click', function( e ) {
1256				jQuery( this ).parent().toggleClass( 'opened' );
1257				e.preventDefault();
1258				return false;
1259			} );
1260
1261		// Add arrows to the mobile menu 
1262		// and close the mobile menu on a link with url is clicked
1263		// (to prevent display a mobile menu after 'Back' pressed)
1264		cont.find( '.menu_mobile:not(.inited_arrows),.sc_layouts_menu_dir_vertical:not(.inited_arrows)' )
1265			.addClass( 'inited_arrows' )
1266			.find( '.menu-item-has-children > a' )
1267				.append( '<span class="open_child_menu"></span>' ).end()
1268			.find ( 'a:not([href="#"])' )
1269				.on( 'click', function(e) {
1270					if ( ! jQuery( e.target ).hasClass( 'open_child_menu' ) ) {
1271						snowy_mobile_menu_close();
1272					}
1273				} );
1274
1275		// Open/Close mobile menu
1276		function snowy_mobile_menu_open() {
1277			var $menu = cont.find( '.menu_mobile' );
1278			$menu
1279				.addClass( 'opened' )
1280				.prev( '.menu_mobile_overlay' ).fadeIn();
1281			$body.addClass( 'menu_mobile_opened' );
1282			$document
1283				.trigger( 'action.stop_wheel_handlers' )
1284				.trigger( 'action.mobile_menu_open', [$menu] );
1285		}
1286		function snowy_mobile_menu_close() {
1287			var $menu = cont.find( '.menu_mobile' );
1288			$document.trigger( 'action.mobile_menu_close', [$menu] );
1289			setTimeout( function() {
1290				$menu
1291					.removeClass( 'opened' )
1292					.prev( '.menu_mobile_overlay' ).fadeOut();
1293				$body.removeClass( 'menu_mobile_opened' );
1294				$document.trigger( 'action.start_wheel_handlers' );
1295			}, snowy_apply_filters( 'snowy_filter_mobile_menu_close_timeout', 0, $menu ) );
1296		}
1297
1298		cont.find( '.sc_layouts_menu_mobile_button > a:not(.inited_click),.menu_mobile_button:not(.inited_click),.menu_mobile_description:not(.inited_click)' )
1299			.addClass( 'inited_click' )
1300			.on( 'click', function( e ) {
1301				var $self = jQuery( this );
1302				if ( $self.parent().hasClass( 'sc_layouts_menu_mobile_button_burger' )
1303					&& $self.next().hasClass( 'sc_layouts_menu_popup' )
1304				) {
1305					return;   // Not use 'return false' - it break event bubble and popup is not open
1306				}
1307				snowy_mobile_menu_open();
1308				e.preventDefault();
1309				return false;
1310			}
1311		);
1312
1313		cont.find( '.menu_mobile_overlay:not(.inited_click)' )
1314			.addClass( 'inited_click' )
1315			.on( 'click', function(e){
1316				snowy_mobile_menu_close();
1317				e.preventDefault();
1318				return false;
1319			} );
1320		cont.find( '.menu_mobile_close:not(.inited_click)' )
1321			.addClass( 'inited_click' )
1322			.on( 'click', function(e){
1323				snowy_mobile_menu_close();
1324				e.preventDefault();
1325				return false;
1326			} )
1327			.on( 'keyup', function(e) {
1328				if (e.keyCode == 13) {
1329					if (jQuery( '.menu_mobile.opened' ).length == 1) {
1330						snowy_mobile_menu_close();
1331						e.preventDefault();
1332						return false;
1333					}
1334				}
1335			} )
1336			.on( 'focus', function() {
1337				if ( ! $body.hasClass( 'menu_mobile_opened' ) ) {
1338					jQuery( '#content_skip_link_anchor' ).focus();
1339				}
1340			} );
1341
1342		// Open/Close mobile submenu
1343		cont.find( '.menu_mobile:not(.inited_click),.sc_layouts_menu_dir_vertical:not([class*="sc_layouts_submenu_"]):not(.inited_click),.sc_layouts_menu.sc_layouts_submenu_dropdown:not(.inited_click)' )
1344			.addClass( 'inited_click' )
1345			.on( 'click', 'li a .open_child_menu,li a', function(e) {
1346				var $self = jQuery( this );
1347				var $a    = $self.hasClass( 'open_child_menu' ) ? $self.parent() : $self;
1348				if ($a.parent().hasClass( 'menu-item-has-children' )) {
1349					if ($a.attr( 'href' ) == '#' || $self.hasClass( 'open_child_menu' )) {
1350						if ($a.siblings( 'ul:visible' ).length > 0) {
1351							$a.siblings( 'ul' ).slideUp().parent().removeClass( 'opened' );
1352						} else {
1353							$self.parents( 'li' ).eq(0).siblings( 'li' ).find( 'ul.sub-menu:visible,ul.sc_layouts_submenu:visible' ).slideUp().parent().removeClass( 'opened' );
1354							$a.siblings( 'ul' ).slideDown(
1355								function() {
1356									var $self = jQuery( this );
1357									// Init layouts
1358									if ( ! $self.hasClass( 'layouts_inited' ) && $self.parents( '.menu_mobile' ).length > 0) {
1359										$self.addClass( 'layouts_inited' );
1360										$document.trigger( 'action.init_hidden_elements', [$self] );
1361									}
1362								}
1363							).parent().addClass( 'opened' );
1364						}
1365					}
1366				}
1367				if ( ! $self.hasClass( 'open_child_menu' ) && $self.parents( '.menu_mobile' ).length > 0 && snowy_is_local_link( $a.attr( 'href' ) )) {
1368					jQuery( '.menu_mobile_close' ).trigger( 'click' );
1369				}
1370				if ( $self.hasClass( 'open_child_menu' ) || $a.attr( 'href' ) == '#' ) {
1371					e.preventDefault();
1372					return false;
1373				}
1374			} )
1375			.on( 'keyup', 'li a', function(e) {
1376				if ( e.keyCode == 9 ) {
1377					jQuery(this).find( '.open_child_menu' ).trigger( 'click' );
1378				}
1379			} );
1380
1381		if ( ! SNOWY_STORAGE['trx_addons_exist'] || jQuery( '.top_panel.top_panel_default .sc_layouts_menu_default' ).length > 0) {
1382			// Init superfish menus
1383			snowy_init_sfmenu( '.sc_layouts_menu:not(.inited):not(.sc_layouts_submenu_dropdown) > ul:not(.inited)' );
1384			// Show menu
1385			jQuery( '.sc_layouts_menu:not(.inited)' ).each(
1386				function() {
1387					var $self = jQuery( this );
1388					if ( $self.find( '>ul.inited' ).length == 1 ) {
1389						$self.addClass( 'inited' );
1390					}
1391				}
1392			);
1393			// Generate 'scroll' event after the menu is showed
1394			$window.trigger( 'scroll' );
1395		}
1396	}
1397
1398
1399	// Init Superfish menu
1400	function snowy_init_sfmenu(selector) {
1401		jQuery( selector ).show().each(
1402			function() {
1403				var $self = jQuery( this );
1404				// Do not init the mobile menu - only add class 'inited'
1405				if ($self.addClass( 'inited' ).parents( '.menu_mobile' ).length > 0) {
1406					return;
1407				}
1408				var animation_in = $self.parent().data( 'animation_in' );
1409				if (animation_in == undefined) {
1410					animation_in = "none";
1411				}
1412				var animation_out = $self.parent().data( 'animation_out' );
1413				if (animation_out == undefined) {
1414					animation_out = "none";
1415				}
1416				$self.superfish(
1417					{
1418						delay: 300,
1419						animation: {
1420							opacity: 'show'
1421						},
1422						animationOut: {
1423							opacity: 'hide'
1424						},
1425						speed: 		animation_in != 'none' ? 500 : 200,
1426						speedOut:	animation_out != 'none' ? 300 : 200,
1427						autoArrows: false,
1428						dropShadows: false,
1429						onBeforeShow: function(ul) {
1430							var $self = jQuery( this ),
1431								$ul   = $self.parents( "ul" );
1432							var par_offset = 0,
1433								par_width = 0,
1434								ul_width = 0,
1435								ul_height = 0;
1436							// Detect horizontal position (left | right)
1437							if ( $ul.length > 1 ) {
1438								var w      = $page_wrap.width();
1439								par_offset = $ul.eq(0).offset().left;
1440								par_width  = $ul.eq(0).outerWidth();
1441								ul_width   = $self.outerWidth();
1442								if (par_offset + par_width + ul_width > w - 20 && par_offset - ul_width > 0) {
1443									$self.addClass( 'submenu_left' );
1444								} else {
1445									$self.removeClass( 'submenu_left' );
1446								}
1447							}
1448							// Shift vertical if menu going out the window
1449							if ( $self.parents( '.top_panel' ).length > 0 ) {
1450								ul_height      = $self.outerHeight();
1451								par_offset     = 0;
1452								var w_height   = snowy_window_height(),
1453									row        = $self.parents( '.sc_layouts_row' ).eq(0),
1454									row_offset = 0,
1455									row_height = 0,
1456									par        = $self.parent();
1457								while (row.length > 0) {
1458									row_offset += row.outerHeight();
1459									if (row.hasClass( 'sc_layouts_row_fixed_on' )) {
1460										break;
1461									}
1462									row = row.prev();
1463								}
1464								while (par.length > 0) {
1465									par_offset += par.position().top + par.parent().position().top;
1466									row_height  = par.outerHeight();
1467									if (par.position().top === 0) {
1468										break;
1469									}
1470									par = par.parents( 'li' ).eq(0);
1471								}
1472								if (row_offset + par_offset + ul_height > w_height) {
1473									if (par_offset > ul_height) {
1474										$self.css( {
1475											'top': 'auto',
1476											'bottom': '-1.4em'
1477										} );
1478									} else {
1479										$self.css( {
1480											'top': '-' + (par_offset - row_height - 2) + 'px',
1481											'bottom': 'auto'
1482										} );
1483									}
1484								}
1485							}
1486							// Animation in
1487							if (animation_in != 'none') {
1488								$self.removeClass( 'animated faster ' + animation_out );
1489								$self.addClass( 'animated fast ' + animation_in );
1490							}
1491						},
1492						onBeforeHide: function(ul) {
1493							if (animation_out != 'none') {
1494								var $self = jQuery( this );
1495								$self.removeClass( 'animated fast ' + animation_in );
1496								$self.addClass( 'animated faster ' + animation_out );
1497							}
1498						},
1499						onShow: function(ul) {
1500							var $self = jQuery( this );
1501							// Init layouts
1502							if ( ! $self.hasClass( 'layouts_inited' )) {
1503								$self.addClass( 'layouts_inited' );
1504								$document.trigger( 'action.init_hidden_elements', [$self] );
1505							}
1506						}
1507					}
1508				);
1509			}
1510		);
1511	}  // snowy_init_sfmenu
1512
1513
1514	// Add TOC in the side menu
1515	// Make this function global because it used in the elementor.js
1516	function snowy_add_toc_to_sidemenu() {
1517		if ( jQuery( '.menu_side_inner' ).length > 0 && jQuery( '#toc_menu' ).length > 0 ) {
1518			jQuery( '#toc_menu' ).appendTo( '.menu_side_inner' );
1519			snowy_stretch_sidemenu();
1520		}
1521	}
1522
1523
1524	// Sidebar open/close
1525	function snowy_init_sidebar_control( cont ) {
1526		cont.find( '.sidebar_control:not(.inited)' )
1527			.addClass( 'inited' )
1528			.on( 'click', function( e ) {
1529				var $self = jQuery( this ),
1530					$parent = $self.parent();
1531				$parent.toggleClass( 'opened' );
1532				if ( $body.hasClass( 'sidebar_small_screen_above' ) ) {
1533					var $next = $self.next();
1534					$next.slideToggle();
1535					if ( $parent.hasClass( 'opened' ) ) {
1536						setTimeout( function() {
1537							$document.trigger( 'action.init_hidden_elements', [$next] );
1538						}, 310 );
1539					}
1540				}
1541				e.preventDefault();
1542				return false;
1543			} );
1544	}
1545
1546
1547	// Masonry posts
1548	function snowy_init_masonry( cont ) {
1549		cont.find( snowy_apply_filters( 'snowy_filter_masonry_wrap', '.masonry_wrap' ) ).each( function() {
1550			var masonry_wrap = jQuery( this );
1551			if ( masonry_wrap.parents( 'div:hidden,article:hidden' ).length > 0) return;
1552			if ( ! masonry_wrap.hasClass( 'inited' ) ) {
1553				masonry_wrap.addClass( 'inited' );
1554				snowy_when_images_loaded( masonry_wrap, function() {
1555					setTimeout( function() {
1556									masonry_wrap.masonry( {
1557										itemSelector: snowy_apply_filters( 'snowy_filter_masonry_item', '.masonry_item' ),
1558										columnWidth: snowy_apply_filters( 'snowy_filter_masonry_item', '.masonry_item' ),
1559										percentPosition: true
1560									} );
1561									$window.trigger('resize');
1562									$window.trigger('scroll');
1563								}, snowy_apply_filters( 'snowy_filter_masonry_init', 10 ) );
1564				});
1565			} else {
1566				setTimeout( function() {
1567					masonry_wrap.masonry();   // Relayout after activate tab
1568				}, snowy_apply_filters( 'snowy_filter_masonry_reinit', 510 ) );
1569			}
1570		} );
1571	}
1572
1573	// Show/Hide Comments
1574	function snowy_init_comments_button( cont ) {
1575		cont.find( '.show_comments_button:not(.inited)' )
1576			.addClass( 'inited' )
1577			.on( 'click', function(e) {
1578				var bt = jQuery(this);
1579				if ( bt.attr( 'href' ) == '#' ) {
1580					bt.toggleClass( 'opened' ).text( bt.data( bt.hasClass( 'opened' ) ? 'hide' : 'show' ) );
1581					var $comments_wrap = bt.parent().next();	//jQuery( '.comments_wrap' )
1582					$comments_wrap.slideToggle( function() {
1583						$comments_wrap.toggleClass( 'opened' );
1584						$window.trigger( 'scroll' );
1585					});
1586					e.preventDefault();
1587					return false;
1588				}
1589			} );
1590	}
1591
1592
1593	// Show comments block when link '#comments' or '#respond' is clicked
1594	function snowy_init_comments_links( cont ) {
1595		cont.find( 'a[href$="#comments"]:not(.inited),a[href$="#respond"]:not(.inited)' )
1596			.addClass( 'inited' )
1597			.on( 'click', function(e) {
1598				var $self = jQuery(this);
1599				if ( snowy_is_local_link( $self.attr( 'href') ) ) {
1600					var $prev_post_content = $self.parents( '.previous_post_content' ),
1601						$comments_wrap = $prev_post_content.length
1602											? $prev_post_content.find( '.comments_wrap' ).eq(0)
1603											: jQuery( '.comments_wrap' ).eq(0),
1604						$show_comments_button = $comments_wrap.prev().find('.show_comments_button ');
1605					if ( $comments_wrap.length ) {
1606						if ( $comments_wrap.css( 'display' ) == 'none' ) {
1607							if ($show_comments_button.length ) {
1608								$show_comments_button.trigger( 'click' );
1609							}
1610						}
1611						if ($show_comments_button.length ) {
1612							snowy_document_animate_to( $show_comments_button.offset().top );
1613						}
1614					}
1615				}
1616			} );
1617	}
1618
1619
1620	// Checkbox with "I agree..."
1621	function snowy_init_checkbox_i_agree( cont ) {
1622		var $i_agree = cont.find('input[type="checkbox"][name="i_agree_privacy_policy"]:not(.inited)'
1623							+ ',input[type="checkbox"][name="gdpr_terms"]:not(.inited)'
1624							+ ',input[type="checkbox"][name="wpgdprc"]:not(.inited)'
1625							+ ',input[type="checkbox"][name="AGREE_TO_TERMS"]:not(.inited)'
1626							+ ',input[type="checkbox"][name="acceptance"]:not(.inited)'
1627							);
1628		if ( $i_agree.length > 0 ) {
1629			if ( true ) {	// New way: On click Submit button - checkbox is checked
1630				$i_agree.each( function() {
1631					var chk = jQuery( this ),
1632						form = chk.parents('form');
1633					chk.addClass( 'inited' );
1634					form.find( 'button,input[type="submit"]' ).on( 'click', function(e) {
1635						if ( ! chk.get(0).checked ) {
1636							form.find('.trx_addons_message_box').remove();
1637							form.append(
1638								'<div class="trx_addons_message_box trx_addons_message_box_error">'
1639									+ SNOWY_STORAGE['msg_i_agree_error']
1640								+ '</div>'
1641							);
1642							var error_msg = form.find('.trx_addons_message_box');
1643							error_msg.fadeIn();
1644							setTimeout( function() {
1645								error_msg.fadeOut( function() {
1646									error_msg.remove();
1647								} );
1648							}, 3000 );
1649							e.preventDefault();
1650							return false;
1651						}
1652					} );
1653				} );
1654			} else {		// Old way: Disable Submit button while checkbox is not checked
1655				$i_agree
1656					.addClass('inited')
1657					.on('change', function(e) {
1658						var $self = jQuery(this),
1659							$bt   = $self.parents('form').find('button,input[type="submit"]');
1660						if ($self.get(0).checked) {
1661							$bt.removeAttr('disabled');
1662						} else {
1663							$bt.attr('disabled', 'disabled');
1664						}
1665					})
1666					.trigger('change');
1667			}
1668		}
1669	}
1670
1671
1672	// Init intersection observer
1673	//==============================================
1674	function snowy_intersection_observer_init() {
1675
1676		if ( typeof IntersectionObserver != 'undefined' ) {
1677			// Create observer
1678			if ( typeof SNOWY_STORAGE['intersection_observer'] == 'undefined' ) {
1679				SNOWY_STORAGE['intersection_observer'] = new IntersectionObserver( function(entries) {
1680						entries.forEach( function( entry ) {
1681							snowy_intersection_observer_in_out( jQuery(entry.target), entry.isIntersecting || entry.intersectionRatio > 0 ? 'in' : 'out', entry );
1682						} );
1683					},
1684					{
1685						root: null,			// avoiding 'root' or setting it to 'null' sets it to default value: viewport
1686						rootMargin: '1px',	// increase (if positive) or decrease (if negative) root area
1687											// 1px is used instead 0px to avoid a problem with appear sticky elements when window is scrolled down
1688						threshold: 0		// 0.0 - 1.0: 0.0 - fired when top of the object enter in the viewport
1689											//            0.5 - fired when half of the object enter in the viewport
1690											//            1.0 - fired when the whole object enter in the viewport
1691					}
1692				);
1693			}
1694		} else {
1695			// Emulate IntersectionObserver behaviour
1696			$window.on( 'scroll', function() {
1697				if ( typeof SNOWY_STORAGE['intersection_observer_items'] != 'undefined' ) {
1698					for ( var i in SNOWY_STORAGE['intersection_observer_items'] ) {
1699						if ( ! SNOWY_STORAGE['intersection_observer_items'][i] || SNOWY_STORAGE['intersection_observer_items'][i].length === 0 ) {
1700							continue;
1701						}
1702						var item = SNOWY_STORAGE['intersection_observer_items'][i],
1703							item_top = item.offset().top,
1704							item_height = item.height();
1705						snowy_intersection_observer_in_out( item, item_top + item_height > snowy_window_scroll_top() && item_top < snowy_window_scroll_top() + snowy_window_height() ? 'in' : 'out' );
1706					}
1707				}
1708			} );
1709		}
1710
1711		// Change state of the entry
1712		window.snowy_intersection_observer_in_out = function( item, state, entry ) {
1713			var callback = null;
1714			if ( state == 'in' ) {
1715				if ( ! item.hasClass( 'snowy_in_viewport' ) ) {
1716					item.addClass( 'snowy_in_viewport' );
1717					callback = item.data('trx-addons-intersection-callback');
1718					if ( callback ) {
1719						callback( item, true, entry );
1720					}
1721				}
1722			} else {
1723				if ( item.hasClass( 'snowy_in_viewport' ) ) {
1724					item.removeClass( 'snowy_in_viewport' );
1725					callback = item.data('trx-addons-intersection-callback');
1726					if ( callback ) {
1727						callback( item, false, entry );
1728					}
1729				}
1730			}
1731		};
1732
1733		// Add elements to the observer
1734		window.snowy_intersection_observer_add = function( items, callback ) {
1735			items.each( function() {
1736				var $self = jQuery( this ),
1737					id = $self.attr( 'id' );
1738				if ( ! $self.hasClass( 'snowy_intersection_inited' ) ) {
1739					if ( ! id ) {
1740						id = 'io-' + ( '' + Math.random() ).replace('.', '');
1741						$self.attr( 'id', id );
1742					}
1743					$self.addClass( 'snowy_intersection_inited' );
1744					if ( callback ) {
1745						$self.data( 'trx-addons-intersection-callback', callback );
1746					}
1747					if ( typeof SNOWY_STORAGE['intersection_observer_items'] == 'undefined' ) {
1748						SNOWY_STORAGE['intersection_observer_items'] = {};
1749					}
1750					SNOWY_STORAGE['intersection_observer_items'][id] = $self;
1751					if ( typeof SNOWY_STORAGE['intersection_observer'] !== 'undefined' ) {
1752						SNOWY_STORAGE['intersection_observer'].observe( $self.get(0) );
1753					}
1754				}
1755			} );
1756		};
1757
1758		// Remove elements from the observer
1759		window.snowy_intersection_observer_remove = function( items ) {
1760			items.each( function() {
1761				var $self = jQuery( this ),
1762					id = $self.attr( 'id' );
1763				if ( $self.hasClass( 'snowy_intersection_inited' ) ) {
1764					$self.removeClass( 'snowy_intersection_inited' );
1765					delete SNOWY_STORAGE['intersection_observer_items'][id];
1766					if ( typeof SNOWY_STORAGE['intersection_observer'] !== 'undefined' ) {
1767						SNOWY_STORAGE['intersection_observer'].unobserve( $self.get(0) );
1768					}
1769				}
1770			} );
1771		};
1772	}
1773
1774
1775
1776	// Scroll actions
1777	//==============================================
1778
1779	// Do actions when page scrolled
1780	function snowy_scroll_actions() {
1781
1782		// Call theme/plugins specific action (if exists)
1783		$document.trigger( 'action.scroll_snowy' );
1784
1785		// Fix/unfix sidebar
1786		snowy_fix_sidebar();
1787
1788		// Fix/unfix nav links
1789		snowy_fix_nav_links();
1790
1791		// Fix/unfix share links
1792		snowy_fix_share_links();
1793
1794		// Shift top and footer panels when header position is 'Under content'
1795		snowy_shift_under_panels();
1796
1797		// Show full post reading progress
1798		snowy_full_post_reading();
1799
1800		// Set flag about scroll actions are finished
1801		SNOWY_STORAGE['scroll_busy'] = false;
1802	}
1803
1804	// Add post_id to the readed list
1805	function snowy_add_to_read_list(post_id) {
1806		if ( post_id > 0 ) {
1807			var read_list = snowy_get_storage('snowy_post_read');
1808			if ( read_list && read_list.charAt(0) == '[' ) {
1809				read_list = JSON.parse(read_list);
1810			} else {
1811				read_list = [];
1812			}
1813			if ( read_list.indexOf(post_id) == -1 ) {
1814				read_list.push(post_id);
1815			}
1816			snowy_set_storage('snowy_post_read', JSON.stringify(read_list));
1817		}
1818	}
1819
1820	var fpr_bt, fpr_cont, fpr_cs, fpr_ch, fpr_pw;
1821	function snowy_full_post_read_change_state() {
1822		fpr_bt = jQuery('.full_post_close');
1823		if ( fpr_bt.length == 1 ) {
1824			fpr_cont = fpr_bt.parent();
1825			fpr_cs   = fpr_cont.offset().top;
1826			fpr_ch   = fpr_cont.height();
1827			fpr_pw   = fpr_bt.find('.full_post_progress');
1828		}
1829	}
1830
1831	// Show full post reading progress
1832	function snowy_full_post_reading() {
1833		if ( typeof fpr_bt == 'undefined' ) {
1834			snowy_full_post_read_change_state();
1835		}
1836		if ( fpr_bt.length == 1 ) {
1837			var ws = snowy_window_scroll_top(),
1838				wh = snowy_window_height();
1839			if ( ws > fpr_cs ) {
1840				if ( ! fpr_pw || fpr_pw.length === 0 ) {
1841					fpr_bt.append(
1842						'<span class="full_post_progress">'
1843							+ '<svg viewBox="0 0 50 50">'
1844								+ '<circle class="full_post_progress_bar" cx="25" cy="25" r="22"></circle>'
1845							+ '</svg>'
1846						+ '</span>'
1847					);
1848					fpr_pw = fpr_bt.find('.full_post_progress');
1849				}
1850				var bar = fpr_pw.find('.full_post_progress_bar'),
1851					bar_max = parseFloat( bar.css('stroke-dasharray') );
1852				if ( fpr_cs + fpr_ch > ws + wh ) {
1853					var now = fpr_cs + fpr_ch - ( ws + wh ),
1854						delta = bar.data('delta');
1855					if ( delta == undefined ) {
1856						delta = now;
1857						bar.data('delta', delta);
1858					}
1859					bar.css( 'stroke-dashoffset', Math.min( 1, now / delta ) * bar_max + 'px' );
1860					if ( now / delta < 0.5 ) {
1861						var post = fpr_cont.prev(),
1862							post_id = post.data('post-id');
1863						post.addClass('full_post_read');
1864						snowy_add_to_read_list(post_id);
1865					}
1866				} else if ( ! fpr_bt.hasClass('full_post_read_complete') ) {
1867					fpr_bt.addClass('full_post_read_complete');
1868				} else if ( fpr_cs + fpr_ch + wh / 3 < ws + wh ) {
1869					fpr_bt.trigger( 'click' );
1870				}
1871			} else {
1872				// Disabled (add false &&) to prevent remove a progress bar when scroll to top
1873				if ( false && fpr_pw.length !== 0 ) {
1874					fpr_pw.remove();
1875					fpr_pw = null;
1876				}
1877			}
1878		}
1879	}  // snowy_full_post_reading
1880
1881	// Shift top and footer panels when header position is 'Under content'
1882	function snowy_shift_under_panels() {
1883
1884		if ($body.hasClass( 'header_position_under' ) && ! snowy_browser_is_mobile()) {
1885
1886			// Disable 'under' behavior on small screen
1887			if ( $body.hasClass( 'mobile_layout' ) ) {	//snowy_window_width() < SNOWY_STORAGE['mobile_breakpoint_underpanels_off'] ) {
1888				if ( $header.css( 'position' ) == 'fixed' ) {
1889					// Header
1890					$header.css(
1891						{
1892							'position': 'relative',
1893							'left': 'auto',
1894							'top': 'auto',
1895							'width': 'auto',
1896							'transform': 'none',
1897							'zIndex': 3
1898						}
1899					);
1900					$header.find( '.top_panel_mask' ).hide();
1901					// Content
1902					$page_content_wrap.css(
1903						{
1904							'marginTop': 0,
1905							'marginBottom': 0,
1906							'zIndex': 2
1907						}
1908					);
1909					// Footer
1910					$footer.css(
1911						{
1912							'position': 'relative',
1913							'left': 'auto',
1914							'bottom': 'auto',
1915							'width': 'auto',
1916							'transform': 'none',
1917							'zIndex': 1
1918						}
1919					);
1920					$footer.find( '.top_panel_mask' ).hide();
1921				}
1922				return;
1923			}
1924
1925			// Header
1926			var delta           = 50;
1927			var scroll_offset   = snowy_window_scroll_top();
1928			var header_height   = _header_height;
1929			var shift           = ! (/Chrome/.test( navigator.userAgent ) && /Google Inc/.test( navigator.vendor ))
1930									|| $header.find( '.slider_engine_revo' ).length === 0
1931										? 0	//1.2		// Parallax speed (if 0 - disable parallax)
1932										: 0;
1933			var mask            = $header.find( '.top_panel_mask' );
1934			var mask_opacity    = 0;
1935			var css             = {};
1936			if (mask.length === 0) {
1937				$header.append( '<div class="top_panel_mask"></div>' );
1938				mask = $header.find( '.top_panel_mask' );
1939			}
1940			if ( $header.css( 'position' ) !== 'fixed' ) {
1941				$page_content_wrap.css(
1942					{
1943						'zIndex': 5,
1944						'marginTop': header_height + 'px'
1945					}
1946				);
1947				$header.css(
1948					{
1949						'position': 'fixed',
1950						'left': 0,
1951						'top': snowy_adminbar_height() + 'px',
1952						'width': '100%',
1953						'zIndex': 3
1954					}
1955				);
1956			} else {
1957				$page_content_wrap.css( 'marginTop', header_height + 'px' );
1958			}
1959			if (scroll_offset > 0) {
1960				var offset = scroll_offset;	// - snowy_adminbar_height();
1961				if (offset <= header_height) {
1962					mask_opacity = Math.max( 0, Math.min( 0.8, (offset - delta) / header_height ) );
1963					// Don't shift header with Revolution slider in Chrome
1964					if (shift) {
1965						$header.css( 'transform', 'translate3d(0px, ' + (-Math.round( offset / shift )) + 'px, 0px)' );
1966					}
1967					mask.css(
1968						{
1969							'opacity': mask_opacity,
1970							'display': offset === 0 ? 'none' : 'block'
1971						}
1972					);
1973				} else {
1974					if (shift) {
1975						$header.css( 'transform', 'translate3d(0px, ' + (-Math.round( offset / shift )) + 'px, 0px)' );
1976					}
1977				}
1978			} else {
1979				if (shift) {
1980					$header.css( 'transform', 'none' );
1981				}
1982				if (mask.css( 'display' ) != 'none') {
1983					mask.css(
1984						{
1985							'opacity': 0,
1986							'display': 'none'
1987						}
1988					);
1989				}
1990			}
1991
1992			// Footer
1993			var footer_height  = Math.min( _footer_height, snowy_window_height() );
1994			var footer_visible = (scroll_offset + snowy_window_height()) - ( $header.outerHeight() + $page_content_wrap.outerHeight() );
1995			if ( $footer.css( 'position' ) !== 'fixed' ) {
1996				$page_content_wrap.css(
1997					{
1998						'marginBottom': footer_height + 'px'
1999					}
2000				);
2001				$footer.css(
2002					{
2003						'position': 'fixed',
2004						'left': 0,
2005						'bottom': 0,
2006						'width': '100%',
2007						'zIndex': 2
2008					}
2009				);
2010			} else {
2011				$page_content_wrap.css( 'marginBottom', footer_height + 'px' );
2012			}
2013			if ( footer_visible > 0 ) {
2014				if ( $footer.css( 'zIndex' ) == 2 ) {
2015					$footer.css( 'zIndex', 4 );
2016				}
2017				mask = $footer.find( '.top_panel_mask' );
2018				if (mask.length === 0) {
2019					$footer.append( '<div class="top_panel_mask"></div>' );
2020					mask = $footer.find( '.top_panel_mask' );
2021				}
2022				if (footer_visible <= footer_height) {
2023					mask_opacity = Math.max( 0, Math.min( 0.8, (footer_height - footer_visible) / footer_height ) );
2024					// Don't shift header with Revolution slider in Chrome
2025					if (shift) {
2026						$footer.css( 'transform', 'translate3d(0px, ' + Math.round( (footer_height - footer_visible) / shift ) + 'px, 0px)' );
2027					}
2028					mask.css(
2029						{
2030							'opacity': mask_opacity,
2031							'display': footer_height - footer_visible <= 0 ? 'none' : 'block'
2032						}
2033					);
2034				} else {
2035					if (shift) {
2036						$footer.css( 'transform', 'none' );
2037					}
2038					if (mask.css( 'display' ) != 'none') {
2039						mask.css(
2040							{
2041								'opacity': 0,
2042								'display': 'none'
2043							}
2044						);
2045					}
2046				}
2047			} else {
2048				if ( $footer.css( 'zIndex' ) == 4 ) {
2049					$footer.css( 'zIndex', 2 );
2050				}
2051			}
2052		}
2053	}  // snowy_shift_under_panels
2054
2055
2056	// Fix/unfix footer
2057	function snowy_fix_footer() {
2058		if ( $body.hasClass( 'header_position_under' ) && ! snowy_browser_is_mobile() ) {
2059			if ( $footer.length > 0 ) {
2060				var ft_height = $footer.outerHeight( false ),
2061				pc            = $page_content_wrap,
2062				pc_offset     = pc.offset().top,
2063				pc_height     = pc.height();
2064				if ( pc_offset + pc_height + ft_height < snowy_window_height() ) {
2065					if ( $footer.css( 'position' ) != 'absolute' ) {
2066						$footer.css( {
2067							'position': 'absolute',
2068							'left': 0,
2069							'bottom': 0,
2070							'width' :'100%'
2071						} );
2072					}
2073				} else {
2074					if ( $footer.css( 'position' ) != 'relative' ) {
2075						$footer.css( {
2076							'position': 'relative',
2077							'left': 'auto',
2078							'bottom': 'auto'
2079						} );
2080					}
2081				}
2082			}
2083		}
2084	}  // snowy_fix_footer
2085
2086	// Fix/unfix sidebar
2087	function snowy_fix_sidebar(force) {
2088		// Fix sidebar only if css sticky behaviour is not used
2089		if ( $body.hasClass( 'fixed_blocks_sticky' ) ) {
2090			return;
2091		}
2092		$sidebar.each( function() {
2093			var sb        = jQuery( this );
2094			var content   = sb.siblings( '.content' );
2095			var old_style = '';
2096
2097			if ( content.length == 0 ) {
2098				return;
2099			}
2100
2101			// Unfix when sidebar is under content
2102			if (content.css( 'float' ) == 'none') {
2103				old_style = sb.data( 'old_style' );
2104				if (old_style !== undefined) {
2105					sb.attr( 'style', old_style ).removeAttr( 'data-old_style' );
2106				}
2107
2108			} else {
2109
2110				var sb_height      = sb.outerHeight();
2111				var sb_shift       = 30;
2112				var content_height = content.outerHeight();
2113				var content_top    = content.offset().top;
2114				var content_shift  = content.position().top;
2115
2116				// If sidebar shorter then content and page scrolled below the content's top
2117				if (sb_height < content_height && snowy_window_scroll_top() + snowy_fixed_rows_height() > content_top) {
2118
2119					var sb_init = {
2120						'position': 'undefined',
2121						'float': 'none',
2122						'top': 'auto',
2123						'bottom': 'auto',
2124						'marginLeft': '0',
2125						'marginRight': '0'
2126					};
2127
2128					if (typeof SNOWY_STORAGE['scroll_offset_last'] == 'undefined') {
2129						SNOWY_STORAGE['sb_top_last']        = content_top;
2130						SNOWY_STORAGE['scroll_offset_last'] = snowy_window_scroll_top();
2131						SNOWY_STORAGE['scroll_dir_last']    = 1;
2132					}
2133					var scroll_dir = snowy_window_scroll_top() - SNOWY_STORAGE['scroll_offset_last'];
2134					if (scroll_dir === 0) {
2135						scroll_dir = SNOWY_STORAGE['scroll_dir_last'];
2136					} else {
2137						scroll_dir = scroll_dir > 0 ? 1 : -1;
2138					}
2139
2140					var sb_big = sb_height + sb_shift >
2140= snowy_window_height() - snowy_fixed_rows_height(),
2141					sb_top     = sb.offset().top;
2142
2143					if (sb_top < 0) {
2144						sb_top = SNOWY_STORAGE['sb_top_last'];
2145					}
2146
2147					// If sidebar height greater then window height
2148					if (sb_big) {
2149
2150						// If change scrolling dir
2151						if (scroll_dir != SNOWY_STORAGE['scroll_dir_last'] && sb.css( 'position' ) == 'fixed') {
2152							sb_init.position = 'absolute';
2153							sb_init.top      = sb_top + content_shift - content_top;
2154
2155						// If scrolling down
2156						} else if (scroll_dir > 0) {
2157							if (snowy_window_scroll_top() + snowy_window_height() >= content_top + content_height) {
2158								sb_init.position = 'absolute';
2159								sb_init.bottom   = 0;
2160							} else if (snowy_window_scroll_top() + snowy_window_height() >= (sb.css( 'position' ) == 'absolute' ? sb_top : content_top) + sb_height + sb_shift) {
2161								sb_init.position = 'fixed';
2162								sb_init.bottom   = sb_shift;
2163							}
2164
2165						// If scrolling up
2166						} else {
2167							if (snowy_window_scroll_top() + snowy_fixed_rows_height() <= sb_top) {
2168								sb_init.position = 'fixed';
2169								sb_init.top      = snowy_fixed_rows_height();
2170							}
2171						}
2172
2173					// If sidebar height less then window height
2174					} else {
2175						if (snowy_window_scroll_top() + snowy_fixed_rows_height() >= content_top + content_height - sb_height) {
2176							sb_init.position = 'absolute';
2177							sb_init.bottom   = 0;
2178						} else {
2179							sb_init.position = 'fixed';
2180							sb_init.top      = snowy_fixed_rows_height();
2181						}
2182					}
2183					
2184					if (force && sb_init.position == 'undefined' && sb.css('position') == 'absolute') {
2185						sb_init.position = 'absolute';
2186						if (sb.css('top') != 'auto') {
2187							sb_init.top = sb.css('top');
2188						} else {
2189							sb_init.bottom = sb.css('bottom');
2190						}
2191					}
2192
2193					// Check bounds
2194					if ( sb_init.position == 'absolute' || sb_init.position == 'undefined' ) {
2195						if ( sb_init.top == 'auto' && sb_init.bottom == 'auto' ) {
2196							sb_init.top = sb.offset().top;
2197						}
2198						if ( sb_init.top != 'auto' ) {
2199							if ( sb_init.top + sb_height > content_height ) {
2200								sb_init.position = 'absolute';
2201								sb_init.top = content_shift + content_height - sb_height;
2202								force = true;
2203							}
2204							if ( sb_init.top + sb_height <= content_shift + content_height && sb_init.top >= snowy_window_scroll_top() + snowy_window_height() ) {
2205								sb_init.position = 'fixed';
2206								sb_init.top      = 'auto';
2207								sb_init.bottom   = sb_shift;
2208								force = true;
2209							}
2210						}
2211					} else if ( sb_init.position == 'fixed' ) {
2212						if ( sb_init.top == 'auto' && sb_init.bottom == 'auto' && sb.css('top') != 'auto') {
2213							sb_init.top = parseFloat( sb.css('top') );
2214						}
2215						if ( sb_init.top != 'auto' && snowy_window_scroll_top() + sb_init.top + sb_height > content_top + content_height ) {
2216							sb_init.position = 'absolute';
2217							sb_init.top = content_shift + content_height - sb_height;
2218							force = true;
2219						}
2220					}
2221
2222					// Set new position of the sidebar
2223					if (sb_init.position != 'undefined') {
2224						// Insert placeholder before sidebar
2225						var style = sb.attr('style');
2226						if (!style) style = '';
2227						if (!sb.prev().hasClass('sidebar_fixed_placeholder')) {
2228							sb.css(sb_init);
2229							SNOWY_STORAGE['scroll_dir_last'] = 0;
2230							sb.before('<div class="sidebar_fixed_placeholder '+sb.attr('class')+'"'
2231									   		+ (sb.data('sb') ? ' data-sb="' + sb.data('sb') + '"' : '')
2232									   + '></div>');
2233						}
2234						// Detect horizontal position
2235						if ( sb_init.position == 'absolute' && $body.hasClass( 'body_style_fullwide' ) && $body.hasClass( 'sidebar_right' ) ) {
2236							sb_init.left = sb.parent().innerWidth() - sb.prev().width() - parseFloat( sb.parent().css( 'paddingLeft' ) );
2237						} else if ( sb_init.position == 'fixed' || $body.hasClass('body_style_fullwide') || $body.hasClass('body_style_fullscreen') ) {
2238							sb_init.left = sb.prev().offset().left;
2239						} else {
2240							sb_init.left = sb.prev().position().left;
2241						}
2242						sb_init.right = 'auto';
2243						sb_init.width = sb.prev().width() + parseFloat(sb.prev().css('paddingLeft')) + parseFloat(sb.prev().css('paddingRight'));
2244						// Set position
2245						if (force
2246							|| sb.css('position') != sb_init.position 
2247							|| SNOWY_STORAGE['scroll_dir_last'] != scroll_dir
2248							|| sb.width() != sb_init.width) {
2249							if (sb.data('old_style') === undefined) {
2250								sb.attr('data-old_style', style);
2251							}
2252							sb.css(sb_init);
2253						}
2254					}
2255
2256					SNOWY_STORAGE['sb_top_last']        = sb_top;
2257					SNOWY_STORAGE['scroll_offset_last'] = snowy_window_scroll_top();
2258					SNOWY_STORAGE['scroll_dir_last']    = scroll_dir;
2259
2260				} else {
2261
2262					// Unfix when page scrolling to top
2263					old_style = sb.data( 'old_style' );
2264					if (old_style !== undefined) {
2265						sb.attr( 'style', old_style ).removeAttr( 'data-old_style' );
2266						if (sb.prev().hasClass('sidebar_fixed_placeholder')) {
2267							sb.prev().remove();
2268						}
2269					}
2270
2271				}
2272			}
2273		} );
2274	}  // snowy_fix_sidebar
2275
2276	// Fix/unfix .nav_links_fixed
2277	function snowy_fix_nav_links() {
2278		if ( $single_nav_links_fixed.length >
2278 0 && $single_nav_links_fixed.css( 'position' ) == 'fixed') {
2279			var window_bottom = snowy_window_scroll_top() + snowy_window_height(),
2280				article = jQuery('.post_item_single'),
2281				article_top = article.length > 0 ? article.offset().top : snowy_window_height(),
2282				article_bottom = article_top + ( article.length > 0 ? article.height() * 2 / 3 : 0 ),
2283				footer_top = $footer.length > 0 ? $footer.offset().top : 100000;
2284			if ( article_bottom < window_bottom && footer_top > window_bottom ) {
2285				if ( ! $single_nav_links_fixed.hasClass('nav-links-visible') ) {
2286					$single_nav_links_fixed.addClass('nav-links-visible');
2287				}
2288			} else {
2289				if ( $single_nav_links_fixed.hasClass('nav-links-visible') ) {
2290					$single_nav_links_fixed.removeClass('nav-links-visible');
2291				}					
2292			}
2293		}
2294	}
2295
2296	// Fix/unfix .post_info_vertical_fixed
2297	function snowy_fix_share_links() {
2298		if ( $single_post_info_fixed.length > 0 ) {
2299			var frh = snowy_fixed_rows_height() + 10,
2300				st = snowy_window_scroll_top() + frh;
2301			$single_post_info_fixed.each( function() {
2302				var share_links = jQuery(this),
2303					share_links_top = share_links.offset().top,
2304					share_links_left = share_links.offset().left,
2305					share_links_height = share_links.height(),
2306					share_links_position = share_links.css( 'position' ),
2307					article = share_links.parents('.post_content'),
2308					article_top = article.offset().top,
2309					article_bottom = article_top + article.height();
2310				if ( share_links_position == 'absolute') {
2311					if ( st >= article_top && st + share_links_height < article_bottom ) {
2312						share_links
2313							.data('abs-pos', {
2314								'left': share_links.css('left'), 
2315								'top':  share_links.css('top')})
2316							.addClass('post_info_vertical_fixed_on')
2317							.css({
2318								'top':  frh,
2319								'left': share_links_left
2320							});
2321					}
2322				} else if ( share_links_position == 'fixed' ) {
2323					if ( st < article_top ) {
2324						if ( share_links.hasClass( 'post_info_vertical_fixed_on' ) ) {
2325							var abs_pos = share_links.data('abs-pos');
2326							share_links
2327								.removeClass( 'post_info_vertical_fixed_on' )
2328								.css({
2329									'top': abs_pos.top,
2330									'left': abs_pos.left
2331								});
2332						}
2333					} else if ( st + share_links_height >= article_bottom ) {
2334						share_links.fadeOut();
2335					} else if ( share_links.css('display') == 'none' ) {
2336						share_links.fadeIn();
2337					}
2338				}
2339			});
2340		}
2341	}
2342
2343
2344
2345
2346	// Resize actions
2347	//==============================================
2348
2349	// Do actions when page scrolled
2350	function snowy_resize_actions(cont) {
2351
2352		// Update global values
2353		_header_height = $header.length === 0 ? 0 : $header.height();
2354		_footer_height = $footer.length === 0 ? 0 : $footer.height();
2355		
2356		// Call handlers
2357		snowy_check_layout();
2358		snowy_fix_sidebar(true);
2359		snowy_fix_footer();
2360		snowy_fix_nav_links();
2361		snowy_stretch_width( cont );
2362		snowy_stretch_bg_video();
2363		snowy_vc_row_fullwidth_to_boxed( cont );
2364		snowy_stretch_sidemenu();
2365		snowy_resize_video( cont );
2366		snowy_shift_under_panels();
2367
2368		// Call theme/plugins specific action (if exists)
2369		//----------------------------------------------
2370		$document.trigger( 'action.resize_snowy', [cont] );
2371	}
2372
2373	// Stretch sidemenu (if present)
2374	function snowy_stretch_sidemenu() {
2375		var toc_items = $menu_side_wrap.find( '.toc_menu_item' );
2376		if (toc_items.length === 0) {
2377			return;
2378		}
2379		var toc_items_height = snowy_window_height()
2380							- snowy_adminbar_height()
2381							- $menu_side_logo.outerHeight()
2382							- toc_items.length;
2383		var th               = Math.floor( toc_items_height / toc_items.length );
2384		var th_add           = toc_items_height - th * toc_items.length;
2385		if (SNOWY_STORAGE['menu_side_stretch'] && toc_items.length >= 5 && th >= 30) {
2386			toc_items.find( ".toc_menu_description,.toc_menu_icon" ).css(
2387				{
2388					'height': th + 'px',
2389					'lineHeight': th + 'px'
2390				}
2391			);
2392			toc_items.eq( 0 ).find( ".toc_menu_description,.toc_menu_icon" ).css(
2393				{
2394					'height': (th + th_add) + 'px',
2395					'lineHeight': (th + th_add) + 'px'
2396				}
2397			);
2398		}
2399		//$menu_side_wrap.find('#toc_menu').height(toc_items_height + toc_items.length - toc_items.eq(0).height());
2400	}
2401
2402	// Scroll sidemenu (if present)
2403	$document.on( 'action.toc_menu_item_active', function() {
2404		var toc_menu = $menu_side_wrap.find( '#toc_menu' );
2405		if (toc_menu.length === 0) {
2406			return;
2407		}
2408		var toc_items = toc_menu.find( '.toc_menu_item' );
2409		if (toc_items.length === 0) {
2410			return;
2411		}
2412		var th           = toc_items.eq( 0 ).height(),
2413		toc_menu_pos     = parseFloat( toc_menu.css( 'top' ) ),
2414		toc_items_height = toc_items.length * th,
2415		menu_side_height = snowy_window_height()
2416							- snowy_adminbar_height()
2417							- $menu_side_logo.outerHeight()
2418							- $menu_side_logo.next( '.toc_menu_item' ).outerHeight();
2419		if ( toc_items_height > menu_side_height ) {
2420			var toc_item_active = $menu_side_wrap.find( '.toc_menu_item_active' ).eq( 0 );
2421			if ( toc_item_active.length == 1 ) {
2422				var toc_item_active_pos = (toc_item_active.index() + 1) * th;
2423				if (toc_menu_pos + toc_item_active_pos > menu_side_height - th) {
2424					toc_menu.css( 'top', Math.max( -toc_item_active_pos + 3 * th, menu_side_height - toc_items_height ) );
2425				} else if (toc_menu_pos < 0 && toc_item_active_pos < -toc_menu_pos + 2 * th) {
2426					toc_menu.css( 'top', Math.min( -toc_item_active_pos + 3 * th, 0 ) );
2427				}
2428			}
2429		} else if ( toc_menu_pos < 0 ) {
2430			toc_menu.css( 'top', 0 );
2431		}
2432	} );
2433
2434	// Check for mobile layout
2435	function snowy_check_layout() {
2436		var resize = true;
2437		if ( $body.hasClass( 'no_layout' ) ) {
2438			$body.removeClass( 'no_layout' );
2439			resize = false;
2440		}
2441		var w = window.innerWidth;
2442		if (w == undefined) {
2443			w = snowy_window_width() + ( snowy_window_height() < snowy_document_height() || snowy_window_scroll_top() > 0 ? 16 : 0 );
2444		}
2445		if ( w < SNOWY_STORAGE['mobile_layout_width'] ) {
2446			if ( ! $body.hasClass( 'mobile_layout' )) {
2447				$body.removeClass( 'desktop_layout' ).addClass( 'mobile_layout' );
2448				$document.trigger( 'action.switch_to_mobile_layout' );
2449				if (resize) {
2450					$window.trigger( 'resize' );
2451				}
2452			}
2453		} else {
2454			if ( ! $body.hasClass( 'desktop_layout' )) {
2455				$body.removeClass( 'mobile_layout' ).addClass( 'desktop_layout' );
2456				jQuery( '.menu_mobile' ).removeClass( 'opened' );
2457				jQuery( '.menu_mobile_overlay' ).hide();
2458				$document.trigger( 'action.switch_to_desktop_layout' );
2459				if ( resize ) {
2460					$window.trigger( 'resize' );
2461				}
2462			}
2463		}
2464		if (SNOWY_STORAGE['mobile_device'] || snowy_browser_is_mobile()) {
2465			$body.addClass( 'mobile_device' );
2466		}
2467	}
2468
2469	// Stretch area to full window width
2470	function snowy_stretch_width(cont) {
2471		if (cont === undefined) {
2472			cont = $body;
2473		}
2474		$stretch_width.each(
2475			function() {
2476				var $el             = jQuery( this );
2477				var $el_cont        = $el.parents( '.page_wrap' );
2478				var $el_cont_offset = 0;
2479				if ($el_cont.length === 0) {
2480					$el_cont = $window;
2481				} else {
2482					$el_cont_offset = $el_cont.offset().left;
2483				}
2484				var $el_full        = $el.next( '.trx-stretch-width-original' );
2485				var el_margin_left  = parseInt( $el.css( 'margin-left' ), 10 );
2486				var el_margin_right = parseInt( $el.css( 'margin-right' ), 10 );
2487				var offset          = $el_cont_offset - $el_full.offset().left - el_margin_left;
2488				var width           = $el_cont.width();
2489				if ( ! $el.hasClass( 'inited' )) {
2490					$el.addClass( 'inited invisible' );
2491					$el.css(
2492						{
2493							'position': 'relative',
2494							'box-sizing': 'border-box'
2495						}
2496					);
2497				}
2498				$el.css(
2499					{
2500						'left': offset,
2501						'width': $el_cont.width()
2502					}
2503				);
2504				if ( ! $el.hasClass( 'trx-stretch-content' ) ) {
2505					var padding      = Math.max( 0, -1 * offset );
2506					var paddingRight = Math.max( 0, width - padding - $el_full.width() + el_margin_left + el_margin_right );
2507					$el.css( { 'padding-left': padding + 'px', 'padding-right': paddingRight + 'px' } );
2508				}
2509				$el.removeClass( 'invisible' );
2510			}
2511		);
2512	}  // snowy_stretch_width
2513
2514	// Resize video frames
2515	function snowy_resize_video(cont) {
2516		if (cont === undefined) {
2517			cont = $body;
2518		}
2519		// Resize tags 'video'
2520		cont.find( 'video' ).each( function() {
2521			var $self = jQuery( this );
2522			// If item now invisible
2523			if ( ( ! SNOWY_STORAGE['resize_tag_video'] && $self.parents('.mejs-mediaelement').length === 0 )
2524				|| $self.hasClass( 'trx_addons_resize' )
2525				|| $self.hasClass( 'trx_addons_noresize' )
2526				|| $self.parents( 'div:hidden,section:hidden,article:hidden' ).length > 0
2527			) {
2528				return;
2529			}
2530			var video     = $self.addClass( 'snowy_resize' ).eq( 0 );
2531			var ratio     = (video.data( 'ratio' ) !== undefined ? video.data( 'ratio' ).split( ':' ) : [16,9]);
2532			ratio         = ratio.length != 2 || ratio[0] === 0 || ratio[1] === 0 ? 16 / 9 : ratio[0] / ratio[1];
2533			var mejs_cont = video.parents( '.mejs-video' ).eq(0);
2534			var mfp_cont  = video.parents( '.mfp-content' ).eq(0);
2535			var w_attr    = video.data( 'width' );
2536			var h_attr    = video.data( 'height' );
2537			if ( ! w_attr || ! h_attr) {
2538				w_attr = video.attr( 'width' );
2539				h_attr = video.attr( 'height' );
2540				if ( ! w_attr || ! h_attr) {
2541					if ( ( ! w_attr || ! h_attr ) && mejs_cont.length > 0 ) {
2542						w_attr = Math.ceil( mejs_cont.width() );
2543						h_attr = Math.ceil( mejs_cont.height() );
2544					}
2545					if ( ! w_attr || ! h_attr ) {
2546					return;
2547				}
2548				}
2549				video.data( {'width': w_attr, 'height': h_attr} );
2550			}
2551			var percent = ('' + w_attr).slice( -1 ) == '%';
2552			w_attr      = parseInt( w_attr, 10 );
2553			h_attr      = parseInt( h_attr, 10 );
2554			var par     = mejs_cont.length > 0 ? mejs_cont.parents('.post_video,.post_featured').eq(0) : video.parents('.post_video,.post_featured').eq(0);
2555			if ( ! par.length ) {
2556				par = mejs_cont.length > 0 ? mejs_cont.parents('div,section,article').eq(0) : video.parents('div,section,article').eq(0);
2557			}
2558			var w_real  = Math.ceil( Math.min( percent ? 10000 : w_attr, par.width() ) );
2559			if ( mfp_cont.length > 0 ) {
2560				w_real  = Math.max( mfp_cont.width(), w_real );
2561			}
2562			var h_real  = Math.ceil( percent ? w_real / ratio : w_real / w_attr * h_attr );
2563			if ( parseInt( video.attr( 'data-last-width' ), 10 ) == w_real ) {
2564				return;
2565			}
2566			if ( percent ) {
2567				video.height( h_real );
2568			} else if ( video.parents( '.wp-video-playlist' ).length > 0 ) {
2569				if ( mejs_cont.length === 0 ) {
2570					video.attr( {'width': w_real, 'height': h_real} );
2571				}
2572			} else {
2573				video.attr( {'width': w_real, 'height': h_real} ).css( {'width': w_real + 'px', 'height': h_real + 'px'} );
2574				// If a height of the video is less than h_real - a max-height is applied, recalculate the width
2575				var h_video = video.height();
2576				if ( h_video < h_real ) {
2577					w_real = Math.ceil( w_real * h_video / h_real );
2578					h_real = h_video;
2579					video.attr( {'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'} );
2580				}
2581				// Set dimensions for Media Elements player
2582				if ( mejs_cont.length > 0 ) {
2583					snowy_set_mejs_player_dimensions( video, w_real, h_real );
2584				}
2585			}
2586			video.attr( 'data-last-width', w_real );
2587		} );
2588
2589		// Resize tags 'iframe'
2590		if ( SNOWY_STORAGE['resize_tag_iframe'] ) {
2591			cont.find( '.video_frame iframe,iframe' ).each( function() {
2592				var $self = jQuery( this );
2593				// If item now invisible
2594				if (   $self.hasClass( 'trx_addons_resize' )
2595					|| $self.hasClass( 'trx_addons_noresize' )
2596					|| $self.parent().is( 'rs-bgvideo' )
2597					|| $self.parents( 'rs-slide' ).length > 0
2598					|| $self.addClass( 'snowy_resize' ).parents( 'div:hidden,section:hidden,article:hidden' ).length > 0
2599					|| document.fullscreenElement
2600					|| document.mozFullScreenElement
2601					|| document.webkitFullscreenElement
2602					|| document.msFullscreenElement
2603				) {
2604					return;
2605				}
2606				var iframe = $self.eq( 0 );
2607				if (iframe.length === 0 || iframe.attr( 'src' ) === undefined || iframe.attr( 'src' ).indexOf( 'soundcloud' ) > 0) {
2608					return;
2609				}
2610				var w_attr = iframe.attr( 'width' );
2611				var h_attr = iframe.attr( 'height' );
2612				if ( ! w_attr || ! h_attr || w_attr <= snowy_apply_filters( 'snowy_filter_noresize_iframe_width', 325 ) ) {
2613					return;
2614				}
2615				var ratio  = iframe.data( 'ratio' ) !== undefined
2616								? iframe.data( 'ratio' ).split( ':' )
2617								: ( iframe.parent().data( 'ratio' ) !== undefined
2618									? iframe.parent().data( 'ratio' ).split( ':' )
2619									: ( iframe.find( '[data-ratio]' ).length > 0
2620										? iframe.find( '[data-ratio]' ).data( 'ratio' ).split( ':' )
2621										: [w_attr, h_attr]
2622										)
2623									);
2624				ratio      = ratio.length != 2 || ratio[0] === 0 || ratio[1] === 0 ? 16 / 9 : ratio[0] / ratio[1];
2625				var percent   = ( '' + w_attr ).slice( -1 ) == '%';
2626				w_attr        = parseInt( w_attr, 10 );
2627				h_attr        = parseInt( h_attr, 10 );
2628				var par       = iframe.parents( '.post_video,.post_featured' ).eq(0);
2629				if ( ! par.length ) {
2630					par = iframe.parents( '.mfp-content' ).eq(0);
2631					if ( ! par.length ) {
2632						par = iframe.parents( 'div,section,article' ).eq(0);
2633					}
2634				}
2635				var	contains  = iframe.data('contains-in-parent')=='1' || iframe.hasClass('contains-in-parent'),
2636					nostretch = iframe.data('no-stretch-to-parent')=='1' || iframe.hasClass('no-stretch-to-parent'),
2637					pw        = Math.ceil( par.width() ),
2638					ph        = Math.ceil( par.height() ),
2639					w_real    = nostretch ? Math.min( w_attr, pw ) : pw,
2640					h_real    = Math.ceil( percent ? w_real / ratio : w_real / w_attr * h_attr );
2641				if ( contains && par.css( 'position' ) == 'absolute' && h_real > ph) {
2642					h_real = ph;
2643					w_real = Math.ceil( percent ? h_real * ratio : h_real * w_attr / h_attr );
2644				}
2645				if (parseInt( iframe.attr( 'data-last-width' ), 10 ) == w_real) {
2646					return;
2647				}
2648				iframe.css( {'width': w_real + 'px', 'height': h_real + 'px'} );
2649				iframe.attr( 'data-last-width', w_real );
2650			} );
2651		}
2652	}  // snowy_resize_video
2653
2654	// Set Media Elements player dimensions
2655	function snowy_set_mejs_player_dimensions(video, w, h) {
2656		if (mejs) {
2657			for (var pl in mejs.players) {
2658				if (mejs.players[pl].media.src == video.attr( 'src' )) {
2659					if (mejs.players[pl].media.setVideoSize) {
2660						mejs.players[pl].media.setVideoSize( w, h );
2661					} else if (mejs.players[pl].media.setSize) {
2662						mejs.players[pl].media.setSize( w, h );
2663					}
2664					mejs.players[pl].setPlayerSize( w, h );
2665					mejs.players[pl].setControlsSize();
2666				}
2667			}
2668		}
2669	}
2670
2671	// Stretch background video
2672	function snowy_stretch_bg_video() {
2673		var video_wrap = jQuery( 'div#background_video,.tourmaster-background-video' );
2674		if (video_wrap.length === 0) {
2675			return;
2676		}
2677		var cont = video_wrap.hasClass( 'tourmaster-background-video' ) ? video_wrap.parent() : video_wrap,
2678		w        = cont.width(),
2679		h        = cont.height(),
2680		video    = video_wrap.find( '>iframe,>video' );
2681		if (w / h < 16 / 9) {
2682			w = h / 9 * 16;
2683		} else {
2684			h = w / 16 * 9;
2685		}
2686		video
2687			.attr( {'width': w, 'height': h} )
2688			.css( {'width': w, 'height': h} );
2689	}
2690
2691	// Recalculate width of the vc_row[data-vc-full-width="true"] when content boxed or menu_side=='left|right'
2692	$document.on('vc-full-width-row action.before_resize_trx_addons', function(e, container) {
2693		snowy_vc_row_fullwidth_to_boxed( jQuery(container) );
2694	});
2695	function snowy_vc_row_fullwidth_to_boxed(cont) {
2696		if ( $body.hasClass( 'body_style_boxed' )
2697			|| $body.hasClass( 'menu_side_present' )
2698			|| parseInt($page_wrap.css('paddingLeft'), 10) > 0
2699		) {
2700			if (cont === undefined || ! cont.hasClass( '.vc_row' ) || ! cont.data( 'vc-full-width' )) {
2701				cont = jQuery( '.vc_row[data-vc-full-width="true"]' );
2702			}
2703			var rtl                = jQuery( 'html' ).attr( 'dir' ) == 'rtl';
2704			var page_wrap_pl       = parseInt( $page_wrap.css('paddingLeft'), 10 );
2705			if ( isNaN( page_wrap_pl ) ) {
2706				page_wrap_pl = 0;
2707			}
2708			var page_wrap_pr       = parseInt( $page_wrap.css('paddingRight'), 10 );
2709			if ( isNaN( page_wrap_pr ) ) {
2710				page_wrap_pr = 0;
2711			}
2712			var page_wrap_width    = $page_wrap.outerWidth() - page_wrap_pl - page_wrap_pr;
2713			var content_wrap       = $page_content_wrap.find( '.content_wrap' );
2714			var content_wrap_width = content_wrap.width();
2715			var indent             = ( page_wrap_width - content_wrap_width ) / 2;
2716			cont.each( function() {
2717				var $self           = jQuery( this );
2718				var mrg             = parseInt( $self.css( 'marginLeft' ), 10 );
2719				var stretch_content = $self.attr( 'data-vc-stretch-content' );
2720				var stretch_row     = $self.attr( 'data-vc-full-width' );
2721				var in_content      = $self.parents( '.content_wrap' ).length > 0;
2722				$self.css( {
2723					'width':         in_content && ! stretch_content && ! stretch_row ? Math.min( page_wrap_width, content_wrap_width ) : page_wrap_width,
2724					'left':          rtl ? 'auto' : ( in_content ? -indent : 0 ) - mrg,
2725					'right':         ! rtl ? 'auto' : ( n_content ? -indent : 0 ) - mrg,
2726					'padding-left':  stretch_content ? 0 : indent + mrg,
2727					'padding-right': stretch_content ? 0 : indent + mrg
2728				} );
2729			} );
2730		}
2731	}
2732
2733	ready_busy = false;
2734
2735} );

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.