(function ($) { 'use strict'; const GeotWP = { uniqueID : null, lat : null, lng : null, img_geoloc : null, img_consent : null, /** * Start function */ init: function () { $(document).ready( GeotWP.ready ); }, /** * When dom it's ready */ ready: function () { GeotWP.initSelectize(); GeotWP.initBrowser(); GeotWP.executeAjax(); if( geot.elementor_popup ) $( document ).on( 'elementor/popup/show', GeotWP.executeAjax ); }, executeGps: function() { const cords = JSON.parse( sessionStorage.getItem('geot_cords') ); if( cords ) { GeotWP.lat = cords.lat; GeotWP.lng = cords.lng; } else { if (navigator.geolocation) { GeotWP.maybe_overlay(); // Set Geolocation navigator.geolocation.getCurrentPosition( GeotWP.successPosition, GeotWP.errorPosition, {maximumAge:10000, timeout:5000, enableHighAccuracy: true} ); } else { console.log(geot.geoloc_fail); } } }, executeAjax: function() { if( ( ! $('.geot-ajax').length && ( ! geot.has_geo_posts || geot.has_geo_posts.length == 0 ) && ! $('.geotr-ajax').length && ! $('.geobl-ajax').length )|| geot.is_builder == '1' ) { return; } /* Geolocation */ if( geot.geoloc_enable && ( geot.geoloc_enable == 'by_html5' || (geot.geoloc_enable == 'by_html5_mobile' && GeotWP.isMobile()) ) ) { GeotWP.executeGps(); } const geot_debug = GeotWP.getUrlParameter('geot_debug'), geot_debug_iso = GeotWP.getUrlParameter('geot_debug_iso'), geot_state = GeotWP.getUrlParameter('geot_state'), geot_state_code = GeotWP.getUrlParameter('geot_state_code'), geot_city = GeotWP.getUrlParameter('geot_city'), geot_zip = GeotWP.getUrlParameter('geot_zip'); let data = { 'action': 'geot_ajax', 'geots': {}, 'vars': geot, 'pid': geot.pid, 'referrer': document.referrer, 'url': window.location.href, 'query_string': document.location.search, 'is_category': geot.is_category, 'is_archive': geot.is_archive, 'is_front_page': geot.is_front_page, 'is_search': geot.is_search, 'browser_language': navigator.language || navigator.userLanguage, 'geot_debug': geot_debug, 'geot_debug_iso': geot_debug_iso, 'geot_state': geot_state, 'geot_state_code': geot_state_code, 'geot_city': geot_city, 'geot_zip': geot_zip, 'geot_lat': GeotWP.lat, 'geot_lng': GeotWP.lng, }; $('.geot-placeholder').show(); $('.geot-ajax').each(function () { let _this = $(this); if (_this.hasClass('geot_menu_item')) { _this = $(this).find('[data-action]').first(); } if( _this.data('action') && _this.data('action').length ) { const uniqid = GeotWP.getUniqueName('geot'); _this.addClass(uniqid); data.geots[uniqid] = { 'action': _this.data('action') || '', 'filter': _this.data('filter') || '', 'region': _this.data('region') || '', 'ex_filter': _this.data('ex_filter') || '', 'ex_region': _this.data('ex_region') || '', 'default': _this.data('default') || '', 'locale': _this.data('locale') || 'en', 'geo_mode': _this.data('geo_mode') || '', } } }); if( $('.geotr-ajax').length ) data.geot_redirects = 1; if( $('.geobl-ajax').length ) data.geot_blockers = 1; const onSuccess = function (response) { if (response.success) { $('.geot-placeholder').remove(); let results = response.data, i, redirect = response.redirect, blocker = response.blocker, remove = response.posts.remove, hide = response.posts.hide, debug = response.debug; if( window.geotWP.selectize && typeof response.geo.country != "undefined") { window.geotWP.selectize.forEach( function (sel) { sel.addItem(response.geo.country.data.iso_code.toUpperCase(), true); }) } if( redirect && redirect.url ) { let do_redirect = true; if( parseInt( redirect.one_time_redirect ) == 1) { if( localStorage.getItem('geo_redirect_' + redirect.id ) ){ do_redirect = false; } localStorage.setItem( 'geo_redirect_' + redirect.id, true ); } if( parseInt( redirect.one_time_redirect ) == 2) { if( sessionStorage.getItem('geo_redirect_' + redirect.id ) ){ do_redirect = false; } sessionStorage.setItem( 'geo_redirect_' + redirect.id, true ) } if( do_redirect ) { $('.geotr-ajax').show(); setTimeout(function () { location.replace(redirect.url) }, 2000); } } if( blocker && blocker.length ) { $('html').html(blocker); } if(! geot.disable_console ) { console.log(response); } let has_media = false; if ( results && results.length ) { for ( i = 0; i < results.length; ++i ) { if ( results[i].action == 'menu_filter' ) { if (results[i].value != true) { $('.' + results[i].id).closest('.geot_menu_item').removeClass('geot_menu_item'); } else { $('.' + results[i].id).closest('.geot_menu_item').remove(); // if still not removed due to class being stripped try this $('.' + results[i].id).closest('li').remove(); } } else if ( results[i].action == 'widget_filter' ) { const widget_id = $('.' + results[i].id).data('widget'); if ( results[i].value != true ) { $('#css-' + widget_id).remove(); } else { $('#' + widget_id).remove(); } $('.' + results[i].id).remove(); } else if ( results[i].action.indexOf('filter' ) > -1) { if ( results[i].value == true ) { let audio_video = $('.' + results[i].id).find('audio.wp-audio-shortcode,video.wp-video-shortcode'); if( audio_video.length ) { $('.' + results[i].id).find('.mejs-container').replaceWith(audio_video); has_media = true; } const html = $('.' + results[i].id).html(); $('.' + results[i].id).replaceWith(html); } $('.' + results[i].id).remove(); } else { $('.' + results[i].id).replaceWith(results[i].value); } } } if( has_media ) { window.wp.mediaelement.initialize(); } if (remove && remove.length) { if( ! geot.is_singular || ( geot.is_singular && ! geot.disable_remove_on_singular ) ){ for (i = 0; i < remove.length; ++i) { let id = remove[i]; let remove_class = '#post-' + id + ', .post-' + id + ',' + '.elementor-jet-woo-products div[data-product-id="'+ id +'"]'; if( geot.remove_class.length ) { remove_class = remove_class + ',' + GeotWP.replaceAll(geot.remove_class,'%id', id); } if( geot.remove_override_class.length ) { remove_class = GeotWP.replaceAll(geot.remove_override_class,'%id', id); } $(remove_class).remove(); } } } if (hide && hide.length) { for (i = 0; i < hide.length; ++i) { let id = hide[i].id; let hide_class = '#post-' + id + ' .entry-content,' + '#post-' + id + ' .woocommerce-product-details__short-description,' + '.post-' + id + ' .entry-content,' + '.elementor-widget-container .post-' + id + ',' + '.jet-listing-dynamic-post-'+ id +',' + '.elementor-jet-woo-products div[data-product-id="'+ id +'"]' + '.post-' + id + ' .woocommerce-product-details__short-description'; if( geot.hide_class.length ) { hide_class = hide_class + ',' + GeotWP.replaceAll(geot.hide_class,'%id', id); } if( geot.hide_override_class.length ) { hide_class = GeotWP.replaceAll(geot.hide_override_class,'%id', id); } $( hide_class ).html('
' + hide[i].msg + '
'); } } if (debug && debug.length) { $('#geot-debug-info').html(debug); $('.geot-debug-data').html(debug.replace(//gi, '')); } $(document).trigger('geotwp_ajax_success', response); } } const error_cb = function (data, error, errorThrown) { console.log('Geot Ajax error: ' + error + ' - ' + errorThrown); } if ( geot && geot.ajax ) GeotWP.request(data, onSuccess, error_cb); }, replaceAll: function(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); }, /** * Start the geot dropdown widget */ initSelectize: function() { if (geot && (/iP(od|hone)/i.test(window.navigator.userAgent) || /IEMobile/i.test(window.navigator.userAgent) || /Windows Phone/i.test(window.navigator.userAgent) || /BlackBerry/i.test(window.navigator.userAgent) || /BB10/i.test(window.navigator.userAgent) || /Android.*Mobile/i.test(window.navigator.userAgent))) { geot.dropdown_search = true; } let geot_options = { onChange: function (country_code) { if (!country_code.length) return; GeotWP.createCookie('geot_country', country_code, geot.geot_cookies_duration); GeotWP.createCookie('geot_rocket_country', country_code, geot.geot_cookies_duration); GeotWP.createCookie('STYXKEY_geot_country', country_code, geot.geot_cookies_duration); if (geot.dropdown_redirect && geot.dropdown_redirect.length) { window.location.replace(geot.dropdown_redirect); } else { window.location.reload(); } } }; if ($('.geot_dropdown').data('flags')) { geot_options.render = { option: function (data, escape) { return '