PageSourceSearch

https://www.beinmacedonia.com/wp-content/themes/citygov/fw/js/core.init.js

js beinmacedonia.com collected 2026-10-02 14:20:19 UTC 70,606 bytes, 1,751 lines download raw bytes

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

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.