PageSourceSearch

https://ccmahamilton.ca/wp-content/themes/coworking/fw/js/core.init.js

js ccmahamilton.ca collected 2026-10-09 05:13:24 UTC 58,749 bytes, 1,683 lines download raw bytes

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

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.