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