1/* global window */ 2/* global document */ 3/* global jQuery */ 4/* global g1 */ 5/* global bimber_front_config */ 6/* global SuperGif */ 7/* global Waypoint */ 8/* global enquire */ 9/* global mashsb */ 10/* global auto_load_next_post_params */ 11/* global FB */ 12/* global mejs */ 13/* global ga */ 14/* global embedly */ 15/* global console */ 16 17/************* 18 * 19 * Init env 20 * 21 *************/ 22 23(function($) { 24 'use strict'; 25 26 var config = $.parseJSON(bimber_front_config); 27 28 // namespace 29 var g1 = { 30 'config': config 31 }; 32 33 g1.getWindowWidth = function () { 34 if (typeof window.innerWidth !== 'undefined') { 35 return window.innerWidth; 36 } 37 38 return $(window).width(); 39 }; 40 41 g1.isDesktopDevice = function () { 42 return g1.getWindowWidth() > g1.getDesktopBreakpoint(); 43 }; 44 45 g1.getDesktopBreakpoint = function () { 46 var desktopBreakPoint = $('#g1-breakpoint-desktop').css('min-width'); 47 48 if ( ! desktopBreakPoint ) { 49 return 9999; 50 } 51 52 desktopBreakPoint = parseInt( desktopBreakPoint, 10 ); 53 54 // not set explicitly via css 55 if (desktopBreakPoint === 0) { 56 return 9999; 57 } 58 59 return desktopBreakPoint; 60 }; 61 62 g1.isTouchDevice = function () { 63 return ('ontouchstart' in window) || navigator.msMaxTouchPoints; 64 }; 65 66 g1.isStickySupported = function () { 67 var prefixes = ['', '-webkit-', '-moz-', '-ms-']; 68 var block = document.createElement('div'); 69 var supported = false; 70 var i; 71 72 // Test for native support. 73 for (i = prefixes.length - 1; i >= 0; i--) { 74 try { 75 block.style.position = prefixes[i] + 'sticky'; 76 } 77 catch(e) {} 78 if (block.style.position !== '') { 79 supported = true; 80 } 81 } 82 83 return supported; 84 }; 85 86 g1.isRTL = function () { 87 return $('body').is('.rtl'); 88 }; 89 90 g1.log = function(data) { 91 if (window.bimberDebugMode && typeof console !== 'undefined') { 92 console.log(data); 93 } 94 }; 95 96 g1.createCookie = function (name,value,time) { 97 var expires; 98 99 if (time) { 100 var date = new Date(); 101 var ms = time; 102 103 if (typeof time === 'object') { 104 ms = time.value; 105 106 switch (time.type) { 107 case 'days': 108 ms = ms * 24 * 60 * 60 * 1000; 109 break; 110 } 111 } 112 113 date.setTime(date.getTime() + ms); 114 expires = '; expires=' + date.toGMTString(); 115 } 116 else { 117 expires = ''; 118 } 119 120 document.cookie = name + '=' + value + expires + '; path=/'; 121 }; 122 123 g1.readCookie = function (name) { 124 var nameEQ = name + '='; 125 var ca = document.cookie.split(';'); 126 127 for(var i = 0; i < ca.length; i += 1) { 128 var c = ca[i]; 129 while (c.charAt(0) === ' ') { 130 c = c.substring(1,c.length); 131 } 132 133 if (c.indexOf(nameEQ) === 0) { 134 return c.substring(nameEQ.length,c.length); 135 } 136 } 137 138 return null; 139 }; 140 141 g1.removeCookie = function (name) { 142 createCookie(name, '', -1); 143 }; 144 145 // expose to the world 146 window.g1 = g1; 147})(jQuery); 148 149/************* 150 * 151 * UI Helpers 152 * 153 ************/ 154 155(function ($) { 156 157 'use strict'; 158 159 g1.uiHelpers = function () { 160 if (g1.isTouchDevice()) { 161 $('body').removeClass( 'g1-hoverable' ); 162 } 163 164 // ----------------- 165 // Mailchimp widget. 166 // ----------------- 167 168 var mc4wpClasses = [ 169 'g1-box', 170 'g1-box-tpl-frame', 171 'g1-newsletter' 172 ]; 173 174 var mc4wpBackgroundClasses = [ 175 'g1-box-background' 176 ]; 177 178 if ('original-2018' === g1.config.stack || 'food' === g1.config.stack ) { 179 mc4wpBackgroundClasses.push('g1-current-background'); 180 } 181 182 if ( 'miami' === g1.config.stack || 'music' === g1.config.stack ) { 183 mc4wpClasses.push('g1-dark'); 184 } 185 186 $('.widget_mc4wp_form_widget'). 187 addClass(mc4wpClasses.join(' ')). 188 wrapInner('<div class="g1-box-inner"></div>'). 189 prepend('<div class="g1-box-icon"></div>').
190 append('<div class="' + mc4wpBackgroundClasses.join(' ') + '"></div>'); 191 192 193 194 // ----------- 195 // bbPress. 196 // ----------- 197 198 var bbPressBackgroundClasses = [ 199 'g1-box-background' 200 ]; 201 202 if ('original-2018' === g1.config.stack || 'food' === g1.config.stack ) { 203 bbPressBackgroundClasses.push('g1-current-background'); 204 } 205 206 $('.bbp_widget_login'). 207 addClass('g1-box g1-box-tpl-frame'). 208 wrapInner('<div class="g1-box-inner"></div>'). 209 append('<div class="' + bbPressBackgroundClasses.join(' ') + '"></div>'); 210 211 212 // ---------- 213 // Search UI. 214 // ---------- 215 216 $('.g1-drop-the-search').on('click', '.g1-drop-toggle', function (e) { 217 e.preventDefault(); 218 219 $('.g1-drop-the-search input.search-field').focus(); 220 }); 221 222 $('.search-submit').on('click', function(e){ 223 var $form = $(this).closest('form'); 224 var $input = $('input.search-field', $form); 225 if ( ! $input.val()){ 226 e.preventDefault(); 227 } 228 }); 229 230 $('#buddypress .load-more').click(function() { 231 var i = 0; 232 var intervalID = setInterval( function() { 233 $('body').trigger( 'g1PageHeightChanged' ); 234 i++; 235 if (i === 5){ 236 window.clearInterval(intervalID); 237 } 238 },1000); 239 }); 240 }; 241 242})(jQuery); 243 244/**************** 245 * 246 * Facebook SDK 247 * 248 ****************/ 249 250(function ($) { 251 252 'use strict'; 253 254 g1.resetFacebookSDK = function () { 255 $('script#facebook-jssdk').remove(); 256 $('#fb-root').remove(); 257 if (window.FB) { 258 delete window.FB; 259 } 260 }; 261 262 $('body').on( 'g1BeforeNewContentReady', function ( e, $newContent ) { 263 if ($newContent.find('.fb-video').length > 0) { 264 g1.resetFacebookSDK(); 265 } 266 } ); 267 268})(jQuery); 269 270 271 272/******************** 273 * 274 * Load More Button 275 * 276 ********************/ 277 278(function ($) { 279 280 'use strict'; 281 282 // prevent triggering the action more than once at the time 283 var loading = false; 284 var startingUrl = window.location.href; 285 var setTargetBlank = g1.config.setTargetBlank; 286 var useWaypoints = g1.config.useWaypoints; 287 288 g1.loadMoreButton = function () { 289 $('.g1-load-more').on('click', function (e) { 290 if (loading) { 291 return; 292 } 293 294 loading = true; 295 296 e.preventDefault(); 297 298 var $button = $(this); 299 var $collectionMore = $button.parents('.g1-collection-more'); 300 var url = $button.attr('data-g1-next-page-url'); 301 var $endMessage = $('.g1-pagination-end'); 302 303 $collectionMore.addClass('g1-collection-more-loading'); 304 305 // load page 306 var xhr = $.get(url); 307 308 // on success 309 xhr.done(function (data) { 310 var collectionSelector = '#primary > .g1-collection .g1-collection-items'; 311 312 // find elements in response 313 var $resCollectionItems = $(data).find(collectionSelector).find('.g1-collection-item'); 314 var $resButton = $(data).find('.g1-load-more'); 315 316 // find collection on page 317 var $collection = $(collectionSelector); 318 319 // add extra classes to new loaded items 320 $resCollectionItems.addClass('g1-collection-item-added'); 321 322 // If there are insta embeds BEFORE the load, we will force to refresh them AFTER the load 323 var $insta = $('script[src="//platform.instagram.com/en_US/embeds.js"]'); 324 325 // make sure that mejs is loaded 326 if (window.wp && typeof window.wp.mediaelement === 'undefined') { 327 var matches = data.match(/<script(.|\n)*?<\/script>/g); 328 var mejsCode = ''; 329 matches.forEach(function( match ) { 330 if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){ 331 match = match.replace('<script','<script async'); 332 mejsCode+=match; 333 } 334 }); 335 matches = data.match(/<link(.|\n)*?\/>/g);
336 matches.forEach(function( match ) { 337 if ( match.indexOf('mejs') > 0 || match.indexOf('mediaelement') > 0 ){ 338 mejsCode+=match; 339 } 340 }); 341 $collection.after(mejsCode); 342 } 343 if (setTargetBlank) { 344 $('a',$resCollectionItems).attr('target','_blank'); 345 } 346 347 var $collection_waypoint = '<span class="bimber-collection-waypoint" data-bimber-archive-url="' + url + '"></span>'; 348 $collection.append($collection_waypoint); 349 // add new elements to collection 350 $collection.append($resCollectionItems); 351 352 // Google Analytics. 353 if ( typeof ga !== 'undefined' && typeof ga.getAll !== 'undefined') { 354 ga('create', ga.getAll()[0].get('trackingId'), 'auto'); 355 ga('set', { location: url }); 356 ga('send', 'pageview'); 357 } 358 359 if ( $insta.length > 0) { 360 window.instgrm.Embeds.process(); 361 } 362 363 if (window.wp && typeof window.wp.mediaelement !== 'undefined') { 364 window.wp.mediaelement.initialize(); 365 } 366 367 // load all dependent functions 368 $('body').trigger( 'g1PageHeightChanged' ); 369 $('body').trigger( 'g1NewContentLoaded', [ $resCollectionItems ] ); 370 371 // update more button 372 if ($resButton.length > 0) { 373 $button.attr('data-g1-next-page-url', $resButton.attr('data-g1-next-page-url')); 374 } else { 375 $collectionMore.remove(); 376 } 377 378 //bind auto play video events 379 if (typeof g1.autoPlayVideo === 'function') { 380 g1.autoPlayVideo(); 381 } 382 383 if ( useWaypoints ){ 384 $('.bimber-collection-waypoint').waypoint(function(direction) { 385 var $waypoint = $(this.element); 386 if('up' === direction) { 387 var $waypointUp = $waypoint.prevAll('.bimber-collection-waypoint'); 388 if ($waypointUp.length > 0){ 389 $waypoint = $($waypointUp[0]); 390 } else { 391 window.history.replaceState( {} , '', startingUrl ); 392 return; 393 } 394 } 395 var waypointUrl = $waypoint.attr('data-bimber-archive-url'); 396 var currentUrl = window.location.href; 397 if ( waypointUrl !== currentUrl ){ 398 window.history.replaceState( {} , '', waypointUrl ); 399 } 400 }, { 401 offset: '-5%' 402 }); 403 } 404 }); 405 406 xhr.fail(function () { 407 $button.addClass('g1-info-error'); 408 $button.remove(); 409 $endMessage.show(); 410 }); 411 412 xhr.always(function () { 413 $collectionMore.removeClass('g1-collection-more-loading'); 414 loading = false; 415 }); 416 }); 417 }; 418 419})(jQuery); 420 421 422/******************* 423 * 424 * Infinite scroll 425 * 426 ******************/ 427 428(function ($) { 429 430 'use strict'; 431 432 g1.infiniteScrollConfig = { 433 'offset': '150%' 434 }; 435 436 var triggeredByClick = false; 437 438 g1.infiniteScroll = function () { 439 $('.g1-collection-more.infinite-scroll').each(function () { 440 var $this = $(this); 441 442 if ($this.is('.on-demand') && !triggeredByClick) { 443 return false; 444 } 445 446 $this.waypoint(function(direction) { 447 if('down' === direction) { 448 $this.find('.g1-load-more').trigger('click'); 449 } 450 }, { 451 // trigger when the "Load More" container is 10% under the browser window 452 offset: g1.infiniteScrollConfig.offset 453 }); 454 }); 455 }; 456 457 // wait for new content and apply infinite scroll events to it 458 $('body').on( 'g1NewContentLoaded', function () { 459 triggeredByClick = true; 460 g1.infiniteScroll(); 461 } ); 462 463})(jQuery); 464 465 466 467/******************* 468 * 469 * Date > Time ago 470 * 471 ******************/ 472 473(function ($) { 474 475 'use strict'; 476 477 g1.dateToTimeago = function () { 478 if (!$.fn.timeago) { 479 return; 480 } 481 482 $('time.entry-date, span.entry-date > time, .comment-metadata time, time.snax-item-date').timeago(); 483 484 $('body').on( 'g1NewContentLoaded', function ( e, $newContent ) { 485 if ($newContent) { 486 $newContent.find('time.entry-date, .comment-metadata time, time.snax-item-date').timeago(); 487 } 488 } ); 489 }; 490 491})(jQuery); 492 493 494/********** 495 * 496 * Canvas 497 * 498 *********/ 499 500(function($) { 501 'use strict'; 502 503 var selectors = { 504 'toggle': '.g1-hamburger' 505 }; 506 507 g1.globalCanvasSelectors = selectors; 508 509 var canvas; 510 511 g1.canvas = function() { 512 canvas = Canvas(); 513 514 // Allow global access. 515 g1.canvasInstance = canvas; 516 517 $(selectors.toggle).on('click', function (e) { 518 e.preventDefault(); 519 520 //$('html, body').animate({ // @maybe 521 // scrollTop: 0 // @maybe 522 //}, 10); // @maybe 523 524 canvas.toggle(); 525 }); 526 }; 527 528 function Canvas () { 529 var that = {}; 530 var listeners = { 531 'open': [], 532 'close': [] 533 }; 534 535 var currentContent = ''; 536 537 var currentScroll = 0; // @maybe 538 539 var _clientY; 540 541 var init = function () {
542 var $overlay = $( '.g1-canvas-overlay'); 543 544 // toogle canvas events 545 $overlay.on('click', that.toggle); 546 547 $('.g1-canvas').on('toggle-canvas', function () { 548 that.toggle(); 549 }); 550 551 $('.g1-canvas .g1-canvas-toggle').on('click', that.toggle); 552 553 554 if ( $('html.g1-off-outside').length ) { 555 enquire.register('screen and ( min-width: 700px )', { 556 match : function() { 557 that.close(); 558 } 559 }); 560 } 561 562 if ( $('html.g1-off-inside').length ) { 563 enquire.register('screen and ( max-width: 1024px )', { 564 match : function() { 565 that.close(); 566 } 567 }); 568 } 569 570 return that; 571 }; 572 573 that.getContent = function() { 574 return $('.g1-canvas-global .g1-canvas-content'); 575 }; 576 577 that.captureClientY = function (event) { 578 // only respond to a single touch 579 //if (event.targetTouches.length === 1) { 580 _clientY = event.targetTouches[0].clientY; 581 //} 582 }; 583 584 that.disableCanvasScroll = function( e ) { 585 // only respond to a single touch 586 //if (e.targetTouches.length !== 1) { 587 // return; 588 //} 589 590 var _element = $('.g1-canvas'); 591 592 var clientY = e.targetTouches[0].clientY - _clientY; 593 594 // The element at the top of its scroll, 595 // and the user scrolls down 596 if (_element.scrollTop === 0 && clientY > 0) { 597 598 alert('top scroll'); 599 600 e.preventDefault(); 601 e.stopPropagation(); 602 return false; 603 } 604 605 // The element at the bottom of its scroll, 606 // and the user scrolls up 607 // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions 608 if ((_element.scrollHeight - _element.scrollTop <= _element.clientHeight) && clientY < 0) { 609 alert('bottom scroll'); 610 611 e.preventDefault(); 612 e.stopPropagation(); 613 return false; 614 } 615 }; 616 617 that.disableBodyScroll = function( e ) { 618 //e.preventDefault(); 619 //e.stopPropagation(); 620 //return false; 621 }; 622 623 that.open = function (content) { 624 //$('.g1-canvas').on('touchstart', that.captureClientY); 625 //$('.g1-canvas').on('touchmove', that.disableCanvasScroll); 626 627 $('.g1-canvas-background[data-bg]:not(.lazyloaded)').addClass('lazyload'); 628 629 window.requestAnimationFrame(function () { 630 var breakpoint = $(document).width(); 631 var cssClass = breakpoint >= 1025 ? 'g1-off-global-desktop' : 'g1-off-global'; 632 $('html').addClass(cssClass); 633 634 currentContent = content; 635 var $canvas = $('.g1-canvas-global'); 636 637 if (content) { 638 if (typeof content === 'string') { 639 $canvas.find('.g1-canvas-content').html(content); 640 } else { 641 $canvas.find('.g1-canvas-content').empty().append(content); 642 } 643 644 // notify about adding new content to DOM so other elements can be reloaded 645 $canvas.find('.g1-canvas-content').trigger('g1-new-content'); 646 647 } 648 649 that.notify('open'); 650 }); 651 }; 652 653 that.close = function () { 654 //$('.g1-canvas').off('touchmove', that.disableCanvasScroll); 655 //$('.g1-canvas').off('touchstart', that.captureClientY); 656 657 window.requestAnimationFrame(function () { 658 $('html').removeClass('g1-off-global g1-off-global-desktop'); 659 660 that.notify('close'); 661 }); 662 }; 663 664 that.toggle = function (e) { 665 if (e) { 666 e.preventDefault(); 667 } 668 669 // is opened? 670 if ( $('html').is('.g1-off-global, .g1-off-global-desktop') ) { 671 that.close(); 672 } else { 673 that.open(null); 674 } 675 }; 676 677 that.notify = function (eventType) { 678 var callbacks = listeners[eventType]; 679 680 for (var i = 0; i < callbacks.length; i++) { 681 callbacks[i](that.getContent()); 682 } 683 }; 684 685 that.on = function (eventType, listener, priority) { 686 listeners[eventType][priority] = listener; 687 }; 688 689 return init(); 690 } 691 692})(jQuery); 693 694 695/******************** 696 * 697 * Sticky sidebar 698 * 699 ********************/ 700 701(function($) { 702 'use strict'; 703 704 var $waypointElem = false;
705 706 var selectors = { 707 'stickyWidgetWrapper': '.g1-sticky-widget-wrapper', 708 'stickyWidget': '.g1-sticky-widget', 709 'widget': '.widget', 710 'content': '#primary .entry-content' 711 }; 712 713 var sidebarSelectors = [ 714 '#secondary', 715 '#tertiary' 716 ]; 717 718 g1.stickyTopOffsetSelectors = [ 719 '#wpadminbar', 720 '.g1-iframe-bar', 721 '.g1-sharebar-loaded', 722 '.g1-sticky-top-wrapper' 723 ]; 724 725 g1.resetStickyElements = function() { 726 $(selectors.stickyWidgetWrapper).css('height', ''); 727 $(selectors.stickyWidget).css('position', 'block'); 728 }; 729 730 g1.stickySidebar = function() { 731 if (!g1.isDesktopDevice()) { 732 g1.resetStickyElements(); 733 return; 734 } 735 736 var $widgets = $(selectors.stickyWidget); 737 738 if ($widgets.length === 0) { 739 return; 740 } 741 742 // Calc top offset for sticky elements. 743 var topOffset = 0; 744 745 $(g1.stickyTopOffsetSelectors).each(function() { 746 var $element = $(this); 747 748 if ($element.length > 0 && $element.is(':visible')) { 749 topOffset += parseInt($element.outerHeight(), 10); 750 } 751 }); 752 753 // Adjust widgets top offset to keep them always fully visible. 754 $widgets.each(function() { 755 var $widget = $(this); 756 var top = parseInt($widget.css('top'), 10); 757 758 if (topOffset > 0) { 759 top += topOffset; 760 761 $widget.css('top', top + 'px'); 762 } 763 }); 764 765 // Apply "position: sticky" pollyfill (IE9+). 766 if (typeof Stickyfill !== 'undefined') { 767 Stickyfill.add($widgets); 768 } 769 770 /** 771 * Increase the last widget height to cover entire sidebar. 772 * 773 * @param {Boolean} isVariableContent - Determines which element is used for widget height calculation. 774 */ 775 var adjustLastWidgetHeight = function(isVariableContent) { 776 $(sidebarSelectors).each(function() { 777 var $sidebar = $(this); 778 var $widgets = $sidebar.children(selectors.widget + ',' + selectors.stickyWidgetWrapper); 779 var $lastWidget = $widgets.last(); 780 781 if ($lastWidget.is(selectors.stickyWidgetWrapper)) { 782 // Reset height (if previously set) to calculate it from scratch. 783 $lastWidget.css('height', ''); 784 785 var sidebarHeight; 786 787 // Lazy loaded dynamic content elements (like embeds) affects its height. 788 // At this point, we don't know what will be the final height. 789 // So when we calculate the first time the last widget height, we do this based on current content height, 790 // and then when we reach the end of the content, we recalculate (assuming that all elements 791 // have already thier final size) the widget height based on current sidebar height (flexbox gives us a certainty 792 // that both #primary and #secondary/#tetriary elements have the same height). 793 if (isVariableContent) { 794 sidebarHeight = parseInt($(selectors.content).outerHeight(), 10); 795 } else { 796 sidebarHeight = parseInt($sidebar.outerHeight(), 10); 797 } 798 799 var widgetsHeight = 0; 800 801 $widgets.each(function() { 802 widgetsHeight += parseInt($(this).outerHeight(true), 10); 803 }); 804 805 // Increase last widget height if exists a space to cover. 806 if (widgetsHeight < sidebarHeight) { 807 var diffHeight = sidebarHeight - widgetsHeight; 808 809 var lastWidgetHeight = parseInt($lastWidget.css('height'), 10); 810 811 lastWidgetHeight += diffHeight; 812 813 $lastWidget.css('height', lastWidgetHeight + 'px'); 814 } 815 816 $waypointElem = $lastWidget; 817 } 818 }); 819 }; 820 821 var $body = $('body'); 822 823 // For a single post, use entry content height to calculate the last widget height at first. 824 var isVariableContent = $body.is('.single'); 825 826 adjustLastWidgetHeight(isVariableContent); 827 828 // Listen to page height changes. 829 // ------------------------------ 830 831 // New content is added (e.g. via auto-load next post) or dynamic element is fully loaded (e.g. Facebook widget). 832 $body.on( 'g1NewContentLoaded g1PageHeightChanged', function(e) { 833 adjustLastWidgetHeight(); 834 } ); 835 836 // Entry content is entirely in the viewport (all inside elements should have final size), adjust widget height. 837 if (false !== $waypointElem) { 838 $waypointElem.waypoint(function(direction) { 839 if ('down' === direction) { 840 adjustLastWidgetHeight(); 841 } 842 }, { 843 // When the bottom of the element hits the bottom of the viewport. 844 offset: 'bottom-in-view' 845 }); 846 } 847 }; 848 849})(jQuery); 850 851 852/***************** 853 * 854 * Sticky Elements 855 * 856 ****************/ 857 858(function ($) { 859 860 'use strict'; 861 862 var selectors = [ 863 '#wpadminbar', 864 '.g1-iframe-bar', 865 '.g1-sharebar-loaded', 866 '.g1-sticky-top-wrapper' 867 ]; 868 869 // Accessible globally. 870 g1.stickyElementsTopOffsetSelectors = selectors; 871 872 g1.stickyPosition = function ($context) { 873 $context = $context || $('body'); 874 875 // Sticky top. 876 var $stickyTop = $('.g1-sticky-top-wrapper'); 877 878 // If exists and not loaded already. 879 if ($stickyTop.length > 0 && !$stickyTop.is('.g1-loaded')) { 880 var disableStickyHeader = false;
881 var isDesktop = g1.getWindowWidth() > 800; 882 883 884 885 // Disable if sharebar enabled. 886 var sharebarLoaded = $('.g1-sharebar-loaded').length > 0 || $('.essb_topbar').length > 0; 887 888 if (sharebarLoaded && isDesktop) { 889 disableStickyHeader = true; 890 } 891 892 if (disableStickyHeader) { 893 // Prevent native sticky support, like on FF. 894 $stickyTop.removeClass('g1-sticky-top-wrapper'); 895 } else { 896 // Apply pollyfill only if not supported. 897 if (!g1.isStickySupported()) { 898 Stickyfill.add($stickyTop); 899 } 900 901 $stickyTop.addClass('g1-loaded'); 902 } 903 } 904 905 // Calculate topOffset after disabling the sticky header! 906 var topOffset = 0; 907 for (var i = 0; i < selectors.length; i++) { 908 var $elem = $(selectors[i]); 909 910 if ($elem.length > 0 && $elem.is(':visible')) { 911 topOffset += $elem.outerHeight(); 912 } 913 } 914 915 916 // Sticky Item Actions (shares, votes etc). 917 $context.find('.g1-wrapper-with-stickies > .entry-actions').each(function() { 918 var $this = $(this); 919 920 $this.css('top', topOffset); 921 922 Stickyfill.add($this); 923 }); 924 925 // Sticky snax form sidebar. 926 Stickyfill.add($('.snax-form-frontend .snax-form-side')); 927 928 929 // Sticky Item Actions (shares, votes etc). 930 $context.find('.entry-tpl-index-stickies > .entry-actions, .entry-tpl-feat-stickies .entry-actions').each(function() { 931 var $this = $(this); 932 933 $this.css('top', topOffset + 10); 934 935 Stickyfill.add($this); 936 }); 937 }; 938 939 $('body').on( 'g1NewContentLoaded', function ( e, $newContent ) { 940 if ($newContent) { 941 g1.stickyPosition($newContent); 942 } 943 } ); 944 945})(jQuery); 946 947 948/********************** 949 * 950 * Droppable Elements 951 * 952 **********************/ 953 954(function ($) { 955 956 'use strict'; 957 958 var selectors = { 959 'drop' : '.g1-drop', 960 'dropExpanded': '.g1-drop-expanded', 961 'dropToggle': '.g1-drop-toggle' 962 }; 963 964 var classes = { 965 'dropExpanded': 'g1-drop-expanded' 966 }; 967 968 g1.droppableElements = function () { 969 // Hide drop on focus out. 970 $('body').on('click touchstart', function (e) { 971 var $activeDrop = $(e.target).parents('.g1-drop-expanded'); 972 973 // Collapse all except active. 974 $(selectors.dropExpanded).not($activeDrop).removeClass(classes.dropExpanded); 975 }); 976 977 // Handle drop state (expanded | collapsed). 978 979 // For touch devices we need to toggle CSS class to trigger state change. 980 if ( g1.isTouchDevice() ) { 981 $('body').on( 'click', selectors.drop, function(e) { 982 var $drop = $(this); 983 984 // Drop is expanded, collapse it on toggle click. 985 if ($drop.is(selectors.dropExpanded)) { 986 var $clickedElement = $(e.target); 987 988 var toggleClicked = $clickedElement.parents(selectors.dropToggle).length > 0; 989 990 if (toggleClicked) { 991 $drop.removeClass(classes.dropExpanded); 992 e.preventDefault(); 993 } 994 // Drop is collapsed, expand it. 995 } else {
996 $drop.addClass(classes.dropExpanded); 997 e.preventDefault(); 998 } 999 } ); 1000 // Devices without touch events, state is handled via CSS :hover 1001 } else { 1002 // Prevent click on toggle. 1003 $(selectors.dropToggle).on( 'click', function() { 1004 }); 1005 } 1006 }; 1007 1008})(jQuery); 1009 1010 1011/******************* 1012 * 1013 * Snax Integration 1014 * 1015 ******************/ 1016 1017(function ($) { 1018 1019 'use strict'; 1020 1021 g1.snax = function () { 1022 var $body = $('body'); 1023 1024 $body.on('snaxFullFormLoaded', function(e, $post) { 1025 $post.find('.g1-button-m.g1-button-solid').removeClass('g1-button-m g1-button-solid').addClass('g1-button-s g1-button-simple'); 1026 $post.find('.g1-beta.g1-beta-1st').removeClass('g1-beta g1-beta-1st').addClass('g1-gamma g1-gamma-1st'); 1027 }); 1028 }; 1029 1030})(jQuery); 1031 1032/******************* 1033 * 1034 * Media Ace Integration 1035 * 1036 ******************/ 1037 1038(function ($) { 1039 1040 'use strict'; 1041 1042 g1.mediaAce = function () { 1043 1044 $('body').on('g1NewContentLoaded', function() { 1045 $('body').trigger('maceLoadYoutube'); 1046 }); 1047 1048 $(document).on('lazybeforeunveil', function(e) { 1049 var $target = $(e.target); 1050 var targetSrc = $target.attr('data-src'); 1051 1052 if (targetSrc && targetSrc.endsWith('.gif')) { 1053 // Wait till image fully loaded. 1054 $target.on('load', function() { 1055 $target.addClass('g1-enable-gif-player'); 1056 1057 // Wait a while before applying player. 1058 setTimeout(function() { 1059 if (typeof g1.gifPlayer === 'function') { 1060 g1.gifPlayer($target.parent()); 1061 } 1062 }, 100); 1063 }); 1064 } 1065 }); 1066 1067 $(document).on('bimberGifPlayerLoaded', function(e, $canvasWrapper) { 1068 if ($canvasWrapper.hasClass('lazyloading')) { 1069 $canvasWrapper.removeClass('lazyloading'); 1070 $canvasWrapper.addClass('lazyloaded'); 1071 } 1072 }); 1073 }; 1074 1075})(jQuery); 1076 1077 1078/******* 1079 * 1080 * Menu 1081 * 1082 *******/ 1083(function (context, $, i18n) { 1084 1085 'use strict'; 1086 1087 $(document).ready(function () { 1088 PrimaryMenu(); 1089 }); 1090 1091 function PrimaryMenu () { 1092 var that = {}; 1093 1094 that.init = function () { 1095 that.registerEventsHandlers(); 1096 1097 // add toggle to menu 1098 $('.menu-item-has-children > a, .menu-item-g1-mega > a').append( '<span class="g1-link-toggle"></span>' ); 1099 1100 return that; 1101 }; 1102 1103 that.registerEventsHandlers = function () { 1104 that.handleMenuItemClick(); 1105 that.handleMenuItemFocusOut(); 1106 }; 1107 1108 that.handleMenuItemFocusOut = function () { 1109 $('body').on('click', function (e) { 1110 if ($(e.target).parents('.mtm-drop-expanded').length === 0 ) { 1111 1112 // Only horizontal menus. 1113 if ($(e.target).parents('.g1-menu-h').length ) { 1114 that.collapseAllOpenedSubmenus(); 1115 } 1116 } 1117 }); 1118 }; 1119 1120 that.handleMenuItemClick = function () { 1121 $('.g1-primary-nav, .g1-secondary-nav').on('click', '.menu-item > a', function (e) { 1122 var $menu = $(this).parents('.g1-primary-nav'); 1123 1124 if ($menu.length === 0) { 1125 $menu = $(this).parents('.g1-secondary-nav'); 1126 } 1127 1128 var isSimpleList = $menu.is('#g1-canvas-primary-nav') || $menu.is('#g1-canvas-secondary-nav'); 1129 1130 if (g1.isTouchDevice() || isSimpleList) { 1131 that.handleMenuTouchEvent($(this), e); 1132 } 1133 }); 1134 }; 1135 1136 that.handleMenuTouchEvent = function ($link, event) { 1137 var $li = $link.parent('li'); 1138 1139 that.collapseAllOpenedSubmenus($li); 1140 1141 if ($li.hasClass('menu-item-has-children')) { 1142 event.preventDefault(); 1143 1144 var $helper = $li.find('ul.sub-menu:first > li.g1-menu-item-helper'); 1145 1146 if ($helper.length === 0) { 1147 var href = $link.attr('href'); 1148 1149 if ( href && href.length ) { 1150 var anchor = i18n.go_to + ' <span class="mtm-item-helper-title">'+ $link.html() +'</span>'; 1151 1152 $helper = $('<li class="menu-item g1-menu-item-helper"><a class="mtm-link" href="'+ href +'"><span class="mtm-link-text"><span class="mtm-link-title">' + anchor +'</span></span></a></li>'); 1153 1154 $li.find('ul.sub-menu:first').prepend($helper); 1155 } 1156 } 1157 1158 if (!$li.is('.mtm-drop-expanded')) { 1159 $li.find('.mtm-drop-expanded .g1-menu-item-helper').remove(); 1160 $li.addClass('mtm-drop-expanded'); 1161 } else { 1162 $li.find('.mtm-drop-expanded').removeClass('mtm-drop-expanded'); 1163 $li.removeClass('mtm-drop-expanded'); 1164 } 1165 } 1166 }; 1167 1168 that.collapseAllOpenedSubmenus = function ($currentItem) { 1169 if ($currentItem) { 1170 var $currentMenu = $currentItem.parents('nav'); 1171 var $topLevelLi = $currentItem.parents('li.menu-item'); 1172 1173 // We are at top level of menu 1174 if($topLevelLi.length === 0) { 1175 // Collapse all, except current. 1176 // This will collapse current item subtree items but not item itself. Item will be collapse by the "handleMenuTouchEvent" handler. 1177 $currentMenu.find('.mtm-drop-expanded').not($currentItem).removeClass('mtm-drop-expanded'); 1178 } else { 1179 // Collapse all opened submenus in current menu, except current subtree. 1180 $topLevelLi.siblings('li').find('.mtm-drop-expanded').removeClass('mtm-drop-expanded'); 1181 } 1182 1183 // Collapse all opened submenus in all other menus. 1184 $('nav').not($currentMenu).find('.mtm-drop-expanded').removeClass('mtm-drop-expanded'); 1185 } else { 1186 // collapse all opened, site wide, submenus 1187 $('.mtm-drop-expanded').removeClass('mtm-drop-expanded'); 1188 } 1189 }; 1190 1191 return that.init(); 1192 } 1193 1194})(window, jQuery, g1.config.i18n.menu); 1195 1196// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 1197// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating 1198// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel 1199// MIT license 1200 1201(function() { 1202 var lastTime = 0; 1203 var vendors = ['ms', 'moz', 'webkit', 'o']; 1204 for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { 1205 window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; 1206 window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; 1207 } 1208 1209 if (!window.requestAnimationFrame) { 1210 window.requestAnimationFrame = function(callback) { 1211 var currTime = new Date().getTime(); 1212 var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 1213 var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 1214 timeToCall); 1215 lastTime = currTime + timeToCall; 1216 return id; 1217 }; 1218 } 1219 1220 if (!window.cancelAnimationFrame) { 1221 window.cancelAnimationFrame = function(id) { 1222 clearTimeout(id); 1223 }; 1224 } 1225}()); 1226 1227 1228 1229/**************** 1230 * 1231 * Popup/Slideup 1232 * 1233 ****************/ 1234 1235(function ($) { 1236 'use strict'; 1237 g1.popup = function () { 1238 var 1239 HTMLBase = $('html'), 1240 Popup = $('.g1-popup-newsletter'), 1241 PopupCookie = g1.readCookie('g1_popup_disabled'), 1242 PopupCloser = $('.g1-popup-base, .g1-popup-closer'); 1243 // If we dont have popup exit. 1244 if( PopupCookie ){ HTMLBase.addClass('exit-intent-disabled'); } 1245 if( Popup.length <= 0 ){ return; } 1246 $(document).on('mouseleave', function(e){ 1247 if( e.clientY < 10 && ! HTMLBase.hasClass('exit-intent-disabled') && ! HTMLBase.hasClass('g1-slideup-visible') ){ 1248 HTMLBase.addClass('g1-popup-ready'); 1249 setTimeout(function(){ 1250 HTMLBase.addClass('g1-popup-visible').addClass('exit-intent-disabled'); 1251 }, 50); 1252 } 1253 }); 1254 PopupCloser.on('click', function(e){ 1255 e.preventDefault(); 1256 HTMLBase.removeClass('g1-popup-visible'); 1257 g1.createCookie('g1_popup_disabled', 1, 24 * 60 * 60 * 1000); 1258 }); 1259 } 1260 1261 1262 1263 g1.slideup = function () { 1264 var 1265 HTMLBase = $('html'), 1266 Slideup = $('.g1-slideup-newsletter'), 1267 SlideupCloser = $('.g1-slideup-newsletter-closer'), 1268 SlideupCookie = g1.readCookie('g1_slideup_disabled'), 1269 ScrollPositon = $(document).scrollTop(), 1270 ScrollTarget = $('.single-post article .entry-content'), 1271 ScrollTargetOffset = ScrollTarget.offset(), 1272 ScrollTargetHeight = ScrollTarget.height(), 1273 ShowOn = 50; 1274 // If we dont have popup exit. 1275 SlideupCloser.on('click', function(e){ 1276 e.preventDefault(); 1277 HTMLBase.removeClass('g1-slideup-visible').addClass('slideup-intent-disabled'); 1278 g1.createCookie('g1_slideup_disabled', 1, 24 * 60 * 60 * 1000); 1279 }); 1280 if( SlideupCookie ){ HTMLBase.addClass('slideup-intent-disabled'); } 1281 if( Slideup.length <= 0 ){ return; } 1282 if( ScrollTarget.length <= 0 ){ return; } 1283 $(window).on('scroll', function(){ 1284 ScrollPositon = $(document).scrollTop(); 1285 ScrollTargetOffset = ScrollTarget.offset(); 1286 ScrollTargetHeight = ScrollTarget.height(); 1287 if( ( (ScrollPositon - ScrollTargetOffset.top) / (ScrollTargetHeight) ).toFixed(6) * 100 >= ShowOn && ! HTMLBase.hasClass('slideup-intent-disabled') && ! HTMLBase.hasClass('g1-popup-visible') ){ 1288 HTMLBase.addClass('g1-slideup-visible'); 1289 } 1290 }); 1291 } 1292})(jQuery); 1293 1294/**************** 1295 * 1296 * GDPR 1297 * 1298 ****************/ 1299 1300(function ($) { 1301 'use strict'; 1302 $(document).ready(function () { 1303 $('.wp-social-login-provider-list').on('click', function() { 1304 if ($(this).hasClass('wp-social-login-provider-list-active')){ 1305 return; 1306 } 1307 $('.snax-wpsl-gdpr-consent').addClass('snax-wpsl-gdpr-consent-blink'); 1308 setTimeout(function(){ 1309 $('.snax-wpsl-gdpr-consent').removeClass('snax-wpsl-gdpr-consent-blink'); 1310 }, 1311 2000); 1312 }); 1313 $('.snax-wpsl-gdpr-consent input').on('click', function() { 1314 var enabled = $(this).is(':checked'); 1315 if (enabled) { 1316 $('.wp-social-login-provider-list').addClass('wp-social-login-provider-list-active'); 1317 } else { 1318 $('.wp-social-login-provider-list').removeClass('wp-social-login-provider-list-active'); 1319 } 1320 }); 1321 }); 1322})(jQuery); 1323 1324/************************** 1325 * 1326 * WordPress Popular Posts 1327 * 1328 **************************/ 1329 1330(function ($) { 1331 1332 'use strict'; 1333 1334 g1.updatePostViews = function(nonce,postId) { 1335 $.ajax({ 1336 'type': 'POST', 1337 'url': g1.config.ajax_url, 1338 'data': { 1339 'action': 'update_views_ajax', 1340 'wpp_id': postId, 1341 'token': nonce 1342 } 1343 }); 1344 }; 1345 1346 // ------------ 1347 // Update views 1348 // ------------ 1349 1350 $('.bimber-count-view').on('click', function() { 1351 var postId; 1352 var $body = $('body'); 1353 1354 if ( $body.is('.single-format-link') ) { 1355 var res = $body.attr('class').match(/postid-(\d+)/); 1356 1357 if (res) { 1358 postId = res[1]; 1359 } 1360 } else { 1361 var $article = $(this).parents('article.format-link'); 1362 if ( $article.length > 0 ) { 1363 postId = $article.attr('class').match(/post\-(\d+)/)[1]; 1364 } 1365 } 1366 1367 if (postId) { 1368 $.ajax({ 1369 'type': 'POST', 1370 'url': g1.config.ajax_url, 1371 'data': { 1372 //'action': 'bimber_update_post_views', 1373 //'post_id': postId 1374 'action': 'update_views_ajax', 1375 'wpp_id': postId, 1376 'token': g1.config.wpp.token 1377 } 1378 }); 1379 } 1380 }); 1381 1382})(jQuery); 1383 1384/******************* 1385 * 1386 * Flickity 1387 * 1388 ******************/ 1389 1390 1391(function ($) { 1392 1393 'use strict'; 1394 1395 g1.flickity = function () { 1396 var 1397 FlickitySpots = $('.adace-shop-the-post-wrap.carousel-wrap .woocommerce .products, .g1-products-widget-carousel .product_list_widget'); 1398 FlickitySpots.each(function () { 1399 if ($(this).hasClass('.flickity-enabled')) { 1400 return; 1401 } 1402 var 1403 ThisFlickityItems = $(this).children(), 1404 ThisFlickityItemsWidth = ThisFlickityItems.outerWidth() * ThisFlickityItems.length, 1405 ThisFlickityArgs = { 1406 cellAlign: 'left', 1407 wrapAround: true, 1408 prevNextButtons: true, 1409 pageDots: false, 1410 groupCells: true, 1411 rightToLeft: g1.isRTL(), 1412 imagesLoaded: true 1413 }; 1414 if (ThisFlickityItemsWidth <= $(this).outerWidth()) { 1415 ThisFlickityArgs.cellAlign = 'center'; 1416 ThisFlickityArgs.wrapAround = false;
1417 } else { 1418 var ThisRequiredNumber = Math.round($(this).outerWidth() / ThisFlickityItems.outerWidth()) * ThisFlickityItems.length; 1419 1420 while (ThisFlickityItems.length < ThisRequiredNumber) { 1421 $(this).append(ThisFlickityItems.clone(true)); 1422 ThisFlickityItems = $(this).children(); 1423 } 1424 } 1425 $(this).flickity(ThisFlickityArgs); 1426 }); 1427 }; 1428 1429 $('body').on('g1NewContentLoaded', function () { 1430 g1.flickity(); 1431 }); 1432})(jQuery); 1433 1434 1435// Sticky off-canvas top offset adjustments. 1436(function ($) { 1437 'use strict'; 1438 1439 $(document).ready(function () { 1440 var selectors = [ 1441 '#wpadminbar', 1442 '.g1-iframe-bar', 1443 '.g1-sticky-top-wrapper' 1444 ]; 1445 1446 var applyOffset = function() { 1447 // Calculate the total height of all sticky elements. 1448 var topOffset = 0; 1449 for (var i = 0; i < selectors.length; i++) { 1450 var $elem = $(selectors[i]); 1451 1452 if ($elem.length > 0 && $elem.is(':visible')) { 1453 topOffset += $elem.outerHeight(); 1454 } 1455 } 1456 1457 1458 var cssRule = 'html.g1-off-inside.g1-off-global-desktop .g1-canvas {top:' + topOffset + 'px;' 1459 1460 $('#g1-canvas-js-css').remove(); 1461 $('head').append( '<style id="g1-canvas-js-css">' + cssRule + '</style>' ); 1462 $('html.g1-off-inside .g1-canvas').removeClass('g1-canvas-no-js').addClass('g1-canvas-js'); 1463 }; 1464 1465 $('body').on( 'g1PageHeightChanged', function(e) { 1466 applyOffset(); 1467 } ); 1468 1469 $('html.g1-off-inside .g1-canvas.g1-canvas-no-js').each(function() { 1470 applyOffset(); 1471 }); 1472 } ); 1473})(jQuery); 1474 1475 1476/************************** 1477 * 1478 * document ready functions (keep this at the end for better compatibillity with optimizing plugins) 1479 * 1480 *************************/ 1481 1482(function ($) { 1483 1484 'use strict'; 1485 1486 $(document).ready(function () { 1487 g1.uiHelpers(); 1488 1489 if (g1.config.timeago === 'on') { 1490 g1.dateToTimeago(); 1491 } 1492 1493 g1.loadMoreButton(); 1494 g1.infiniteScroll(); 1495 g1.stickyPosition(); 1496 g1.droppableElements(); 1497 g1.canvas(); 1498 g1.snax(); 1499 g1.mediaAce(); 1500 g1.flickity(); 1501 g1.popup(); 1502 g1.slideup(); 1503 g1.stickySidebar(); 1504 }); 1505 1506})(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.