/* global window */ /* global document */ /* global jQuery */ /* global g1 */ /* global bimber_front_config */ /* global SuperGif */ /* global Waypoint */ /* global enquire */ /* global mashsb */ /* global auto_load_next_post_params */ /* global FB */ /* global mejs */ /* global ga */ /* global embedly */ /* global console */ /************* * * Init env * *************/ (function($) { 'use strict'; var config = bimber_front_config; // namespace var g1 = { 'config': config }; g1.getWindowWidth = function () { if (typeof window.innerWidth !== 'undefined') { return window.innerWidth; } return $(window).width(); }; g1.isDesktopDevice = function () { return g1.getWindowWidth() > g1.getDesktopBreakpoint(); }; g1.getDesktopBreakpoint = function () { var desktopBreakPoint = $('#g1-breakpoint-desktop').css('min-width'); if ( ! desktopBreakPoint ) { return 9999; } desktopBreakPoint = parseInt( desktopBreakPoint, 10 ); // not set explicitly via css if (desktopBreakPoint === 0) { return 9999; } return desktopBreakPoint; }; g1.isTouchDevice = function () { return ('ontouchstart' in window) || navigator.msMaxTouchPoints; }; g1.isStickySupported = function () { var prefixes = ['', '-webkit-', '-moz-', '-ms-']; var block = document.createElement('div'); var supported = false; var i; // Test for native support. for (i = prefixes.length - 1; i >= 0; i--) { try { block.style.position = prefixes[i] + 'sticky'; } catch(e) {} if (block.style.position !== '') { supported = true; } } return supported; }; g1.isRTL = function () { return $('body').is('.rtl'); }; g1.log = function(data) { if ((g1.config.debug_mode || window.bimberDebugMode) && typeof console !== 'undefined') { if ($.isArray(data)) { for (var i in data) { console.log(data[i]); } } else { console.log(data); } } }; g1.createCookie = function (name,value,time) { var expires; if (time) { var date = new Date(); var ms = time; if (typeof time === 'object') { ms = time.value; switch (time.type) { case 'days': ms = ms * 24 * 60 * 60 * 1000; break; } } date.setTime(date.getTime() + ms); expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires + '; path=/'; }; g1.readCookie = function (name) { var nameEQ = name + '='; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i += 1) { var c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); } } return null; }; g1.removeCookie = function (name) { g1.createCookie(name, '', -1); }; // expose to the world window.g1 = g1; })(jQuery); /************* * * UI Helpers * ************/ (function ($) { 'use strict'; g1.uiHelpers = function () { if (g1.isTouchDevice()) { $('body').removeClass( 'g1-hoverable' ); } // ----------------- // Mailchimp widget. // ----------------- var mc4wpClasses = [ 'g1-box', 'g1-box-tpl-frame', 'g1-newsletter' ]; var mc4wpBackgroundClasses = [ 'g1-box-background' ]; if ('original-2018' === g1.config.stack || 'food' === g1.config.stack ) { mc4wpBackgroundClasses.push('g1-current-background'); } if ( 'miami' === g1.config.stack || 'music' === g1.config.stack ) { mc4wpClasses.push('g1-dark'); } $('.widget_mc4wp_form_widget'). addClass(mc4wpClasses.join(' ')). wrapInner('
'). prepend(''). append(''); // ----------- // bbPress. // ----------- var bbPressBackgroundClasses = [ 'g1-box-background' ]; if ('original-2018' === g1.config.stack || 'food' === g1.config.stack ) { bbPressBackgroundClasses.push('g1-current-background'); } $('.bbp_widget_login'). addClass('g1-box g1-box-tpl-frame'). wrapInner(''). append(''); // ---------- // Search UI. // ---------- $('.g1-drop-the-search').on('click', '.g1-drop-toggle', function (e) { e.preventDefault(); $('.g1-drop-the-search input.search-field').focus(); }); $('.search-submit').on('click', function(e){ var $form = $(this).closest('form'); var $input = $('input.search-field', $form); if ( ! $input.val()){ e.preventDefault(); } }); $('#buddypress .load-more').click(function() { var i = 0; var intervalID = setInterval( function() { $('body').trigger( 'g1PageHeightChanged' ); i++; if (i === 5){ window.clearInterval(intervalID); } },1000); }); }; })(jQuery); /**************** * * Facebook SDK * ****************/ (function ($) { 'use strict'; g1.resetFacebookSDK = function () { $('script#facebook-jssdk').remove(); $('#fb-root').remove(); if (window.FB) { delete window.FB; } }; $('body').on( 'g1BeforeNewContentReady', function ( e, $newContent ) { if ($newContent.find('.fb-video').length > 0) { g1.resetFacebookSDK(); } } ); })(jQuery); /**************** * * Instagram SDK * ****************/ (function ($) { 'use strict'; $('body').on( 'g1NewContentLoaded', function ( e, $newContent ) { if ($newContent.find('.instagram-media').length > 0) { if (typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined') { instgrm.Embeds.process(); } } } ); })(jQuery); /******************** * * Load More Button * ********************/ (function ($) { 'use strict'; // prevent triggering the action more than once at the time var loading = false; var startingUrl = window.location.href; var setTargetBlank = g1.config.setTargetBlank; var useWaypoints = g1.config.useWaypoints; g1.loadMoreButton = function () { $('.g1-load-more').on('click', function (e) { if (loading) { return; } loading = true; e.preventDefault(); var $button = $(this); var $collectionMore = $button.parents('.g1-collection-more'); var url = $button.attr('data-g1-next-page-url'); var $endMessage = $('.g1-pagination-end'); $collectionMore.addClass('g1-collection-more-loading'); // load page var xhr = $.get(url); // on success xhr.done(function (data) { var collectionSelector = '#primary > .g1-collection .g1-collection-items'; // find elements in response var $resCollectionItems = $(data).find(collectionSelector).find('.g1-collection-item'); var $resButton = $(data).find('.g1-load-more'); // find collection on page var $collection = $(collectionSelector); // add extra classes to new loaded items $resCollectionItems.addClass('g1-collection-item-added'); // If there are insta embeds BEFORE the load, we will force to refresh them AFTER the load var $insta = $('script[src="//platform.instagram.com/en_US/embeds.js"]'); // make sure that mejs is loaded if (window.wp && typeof window.wp.mediaelement === 'undefined') { var matches = data.match(/