PageSourceSearch

https://masaveubodegas.com/wp-content/themes/qwery/js/init.js?reload=269235784

js masaveubodegas.com collected 2026-10-08 12:41:35 UTC 92,798 bytes, 2,683 lines download raw bytes

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

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.