PageSourceSearch

https://mathlingo.com/wp-content/themes/kidsplanet/fw/js/core.init.js

js mathlingo.com collected 2026-10-06 13:16:30 UTC 53,715 bytes, 1,531 lines download raw bytes

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

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.