PageSourceSearch

https://healthymontanakids.org/wp-content/themes/kidsplanet/fw/js/core.init.js

js healthymontanakids.org collected 2026-10-07 06:39:04 UTC 54,748 bytes, 1,586 lines download raw bytes

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

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.