1/** 2 * Table of contents 3 * 4 * 1. General 5 * 2. Components 6 * 3. Header 7 * 4. Core 8 * 5. Widgets 9 * 6. Elements 10 * 7. Other 11 * 8. Accessibility 12 * 9. Plugins 13 */ 14 15(function($){ "use strict"; 16$(document).ready( function() { 17 18/* ----------------------------------------------------------------------------- 19 20 1. GENERAL 21 22----------------------------------------------------------------------------- */ 23 24 /* ------------------------------------------------------------------------- 25 IMPROVE ACCESSIBILITY 26 -------------------------------------------------------------------------- */ 27 28 if ( $( 'body' ).hasClass( 'lsvr-accessibility' ) ) { 29 30 // User is using mouse 31 $(document).on( 'mousedown', function() { 32 $('body').addClass( 'lsvr-using-mouse' ); 33 $('body').removeClass( 'lsvr-using-keyboard' ); 34 }); 35 36 // User is using keyboard 37 $(document).on( 'keyup', function(e) { 38 if ( e.key === "Tab" ) { 39 $('body').addClass( 'lsvr-using-keyboard' ); 40 $('body').removeClass( 'lsvr-using-mouse' ); 41 } 42 }); 43 44 } 45 46 47/* ----------------------------------------------------------------------------- 48 49 2. COMPONENTS 50 51----------------------------------------------------------------------------- */ 52 53 /* ------------------------------------------------------------------------- 54 LEAFLET MAP 55 -------------------------------------------------------------------------- */ 56 57 if ( $.fn.lsvrTownpressMapLeaflet && 'object' === typeof L ) { 58 59 $( '.c-map--leaflet .c-map__canvas' ).each(function() { 60 $(this).lsvrTownpressMapLeaflet(); 61 }); 62 63 } 64 65 /* ------------------------------------------------------------------------- 66 GOOGLE MAP 67 -------------------------------------------------------------------------- */ 68 69 if ( $.fn.lsvrTownpressMapGmaps ) { 70 71 $( '.c-map--gmaps .c-map__canvas' ).each(function() { 72 $(this).lsvrTownpressMapGmaps(); 73 }); 74 75 } 76 77 78/* ----------------------------------------------------------------------------- 79 80 3. HEADER 81 82----------------------------------------------------------------------------- */ 83 84 /* ------------------------------------------------------------------------- 85 HEADER MENU 86 ------------------------------------------------------------------------- */ 87 88 $( '.header-menu' ).each(function() { 89 90 var $this = $(this); 91 92 // Hide desktop all submenus function 93 function resetMenu() { 94 $this.find( '.header-menu__item' ).removeClass( 'header-menu__item--hover header-menu__item--active' ); 95 $this.find( '.header-menu__item-link' ).attr( 'aria-expanded', false ); 96 $this.find( '.header-menu__submenu' ).removeAttr( 'style' ).attr( 'aria-expanded', false ); 97 } 98 99 // Reset menu when click on link without submenu 100 $this.find( '.header-menu__item-link' ).each(function() { 101 $(this).on( 'click', function() { 102 if ( $(this).parent().find( '> .header-menu__submenu' ).length < 1 ) { 103 resetMenu(); 104 } 105 }); 106 }); 107 108 // Parse submenus 109 $this.find( '.header-menu__item--dropdown .header-menu__submenu--level-0, .header-menu__item--dropdown .header-menu__submenu--level-1, .header-menu__item--megamenu .header-menu__submenu--level-0' ).each(function() { 110 111 var $submenu = $(this), 112 $parent = $(this).parent(), 113 $link = $parent.find( '> .header-menu__item-link' ); 114 115 // Show submenu function 116 function showSubmenu() { 117 $parent.addClass( 'header-menu__item--hover' ); 118 $submenu.show(); 119 $link.attr( 'aria-expanded', true ); 120 $submenu.attr( 'aria-expanded', true ); 121 } 122 123 // Hide submenu function 124 function hideSubmenu() { 125 $parent.removeClass( 'header-menu__item--hover' ); 126 $submenu.hide(); 127 $link.attr( 'aria-expanded', false ); 128 $submenu.attr( 'aria-expanded', false ); 129 } 130 131 // Mouseover and focus action 132 $parent.on( 'mouseover focus', function() { 133 showSubmenu(); 134 }); 135 136 // Mouseleave and blur action 137 $parent.on( 'mouseleave blur', function() { 138 hideSubmenu(); 139 }); 140 141 // On click or key enter 142 $link.on( 'click', function( event ) { 143 if ( ! $parent.hasClass( 'header-menu__item--hover' ) ) { 144 145 // Hide opened submenus 146 $parent.siblings( '.header-menu__item.header-menu__item--hover' ).each(function() { 147 $(this).removeClass( 'header-menu__item--hover' ); 148 $(this).find( '> .header-menu__submenu' ).hide(); 149 $(this).find( '> .header-menu__item-link' ).attr( 'aria-expanded', false ); 150 $(this).find( '> .header-menu__submenu' ).attr( 'aria-expanded', false ); 151 }); 152 153 // Show submenu 154 showSubmenu(); 155 156 // Hide on click outside 157 $( 'html' ).on( 'click.lsvrTownpressHeaderMenuCloseSubmenuOnClickOutside', function(e) { 158 159 hideSubmenu(); 160 $( 'html' ).unbind( 'click.lsvrTownpressHeaderMenuCloseSubmenuOnClickOutside' ); 161 162 }); 163 164 // Disable link 165 $parent.on( 'click touchstart', function(e) { 166 e.stopPropagation(); 167 }); 168 return false;
169 170 } 171 hideSubmenu(); 172 }); 173 174 }); 175 176 // Close submenu on ESC key 177 $(document).on( 'keyup.lsvrTownpressHeaderMenuCloseSubmenuOnEscKey', function(e) { 178 179 if ( e.key === "Escape" ) { 180 181 // Find focused link parent 182 if ( $( '*:focus' ).closest( '.header-menu__item--hover' ).length > 0 ) { 183 184 $( '*:focus' ).closest( '.header-menu__item--hover' ).each(function() { 185 186 // Close active submenu 187 $(this).removeClass( 'header-menu__item--hover' ); 188 $(this).find( '> .header-menu__submenu' ).hide(); 189 $(this).find( '> .header-menu__item-link' ).attr( 'aria-expanded', false ); 190 $(this).find( '> .header-menu__submenu' ).attr( 'aria-expanded', false ); 191 192 // Change focus 193 $(this).find( '> .header-menu__item-link' ).focus(); 194 195 }); 196 197 } 198 199 // Otherwise hide all submenus 200 else { 201 202 $( '.header-menu__item--hover' ).each(function() { 203 204 $(this).removeClass( 'header-menu__item--hover' ); 205 $(this).find( '> .header-menu__submenu' ).hide(); 206 $(this).find( '> .header-menu__item-link' ).attr( 'aria-expanded', false ); 207 $(this).find( '> .header-menu__submenu' ).attr( 'aria-expanded', false ); 208 209 }); 210 211 } 212 213 } 214 215 }); 216 217 // Reset on screen transition 218 $(document).on( 'lsvrTownpressScreenTransition', function() { 219 resetMenu(); 220 }); 221 222 }); 223 224 /* ------------------------------------------------------------------------- 225 STICKY NAVBAR 226 -------------------------------------------------------------------------- */ 227 228 $( '.header-navbar--sticky' ).each(function() { 229 230 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() > 991 ) { 231
232 var $navbar = $(this), 233 $placeholder = $( '.header-navbar__placeholder' ), 234 navbarHeight = $navbar.outerHeight(); 235 236 $placeholder.css( 'height', navbarHeight ); 237 238 } 239 240 }); 241 242 /* ------------------------------------------------------------------------- 243 HEADER MAP 244 -------------------------------------------------------------------------- */ 245 246 $( '.header-map' ).each(function() { 247 248 var $this = $(this), 249 $canvas = $this.find( '.header-map__canvas' ), 250 $close = $this.find( '.header-map__close' ), 251 $toggle = $( '.header-map-toggle' ), 252 $spinner = $this.find( '.c-spinner' ), 253 mapPlatform = $canvas.data( 'map-platform' ), 254 map; 255 256 // Toggle map 257 $toggle.on( 'click', function() { 258 259 $this.slideToggle( 100, function() { 260 261 // Load map on first display 262 if ( $this.hasClass( 'header-map--loading' ) ) { 263 264 // Google maps 265 if ( 'gmaps' === mapPlatform && $.fn.lsvrTownpressMapGmaps ) { 266 $canvas.lsvrTownpressMapGmaps(); 267 } 268 269 // Leaflet 270 else if ( 'leaflet' === mapPlatform && $.fn.lsvrTownpressMapLeaflet && 'object' === typeof L ) { 271 $canvas.lsvrTownpressMapLeaflet(); 272 } 273 274 } 275 276 // Display already loaded map 277 else if ( $this.is( ':visible' ) ) { 278 279 // Reize on open 280 if ( typeof $canvas.data( 'map' ) !== 'undefined' ) { 281 map = $canvas.data( 'map' ); 282 283 // Google map 284 if ( 'gmaps' === mapPlatform && 'object' == typeof map && 'object' === typeof google && 'object' === typeof google.maps ) { 285 google.maps.event.trigger( map, 'resize' ); 286 } 287 288 // Leaflet 289 else if ( 'leaflet' === mapPlatform && 'object' == typeof map && 'function' === typeof map['invalidateSize'] ) { 290 map.invalidateSize() 291 } 292 293 } 294 295 } 296 297 $toggle.toggleClass( 'header-map-toggle--active' ); 298 $this.removeClass( 'header-map--loading' ); 299 300 }); 301 302 $( '#header' ).toggleClass( 'header--map-open' ); 303 $( 'body' ).toggleClass( 'lsvr-header-map-open' ); 304 305 }); 306 307 // Close map 308 $close.on( 'click', function() { 309 $this.slideUp( 100 ); 310 $toggle.removeClass( 'header-map-toggle--active' ); 311 $( '#header' ).removeClass( 'header--map-open' ); 312 $( 'body' ).removeClass( 'lsvr-header-map-open' ); 313 }); 314 315 }); 316 317 /* ------------------------------------------------------------------------- 318 MOBILE TOOLBAR 319 -------------------------------------------------------------------------- */ 320 321 // Toogle 322 $( '.header-toolbar-toggle__menu-button' ).each(function() { 323 $(this).on( 'click', function() { 324 325 $( '.header-toolbar-toggle' ).toggleClass( 'header-toolbar-toggle--active' ); 326 $(this).toggleClass( 'header-toolbar-toggle__menu-button--active' ); 327 $( '.header-toolbar' ).slideToggle( 200 ); 328 329 if ( $(this).hasClass( 'header-toolbar-toggle__menu-button--active' ) ) { 330 $(this).attr( 'aria-expanded', true ); 331 } else { 332 $(this).attr( 'aria-expanded', false ); 333 } 334 335 336 }); 337 }); 338 339 // Mobile menu 340 $( '.header-mobile-menu' ).each(function() { 341 342 var expandSubmenuLabel = $(this).data( 'label-expand-submenu' ), 343 collapseSubmenuLabel = $(this).data( 'label-collapse-submenu' ); 344 345 // Submenu toggle 346 $(this).find( '.header-mobile-menu__toggle' ).each(function() { 347 348 var $toggle = $(this), 349 $parent = $toggle.parent(), 350 $submenu = $parent.find( '> .header-mobile-menu__submenu' ); 351 352 $toggle.on( 'click', function( event ) { 353 354 $toggle.toggleClass( 'header-mobile-menu__toggle--active' ); 355 $parent.toggleClass( 'header-mobile-menu__item--active' ); 356 $submenu.slideToggle( 200 ); 357 358 if ( $toggle.hasClass( 'header-mobile-menu__toggle--active' ) ) { 359 360 $toggle.attr( 'aria-label', collapseSubmenuLabel ); 361 $toggle.attr( 'aria-expanded', true ); 362 $submenu.attr( 'aria-expanded', true ); 363 364 } else { 365 366 $toggle.attr( 'aria-label', expandSubmenuLabel ); 367 $toggle.attr( 'aria-expanded', false ); 368 $submenu.attr( 'aria-expanded', false ); 369 370 } 371 372 }); 373 374 }); 375 376 // Close mobile submenu on ESC key 377 $(document).on( 'keyup.lsvrTownpressHeaderMobileMenuCloseSubmenuOnEscKey', function(e) { 378 379 if ( e.key === "Escape" ) { 380 381 // Find focused link parent 382 if ( $( '*:focus' ).closest( '.header-mobile-menu__item--active' ).length > 0 ) { 383 384 $( '*:focus' ).closest( '.header-mobile-menu__item--active' ).each(function() { 385 386 // Close active submenu 387 $(this).removeClass( 'header-mobile-menu__item--active' ); 388 $(this).find( '> .header-mobile-menu__submenu' ).hide(); 389 $(this).find( '> .header-mobile-menu__toggle' ).removeClass( 'header-mobile-menu__toggle--active' ); 390 $(this).find( '> .header-mobile-menu__toggle' ).attr( 'aria-label', expandSubmenuLabel ); 391 $(this).find( '> .header-mobile-menu__toggle' ).attr( 'aria-expanded', false ); 392 $(this).find( '> .header-mobile-menu__submenu' ).attr( 'aria-expanded', false ); 393 394 // Change focus 395 $(this).find( '> .header-mobile-menu__toggle' ).focus(); 396 397 }); 398 399 } 400 401 // Otherwise hide all submenus 402 else { 403 404 $( '.header-mobile-menu__item' ).each(function() { 405 406 $(this).removeClass( 'header-mobile-menu__item--active' ); 407 $(this).find( '> .header-mobile-menu__submenu' ).hide(); 408 $(this).find( '> .header-mobile-menu__toggle' ).removeClass( 'header-mobile-menu__toggle--active' ); 409 $(this).find( '> .header-mobile-menu__toggle' ).attr( 'aria-label', expandSubmenuLabel ); 410 $(this).find( '> .header-mobile-menu__toggle' ).attr( 'aria-expanded', false ); 411 $(this).find( '> .header-mobile-menu__submenu' ).attr( 'aria-expanded', false ); 412 413 }); 414 415 } 416 417 } 418 419 }); 420 421 // Reset on screen transition 422 $(document).on( 'lsvrTownpressScreenTransition', function() { 423 424 $( '.header-toolbar-toggle' ).removeClass( 'header-toolbar-toggle--active' ); 425 $( '.header-toolbar-toggle__menu-button' ).removeClass( 'header-toolbar-toggle__menu-button--active' ).attr( 'aria-expanded', false ); 426 $( '.header-toolbar' ).removeAttr( 'style' ); 427 $( '.header-mobile-menu__item--active' ).removeClass( 'header-mobile-menu__item--active' ); 428 $( '.header-mobile-menu__submenu' ).removeAttr( 'style' ).attr( 'aria-expanded', false ); 429 $( '.header-mobile-menu__toggle--active' ).removeClass( 'header-mobile-menu__toggle--active' ); 430 $( '.header-mobile-menu__toggle' ).attr( 'aria-expanded', false ).attr( 'aria-label', $( '.header-mobile-menu' ).data( 'label-expand-submenu' ) ); 431 432 }); 433 434 }); 435 436 437 /* ------------------------------------------------------------------------- 438 BACKGROUND SLIDESHOW 439 -------------------------------------------------------------------------- */ 440 441 $( '.header-background--slideshow, .header-background--slideshow-home' ).each(function() { 442 443 var $this = $(this), 444 $images = $this.find( '.header-background__image' ),
445 slideshowSpeed = $this.data( 'slideshow-speed' ) ? parseInt( $this.data( 'slideshow-speed' ) ) * 1000 : 10, 446 animationSpeed = 2000; 447 448 // Continue if there are at least two images 449 if ( $images.length > 1 ) { 450 451 // Set default active image 452 $images.filter( '.header-background__image--default' ).addClass( 'header-background__image--active' ); 453 var $active = $images.filter( '.header-background__image--active' ), 454 $next; 455 456 // Change image to next one 457 var changeImage = function() { 458 459 // Determine next image 460 if ( $active.next().length > 0 ) { 461 $next = $active.next(); 462 } 463 else { 464 $next = $images.first(); 465 } 466 467 // Hide active 468 $active.fadeOut( animationSpeed, function() { 469 $(this).removeClass( 'header-background__image--active' ); 470 }); 471 472 // Show next 473 $next.fadeIn( animationSpeed, function() { 474 $(this).addClass( 'header-background__image--active' ); 475 $active = $(this); 476 }); 477 478 // Repeat 479 setTimeout( function() { 480 changeImage(); 481 }, slideshowSpeed ); 482 483 }; 484 485 // Init 486 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() > 1199 ) { 487 setTimeout( function() { 488 changeImage(); 489 }, slideshowSpeed ); 490 } 491 492 } 493 494 }); 495 496/* ----------------------------------------------------------------------------- 497 498 4. CORE 499 500----------------------------------------------------------------------------- */ 501 502 /* ------------------------------------------------------------------------- 503 GALLERIES 504 ------------------------------------------------------------------------- */ 505 506 // Gallery masonry 507 if ( $.fn.masonry && $.fn.imagesLoaded ) { 508 $( '.lsvr_gallery-post-archive .lsvr-grid--masonry, .lsvr_gallery-post-single .post__image-list--masonry' ).each(function() { 509 510 var $this = $(this), 511 isRTL = $( 'html' ).attr( 'dir' ) && 'rtl' === $( 'html' ).attr( 'dir' ) ? true : false; 512 513 // Wait for images to load 514 $this.imagesLoaded(function() { 515 $this.masonry({ 516 isRTL: isRTL 517 }); 518 }); 519 520 }); 521 } 522 523 /* ------------------------------------------------------------------------- 524 DOCUMENTS 525 ------------------------------------------------------------------------- */ 526 527 // Categorized attachments 528 $( '.lsvr_document-post-archive--categorized-attachments .post-tree' ).each(function() { 529 530 var expandSubmenuLabel = $(this).data( 'label-expand-submenu' ), 531 collapseSubmenuLabel = $(this).data( 'label-collapse-submenu' ); 532 533 $(this).find( '.post-tree__item-toggle' ).each(function() { 534 535 var $toggle = $(this), 536 $parent = $toggle.parent(), 537 $submenu = $parent.find( '> .post-tree__children' ); 538 539 $toggle.on( 'click', function() { 540 541 $toggle.toggleClass( 'post-tree__item-toggle--active' ); 542 $parent.toggleClass( 'post-tree__item--active' ); 543 $submenu.slideToggle( 200 ); 544 545 if ( $toggle.hasClass( 'post-tree__item-toggle--active' ) ) { 546 547 $toggle.attr( 'aria-label', collapseSubmenuLabel ); 548 $toggle.attr( 'aria-expanded', true ); 549 $submenu.attr( 'aria-expanded', true ); 550 551 } else { 552 553 $toggle.attr( 'aria-label', expandSubmenuLabel ); 554 $toggle.attr( 'aria-expanded', false ); 555 $submenu.attr( 'aria-expanded', false ); 556 557 } 558 559 }); 560 561 }); 562 563 // Close mobile submenu on ESC key 564 $(document).on( 'keyup.lsvrTownpressDocumentArchiveCategorizedAttachmentsCloseSubmenuOnEscKey', function(e) { 565 566 if ( e.key === "Escape" ) { 567 568 // Find focused link parent 569 if ( $( '*:focus' ).closest( '.post-tree__item--active' ).length > 0 ) { 570 571 $( '*:focus' ).closest( '.post-tree__item--active' ).each(function() { 572 573 // Close active submenu 574 $(this).removeClass( 'post-tree__item--active' ); 575 $(this).find( '> .post-tree__children' ).hide(); 576 $(this).find( '> .post-tree__item-toggle' ).removeClass( 'post-tree__item-toggle--active' ); 577 $(this).find( '> .post-tree__item-toggle' ).attr( 'aria-label', expandSubmenuLabel ); 578 $(this).find( '> .post-tree__item-toggle' ).attr( 'aria-expanded', false ); 579 $(this).find( '> .post-tree__children' ).attr( 'aria-expanded', false ); 580 581 // Change focus 582 $(this).find( '> .post-tree__item-toggle' ).focus(); 583 584 }); 585 586 } 587 588 // Otherwise hide all submenus 589 else { 590 591 $( '.post-tree__item' ).each(function() { 592 593 $(this).removeClass( 'header-post-tree__item--active' ); 594 $(this).find( '> .post-tree__children' ).hide(); 595 $(this).find( '> .post-tree__item-toggle' ).removeClass( 'post-tree__item-toggle--active' ); 596 $(this).find( '> .post-tree__item-toggle' ).attr( 'aria-label', expandSubmenuLabel ); 597 $(this).find( '> .post-tree__item-toggle' ).attr( 'aria-expanded', false ); 598 $(this).find( '> .post-tree__children' ).attr( 'aria-expanded', false ); 599 600 }); 601 602 } 603 604 } 605 606 }); 607 608 // Reset on screen transition 609 $(document).on( 'lsvrTownpressScreenTransition', function() { 610 611 $( '.post-tree__children' ).removeAttr( 'style' ); 612 $( '.post-tree__item-toggle' ).removeClass( 'post-tree__item-toggle--active' ).attr( 'aria-label', expandSubmenuLabel ).attr( 'aria-expanded', false ); 613 $( '.post-tree__children' ).attr( 'aria-expanded', false ); 614 615 }); 616 617 }); 618 619 620/* ----------------------------------------------------------------------------- 621 622 5. WIDGETS 623 624----------------------------------------------------------------------------- */ 625 626 /* ------------------------------------------------------------------------- 627 MENU WIDGET 628 ------------------------------------------------------------------------- */ 629 630 $( '.lsvr-townpress-menu-widget__nav' ).each(function() { 631 632 var $this = $(this), 633 expandPopupLabel = $(this).data( 'label-expand-submenu' ), 634 collapsePopupLabel = $(this).data( 'label-collapse-submenu' ); 635 636 // Hide desktop all submenus function 637 function resetMenu() { 638 $this.find( '.lsvr-townpress-menu-widget__item' ).removeClass( 'lsvr-townpress-menu-widget__item--hover lsvr-townpress-menu-widget__item--active' ); 639 $this.find( '.lsvr-townpress-menu-widget__item-link' ).attr( 'aria-expanded', false ); 640 $this.find( '.lsvr-townpress-menu-widget__submenu' ).removeAttr( 'style' ).attr( 'aria-expanded', false ); 641 $this.find( '.lsvr-townpress-menu-widget__submenu-toggle' ).removeClass( 'lsvr-townpress-menu-widget__submenu-toggle--active' ).attr( 'title', expandPopupLabel ).attr( 'aria-expanded', false ); 642 } 643 644 // Reset menu when click on link without submenu 645 $this.find( '.lsvr-townpress-menu-widget__item-link' ).each(function() { 646 $(this).on( 'click', function() { 647 if ( $(this).parent().find( '> .lsvr-townpress-menu-widget__submenu' ).length < 1 ) { 648 resetMenu(); 649 } 650 }); 651 }); 652 653 $(this).find( '.lsvr-townpress-menu-widget__submenu--level-0, .lsvr-townpress-menu-widget__submenu--level-1' ).not( ':visible' ).each(function() { 654 655 var $submenu = $(this), 656 $parent = $(this).parent(), 657 $link = $parent.find( '> .lsvr-townpress-menu-widget__item-link' ), 658 $toggle = $parent.find( '> .lsvr-townpress-menu-widget__toggle' ); 659 660 // Show submenu function 661 function showSubmenu() { 662 $parent.addClass( 'lsvr-townpress-menu-widget__item--hover lsvr-townpress-menu-widget__item--active' ); 663 $submenu.show(); 664 $link.attr( 'aria-expanded', true ); 665 $submenu.attr( 'aria-expanded', true ); 666 } 667 668 // Hide submenu function 669 function hideSubmenu() { 670 $parent.removeClass( 'lsvr-townpress-menu-widget__item--hover lsvr-townpress-menu-widget__item--active' ); 671 $submenu.hide(); 672 $link.attr( 'aria-expanded', false ); 673 $submenu.attr( 'aria-expanded', false ); 674 } 675 676 // Desktop hover and touch 677 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() > 991 ) { 678 679 // Mouseover and focus action 680 $parent.on( 'mouseover focus', function() { 681 showSubmenu(); 682 }); 683 684 // Mouseleave and blur action 685 $parent.on( 'mouseleave blur', function() { 686 hideSubmenu(); 687 }); 688 689 // Touch 690 $link.on( 'click', function() { 691 if ( ! $parent.hasClass( 'lsvr-townpress-menu-widget__item--hover' ) ) { 692 693 // Hide opened submenus 694 $parent.siblings( '.lsvr-townpress-menu-widget__item--hover' ).each(function() { 695 $(this).removeClass( 'lsvr-townpress-menu-widget__item--hover' ); 696 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).hide(); 697 $(this).find( '> .lsvr-townpress-menu-widget__item-link' ).attr( 'aria-expanded', false ); 698 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).attr( 'aria-expanded', false ); 699 }); 700 701 // Show subemnu 702 showSubmenu(); 703 704 // Hide on click outside 705 $( 'html' ).on( 'click.lsvrTownpressMenuWidgetCloseSubmenuOnClickOutside', function(e) { 706 707 hideSubmenu(); 708 $( 'html' ).unbind( 'click.lsvrTownpressMenuWidgetCloseSubmenuOnClickOutside' ); 709 710 }); 711 712 // Disable link 713 $parent.on( 'click touchstart', function(e) { 714 e.stopPropagation(); 715 }); 716 return false;
717 718 } 719 hideSubmenu(); 720 }); 721 722 } 723 724 // Toggle 725 $toggle.on( 'click', function() { 726 727 $toggle.toggleClass( 'lsvr-townpress-menu-widget__toggle--active' ); 728 $parent.toggleClass( 'lsvr-townpress-menu-widget__item--active' ); 729 $submenu.slideToggle( 200 ); 730 731 if ( $toggle.hasClass( 'lsvr-townpress-menu-widget__toggle--active' ) ) { 732 733 $toggle.attr( 'aria-label', collapsePopupLabel ); 734 $toggle.attr( 'aria-expanded', true ); 735 $submenu.attr( 'aria-expanded', true ); 736 737 } else { 738 739 $toggle.attr( 'aria-label', expandPopupLabel ); 740 $toggle.attr( 'aria-expanded', false ); 741 $submenu.attr( 'aria-expanded', false ); 742 743 } 744 745 }); 746 747 }); 748 749 // Close submenu on ESC key 750 $(document).on( 'keyup.lsvrTownpressMenuWidgetCloseSubmenuOnEscKey', function(e) { 751 752 if ( e.key === "Escape" ) { 753 754 // Find focused link parent 755 if ( $( '*:focus' ).closest( '.lsvr-townpress-menu-widget__item--active' ).length > 0 ) { 756 757 $( '*:focus' ).closest( '.lsvr-townpress-menu-widget__item--active' ).each(function() { 758 759 // Close active submenu 760 $(this).removeClass( 'lsvr-townpress-menu-widget__item--hover lsvr-townpress-menu-widget__item--active' ); 761 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).hide(); 762 $(this).find( '> .lsvr-townpress-menu-widget__item-link' ).attr( 'aria-expanded', false ); 763 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).attr( 'aria-expanded', false ); 764 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).removeClass( 'lsvr-townpress-menu-widget__toggle--active lsvr-townpress-menu-widget__toggle--hover' ); 765 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).attr( 'aria-label', expandPopupLabel ); 766 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).attr( 'aria-expanded', false ); 767 768 // Change focus 769 $(this).find( '> .lsvr-townpress-menu-widget__item-link' ).focus(); 770 771 }); 772 773 } 774 775 // Otherwise hide all submenus 776 else { 777 778 $( '.lsvr-townpress-menu-widget__item--active' ).each(function() { 779 780 $(this).removeClass( 'lsvr-townpress-menu-widget__item--active lsvr-townpress-menu-widget__item--hover' ); 781 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).hide(); 782 $(this).find( '> .lsvr-townpress-menu-widget__item-link' ).attr( 'aria-expanded', false ); 783 $(this).find( '> .lsvr-townpress-menu-widget__submenu' ).attr( 'aria-expanded', false ); 784 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).removeClass( 'lsvr-townpress-menu-widget__toggle--active lsvr-townpress-menu-widget__toggle--hover' ); 785 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).attr( 'aria-label', expandPopupLabel ); 786 $(this).find( '> .lsvr-townpress-menu-widget__toggle' ).attr( 'aria-expanded', false ); 787 788 }); 789 790 } 791 792 } 793 794 }); 795 796 // Reset on screen transition 797 $(document).on( 'lsvrTownpressScreenTransition', function() { 798 resetMenu(); 799 }); 800 801 }); 802 803 804 805/* ----------------------------------------------------------------------------- 806 807 6. ELEMENTS 808 809----------------------------------------------------------------------------- */ 810 811 /* ------------------------------------------------------------------------- 812 POST SLIDER 813 -------------------------------------------------------------------------- */ 814 815 if ( $.fn.owlCarousel ) { 816 $( '.lsvr-townpress-post-slider' ).each( function() { 817 818 var $this = $(this), 819 $sliderInner = $this.find( '.lsvr-townpress-post-slider__inner' ), 820 $slideList = $this.find( '.lsvr-townpress-post-slider__list' ), 821 $slides = $this.find( '.lsvr-townpress-post-slider__post' ), 822 $indicator = $this.find( '.lsvr-townpress-post-slider__indicator-inner' ), 823 slideCount = $slides.length, 824 autoplay = $this.data( 'autoplay' ) && parseInt( $this.data( 'autoplay' ) ) > 0 ? true : false, 825 autoplayTimeout = $this.data( 'autoplay' ) && parseInt( $this.data( 'autoplay' ) ) > 0 ? parseInt( $this.data( 'autoplay' ) ) * 1000 : 0, 826 rtl = $( 'html' ).attr( 'dir' ) && $( 'html' ).attr( 'dir' ) == 'rtl' ? true : false; 827 828 if ( slideCount > 1 ) { 829 830 // Init carousel
831 $slideList.owlCarousel({ 832 rtl: rtl, 833 autoHeight: true, 834 loop: true, 835 nav: true, 836 navText: new Array( '<span class="lsvr-townpress-post-slider__indicator-icon lsvr-townpress-post-slider__indicator-icon--left icon-angle-left" aria-hidden="true"></span>', '<span class="lsvr-townpress-post-slider__indicator-icon lsvr-townpress-post-slider__indicator-icon--right icon-angle-right" aria-hidden="true"></span>' ), 837 navRewind: true, 838 dots: false, 839 autoplay: autoplay, 840 autoplayTimeout: autoplayTimeout, 841 autoplayHoverPause: true, 842 responsive:{ 843 0: { 844 items: 1 845 } 846 }, 847 onTranslated: function() { 848 849 // Refresh indicator 850 if ( autoplay ) { 851 $indicator.stop( 0, 0 ); 852 } 853 if ( autoplay && $.fn.lsvrTownpressGetMediaQueryBreakpoint() > 991 ) { 854 $indicator.css( 'width', 0 ); 855 if ( ! $this.hasClass( 'lsvr-townpress-post-slider--paused' ) ) { 856 $indicator.stop( 0, 0 ).animate({ width : "100%" }, autoplayTimeout ); 857 } 858 } 859 860 } 861 }); 862 863 // Autoplay indicator 864 if ( true === autoplay ) { 865 866 $this.addClass( 'lsvr-townpress-post-slider--has-indicator' ); 867 868 // Initial animation 869 $indicator.animate({ 870 width : "100%" 871 }, autoplayTimeout, 'linear' ); 872 873 // Pause 874 var sliderPause = function() { 875 $this.addClass( 'lsvr-townpress-post-slider--paused' ); 876 $indicator.stop( 0, 0 ); 877 }; 878 var sliderResume = function() { 879 $this.removeClass( 'lsvr-townpress-post-slider--paused' ); 880 $indicator.stop( 0, 0 ).animate({ 881 width : "100%" 882 }, autoplayTimeout, 'linear' ); 883 }; 884 885 $this.on( 'mouseenter', function() { 886 sliderPause(); 887 }); 888 889 $this.on( 'mouseleave', function() { 890 sliderResume(); 891 }); 892 893 // Stop on smaller resolutions 894 $( document ).on( 'lsvrTownpressScreenTransition', function() { 895 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() <= 991 ) { 896 sliderPause(); 897 } 898 }); 899 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() <= 991 ) { 900 sliderPause(); 901 } 902 903 } 904 905 } 906 907 }); 908 } 909 910 911/* ----------------------------------------------------------------------------- 912 913 7. OTHER 914 915----------------------------------------------------------------------------- */ 916 917 /* ------------------------------------------------------------------------- 918 BACK TO TOP 919 ------------------------------------------------------------------------- */ 920 921 $( '.back-to-top__link' ).each(function() { 922 923 $(this).on( 'click', function() { 924 $( 'html, body' ).animate({ scrollTop: 0 }, 100 ); 925 return false; 926 }); 927 928 }); 929 930 /* ------------------------------------------------------------------------- 931 MAGNIFIC POPUP 932 ------------------------------------------------------------------------- */ 933 934 if ( $.fn.magnificPopup ) { 935 936 // Lightbox config 937 if ( 'undefined' !== typeof lsvr_townpress_js_labels && lsvr_townpress_js_labels.hasOwnProperty( 'magnific_popup' ) ) { 938 939 var js_strings = lsvr_townpress_js_labels.magnific_popup; 940 $.extend( true, $.magnificPopup.defaults, { 941 tClose: js_strings.mp_tClose, 942 tLoading: js_strings.mp_tLoading, 943 gallery: { 944 tPrev: js_strings.mp_tPrev, 945 tNext: js_strings.mp_tNext, 946 tCounter: '%curr% / %total%' 947 }, 948 image: { 949 tError: js_strings.mp_image_tError, 950 }, 951 ajax: { 952 tError: js_strings.mp_ajax_tError, 953 } 954 }); 955 956 } 957 958 // Init lightbox 959 $( '.lsvr-open-in-lightbox, body:not( .elementor-page ) .gallery .gallery-item a, .wp-block-gallery .blocks-gallery-item a' ).magnificPopup({ 960 type: 'image', 961 removalDelay: 300, 962 mainClass: 'mfp-fade', 963 gallery: { 964 enabled: true 965 } 966 }); 967 968 } 969 970}); 971})(jQuery); 972 973(function($){ "use strict"; 974 975/* ----------------------------------------------------------------------------- 976 977 8. PLUGINS 978 979----------------------------------------------------------------------------- */ 980 981 /* ------------------------------------------------------------------------- 982 MEDIA QUERY BREAKPOINT 983 ------------------------------------------------------------------------- */ 984 985 if ( ! $.fn.lsvrTownpressGetMediaQueryBreakpoint ) { 986 $.fn.lsvrTownpressGetMediaQueryBreakpoint = function() { 987 988 if ( $( '#lsvr-media-query-breakpoint' ).length < 1 ) { 989 $( 'body' ).append( '<span id="lsvr-media-query-breakpoint" style="display: none;"></span>' ); 990 } 991 var value = $( '#lsvr-media-query-breakpoint' ).css( 'font-family' ); 992 if ( typeof value !== 'undefined' ) { 993 value = value.replace( "\"", "" ).replace( "\"", "" ).replace( "\'", "" ).replace( "\'", "" ); 994 } 995 if ( isNaN( value ) ) { 996 return $( window ).width(); 997 } 998 else { 999 return parseInt( value ); 1000 } 1001 1002 }; 1003 } 1004 1005 var lsvrTownpressMediaQueryBreakpoint; 1006 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint ) { 1007 lsvrTownpressMediaQueryBreakpoint = $.fn.lsvrTownpressGetMediaQueryBreakpoint(); 1008 $(window).on( 'resize', function(){ 1009 if ( $.fn.lsvrTownpressGetMediaQueryBreakpoint() !== lsvrTownpressMediaQueryBreakpoint ) { 1010 lsvrTownpressMediaQueryBreakpoint = $.fn.lsvrTownpressGetMediaQueryBreakpoint(); 1011 $.event.trigger({ 1012 type: 'lsvrTownpressScreenTransition', 1013 message: 'Screen transition completed.', 1014 time: new Date() 1015 }); 1016 } 1017 }); 1018 } 1019 else { 1020 lsvrTownpressMediaQueryBreakpoint = $(document).width(); 1021 } 1022 1023 /* ------------------------------------------------------------------------- 1024 LEAFLET MAP 1025 -------------------------------------------------------------------------- */ 1026 1027 if ( ! $.fn.lsvrTownpressMapLeaflet ) { 1028 $.fn.lsvrTownpressMapLeaflet = function() { 1029 1030 // Prepare params 1031 var $this = $(this), 1032 mapProvider = $this.data( 'map-provider' ) ? $this.data( 'map-provider' ) : 'osm', 1033 zoom = $this.data( 'zoom' ) ? $this.data( 'zoom' ) : 17, 1034 enableMouseWheel = $this.data( 'mousewheel' ) && true === String( $this.data( 'mousewheel' ) ) ? true : false, 1035 elementId = $this.attr( 'id' ),
1036 address = $this.data( 'address' ) ? $this.data( 'address' ) : false, 1037 latLong = $this.data( 'latlong' ) ? $this.data( 'latlong' ) : false, 1038 latitude = false, longitude = false; 1039 1040 // Parse latitude and longitude 1041 if ( false !== latLong ) { 1042 var latLongArr = latLong.split( ',' ); 1043 if ( latLongArr.length == 2 ) { 1044 latitude = latLongArr[0].trim(); 1045 longitude = latLongArr[1].trim(); 1046 } 1047 } 1048 1049 // Proceed only if latitude and longitude were obtained 1050 if ( false !== latitude && false !== longitude ) { 1051 1052 // Prepare map options 1053 var mapOptions = { 1054 center : [ latitude, longitude ], 1055 zoom : zoom, 1056 scrollWheelZoom : enableMouseWheel, 1057 }; 1058 1059 // Init the map object 1060 var map = L.map( elementId, mapOptions ); 1061 $this.data( 'map', map ); 1062 1063 // Load tiles from Mapbox 1064 if ( 'mapbox' === mapProvider ) { 1065 1066 var apiKey = typeof lsvr_townpress_mapbox_api_key !== 'undefined' ? lsvr_townpress_mapbox_api_key : false; 1067 if ( false !== apiKey ) { 1068 1069 L.tileLayer( 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}
1069?access_token=' + apiKey, { 1070 attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', 1071 id: 'mapbox/streets-v11', 1072 tileSize: 512, 1073 zoomOffset: -1, 1074 accessToken: apiKey 1075 }).addTo( map ); 1076 1077 } 1078 1079 } 1080 1081 // Load tiles from Open Street Map 1082 else if ( 'osm' === mapProvider ) { 1083 1084 L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { 1085 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>', 1086 subdomains: ['a','b','c'] 1087 }).addTo( map ); 1088 1089 } 1090 1091 // Marker HTML 1092 var marker = L.divIcon({ 1093 iconAnchor : [15, 40], 1094 className : 'c-map__marker-wrapper', 1095 html : '<div class="c-map__marker"><div class="c-map__marker-inner"></div></div>' 1096 }); 1097 1098 // Add marker 1099 L.marker([ latitude, longitude ], { 1100 icon : marker 1101 }).addTo(map); 1102 1103 // Remove loading 1104 $this.removeClass( 'c-map__canvas--loading' ); 1105 $this.parent().find( '.c-spinner' ).fadeOut( 200, 1106 function() { 1107 $(this).remove(); 1108 } 1109 ); 1110 1111 } 1112 1113 // Otherwise hide the map 1114 else { 1115 $this.hide(); 1116 } 1117 1118 }; 1119 } 1120 1121 /* ------------------------------------------------------------------------- 1122 GOOGLE MAP 1123 -------------------------------------------------------------------------- */ 1124 1125 if ( ! $.fn.lsvrTownpressMapGmaps ) { 1126 $.fn.lsvrTownpressMapGmaps = function() { 1127 1128 // Prepare params 1129 var $this = $(this), 1130 mapType = $this.data( 'maptype' ) ? $this.data( 'maptype' ) : 'terrain', 1131 zoom = $this.data( 'zoom' ) ? $this.data( 'zoom' ) : 17, 1132 enableMouseWheel = $this.data( 'mousewheel' ) && true === String( $this.data( 'mousewheel' ) ) ? true : false, 1133 elementId = $this.attr( 'id' ), 1134 address = $this.data( 'address' ) ? $this.data( 'address' ) : false, 1135 latLong = $this.data( 'latlong' ) ? $this.data( 'latlong' ) : false, 1136 latitude = false, longitude = false; 1137 1138 // Parse latitude and longitude 1139 if ( false !== latLong ) { 1140 var latLongArr = latLong.split( ',' ); 1141 if ( latLongArr.length == 2 ) { 1142 latitude = latLongArr[0].trim(); 1143 longitude = latLongArr[1].trim(); 1144 } 1145 } 1146 1147 // Load Google Maps API 1148 if ( $.fn.lsvrTownpressLoadGoogleMapsApi ) { 1149 $.fn.lsvrTownpressLoadGoogleMapsApi(); 1150 } 1151 1152 // Set basic API settings 1153 var apiSetup = function() { 1154 1155 // Get map type 1156 switch ( mapType ) { 1157 case 'roadmap': 1158 mapType = google.maps.MapTypeId.ROADMAP; 1159 break; 1160 case 'satellite': 1161 mapType = google.maps.MapTypeId.SATELLITE; 1162 break; 1163 case 'hybrid': 1164 mapType = google.maps.MapTypeId.HYBRID; 1165 break; 1166 default: 1167 mapType = google.maps.MapTypeId.TERRAIN; 1168 } 1169 1170 // Prepare map options 1171 var mapOptions = { 1172 'zoom' : zoom, 1173 'mapTypeId' : mapType, 1174 'scrollwheel' : enableMouseWheel, 1175 }; 1176 1177 // Set custom styles 1178 if ( 'undefined' !== typeof lsvr_townpress_google_maps_style_json ) { 1179 mapOptions.styles = JSON.parse( lsvr_townpress_google_maps_style_json ); 1180 } 1181 else if ( 'undefined' !== typeof lsvr_townpress_google_maps_style ) { 1182 mapOptions.styles = lsvr_townpress_google_maps_style; 1183 } 1184 1185 // Init the map object 1186 var map = new google.maps.Map( document.getElementById( elementId ), 1187 mapOptions ); 1188 $this.data( 'map', map ); 1189 1190 // If latitude and longitude were obtained, center the map 1191 if ( false !== latitude && false !== longitude ) { 1192 var location = new google.maps.LatLng( latitude, longitude ); 1193 map.setCenter( location ); 1194 var marker = new google.maps.Marker({ 1195 position: location, 1196 map: map 1197 }); 1198 $this.removeClass( 'c-map__canvas--loading' ); 1199 $this.parent().find( '.c-spinner' ).fadeOut( 200, 1200 function() { 1201 $(this).remove(); 1202 } 1203 ); 1204 } 1205 1206 // Otherwise hide the map 1207 else { 1208 $this.hide(); 1209 } 1210 1211 }; 1212 1213 // Check if API is already loaded, if not, wait for trigger 1214 if ( 'object' === typeof google && 'object' === typeof google.maps ) { 1215 apiSetup(); 1216 } 1217 else { 1218 $( document ).on( 'lsvrTownpressGoogleMapsApiLoaded', function() { 1219 apiSetup(); 1220 }); 1221 } 1222 1223 }; 1224 } 1225 1226 /* ------------------------------------------------------------------------- 1227 LOAD GOOGLE MAPS API 1228 -------------------------------------------------------------------------- */ 1229 1230 if ( ! $.fn.lsvrTownpressLoadGoogleMapsApi ) { 1231 $.fn.lsvrTownpressLoadGoogleMapsApi = function() { 1232 1233 // Check if Google Maps API isn't already loaded 1234 if ( ! $( 'body' ).hasClass( 'lsvr-google-maps-api-loaded' ) ) { 1235 1236 // Check if Google Maps API object doesn't already exists 1237 if ( 'object' === typeof google && 'object' === typeof google.maps ) { 1238 $.fn.lsvrTownpressGoogleMapsApiLoaded(); 1239 } 1240 1241 // If there is not existing instance of Google Maps API, let's create it 1242 else if ( ! $( 'body' ).hasClass( 'lsvr-google-maps-api-being-loaded' ) ) { 1243 1244 $( 'body' ).addClass( 'lsvr-google-maps-api-being-loaded' ); 1245 1246 var script = document.createElement( 'script' ), 1247 apiKey = typeof lsvr_townpress_google_api_key !== 'undefined' ? lsvr_townpress_google_api_key : false, 1248 language = $( 'html' ).attr( 'lang' ) ? $( 'html' ).attr( 'lang' ) : 'en'; 1249 1250 // Parse language 1251 language = language.indexOf( '-' ) > 0 ? language.substring( 0, language.indexOf( '-' ) ) : language; 1252 1253 // Append the script 1254 if ( apiKey !== false ) { 1255 script.type = 'text/javascript';
1256 script.src = 'https://maps.googleapis.com/maps/api/js?language=' + encodeURIComponent( language ) + '&key=' + encodeURIComponent( apiKey ) + '&callback=jQuery.fn.lsvrTownpressGoogleMapsApiLoaded'; 1257 document.body.appendChild( script ); 1258 } 1259 1260 } 1261 1262 } 1263 1264 }; 1265 } 1266 1267 // Trigger event 1268 if ( ! $.fn.lsvrTownpressGoogleMapsApiLoaded ) { 1269 $.fn.lsvrTownpressGoogleMapsApiLoaded = function() { 1270 1271 // Make sure that Google Maps API object does exist 1272 if ( 'object' === typeof google && 'object' === typeof google.maps ) { 1273 1274 // Trigger the event 1275 $.event.trigger({ 1276 type: 'lsvrTownpressGoogleMapsApiLoaded', 1277 message: 'Google Maps API is ready.', 1278 time: new Date() 1279 }); 1280 1281 // Add class to BODY element 1282 $( 'body' ).removeClass( 'lsvr-google-maps-api-being-loaded' ); 1283 $( 'body' ).addClass( 'lsvr-google-maps-api-loaded' ); 1284 1285 } 1286 1287 }; 1288 } 1289 1290})(jQuery);
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.