1(function ($) { 2 'use strict'; 3 4 const GeotWP = { 5 uniqueID : null, 6 lat : null, 7 lng : null, 8 img_geoloc : null, 9 img_consent : null, 10 /** 11 * Start function 12 */ 13 init: function () { 14 $(document).ready( GeotWP.ready ); 15 }, 16 /** 17 * When dom it's ready 18 */ 19 ready: function () { 20 GeotWP.initSelectize(); 21 GeotWP.initBrowser(); 22 GeotWP.executeAjax(); 23 24 if( geot.elementor_popup ) 25 $( document ).on( 'elementor/popup/show', GeotWP.executeAjax ); 26 27 }, 28 executeGps: function() { 29 const cords = JSON.parse( sessionStorage.getItem('geot_cords') ); 30 if( cords ) { 31 GeotWP.lat = cords.lat; 32 GeotWP.lng = cords.lng; 33 } else { 34 if (navigator.geolocation) { 35 GeotWP.maybe_overlay(); 36 37 // Set Geolocation 38 navigator.geolocation.getCurrentPosition( 39 GeotWP.successPosition, 40 GeotWP.errorPosition, 41 {maximumAge:10000, timeout:5000, enableHighAccuracy: true} 42 ); 43 44 } else { 45 console.log(geot.geoloc_fail); 46 } 47 } 48 }, 49 executeAjax: function() { 50 if( ( ! $('.geot-ajax').length && 51 ( ! geot.has_geo_posts || geot.has_geo_posts.length == 0 ) && 52 ! $('.geotr-ajax').length && 53 ! $('.geobl-ajax').length )|| 54 geot.is_builder == '1' ) { 55 return; 56 } 57 /* Geolocation */ 58 if( geot.geoloc_enable && ( geot.geoloc_enable == 'by_html5' || (geot.geoloc_enable == 'by_html5_mobile' && GeotWP.isMobile()) ) ) { 59 GeotWP.executeGps(); 60 } 61 const geot_debug = GeotWP.getUrlParameter('geot_debug'), 62 geot_debug_iso = GeotWP.getUrlParameter('geot_debug_iso'), 63 geot_state = GeotWP.getUrlParameter('geot_state'), 64 geot_state_code = GeotWP.getUrlParameter('geot_state_code'), 65 geot_city = GeotWP.getUrlParameter('geot_city'), 66 geot_zip = GeotWP.getUrlParameter('geot_zip'); 67 let data = { 68 'action': 'geot_ajax', 69 'geots': {}, 70 'vars': geot, 71 'pid': geot.pid, 72 'referrer': document.referrer, 73 'url': window.location.href, 74 'query_string': document.location.search, 75 'is_category': geot.is_category, 76 'is_archive': geot.is_archive, 77 'is_front_page': geot.is_front_page, 78 'is_search': geot.is_search, 79 'browser_language': navigator.language || navigator.userLanguage, 80 'geot_debug': geot_debug, 81 'geot_debug_iso': geot_debug_iso, 82 'geot_state': geot_state, 83 'geot_state_code': geot_state_code, 84 'geot_city': geot_city, 85 'geot_zip': geot_zip, 86 'geot_lat': GeotWP.lat, 87 'geot_lng': GeotWP.lng, 88 }; 89 90 91 $('.geot-placeholder').show(); 92 93 $('.geot-ajax').each(function () { 94 let _this = $(this); 95 if (_this.hasClass('geot_menu_item')) { 96 97 _this = $(this).find('[data-action]').first(); 98 } 99 100 if( _this.data('action') && _this.data('action').length ) { 101 const uniqid = GeotWP.getUniqueName('geot'); 102 _this.addClass(uniqid); 103 data.geots[uniqid] = { 104 'action': _this.data('action') || '', 105 'filter': _this.data('filter') || '', 106 'region': _this.data('region') || '', 107 'ex_filter': _this.data('ex_filter') || '',
108 'ex_region': _this.data('ex_region') || '', 109 'default': _this.data('default') || '', 110 'locale': _this.data('locale') || 'en', 111 'geo_mode': _this.data('geo_mode') || '', 112 } 113 } 114 }); 115 116 117 if( $('.geotr-ajax').length ) 118 data.geot_redirects = 1; 119 120 if( $('.geobl-ajax').length ) 121 data.geot_blockers = 1; 122 123 124 const onSuccess = function (response) { 125 if (response.success) { 126 127 $('.geot-placeholder').remove(); 128 129 let results = response.data, 130 i, 131 redirect = response.redirect, 132 blocker = response.blocker, 133 remove = response.posts.remove, 134 hide = response.posts.hide, 135 debug = response.debug; 136 if( window.geotWP.selectize && typeof response.geo.country != "undefined") { 137 window.geotWP.selectize.forEach( function (sel) { 138 sel.addItem(response.geo.country.data.iso_code.toUpperCase(), true); 139 }) 140 } 141 if( redirect && redirect.url ) { 142 let do_redirect = true; 143 if( parseInt( redirect.one_time_redirect ) == 1) { 144 if( localStorage.getItem('geo_redirect_' + redirect.id ) ){ 145 do_redirect = false; 146 } 147 localStorage.setItem( 'geo_redirect_' + redirect.id, true ); 148 } if( parseInt( redirect.one_time_redirect ) == 2) { 149 if( sessionStorage.getItem('geo_redirect_' + redirect.id ) ){ 150 do_redirect = false; 151 } 152 sessionStorage.setItem( 'geo_redirect_' + redirect.id, true ) 153 } 154 if( do_redirect ) { 155 $('.geotr-ajax').show(); 156 setTimeout(function () { 157 location.replace(redirect.url) 158 }, 2000); 159 } 160 } 161 162 if( blocker && blocker.length ) { 163 $('html').html(blocker); 164 } 165 if(! geot.disable_console ) { 166 console.log(response); 167 } 168 let has_media = false; 169 if ( results && results.length ) { 170 for ( i = 0; i < results.length; ++i ) { 171 if ( results[i].action == 'menu_filter' ) { 172 if (results[i].value != true) { 173 $('.' + results[i].id).closest('.geot_menu_item').removeClass('geot_menu_item'); 174 } else { 175 $('.' + results[i].id).closest('.geot_menu_item').remove(); 176 // if still not removed due to class being stripped try this 177 $('.' + results[i].id).closest('li').remove(); 178 } 179 } else if ( results[i].action == 'widget_filter' ) { 180 const widget_id = $('.' + results[i].id).data('widget'); 181 if ( results[i].value != true ) { 182 $('#css-' + widget_id).remove(); 183 } else { 184 $('#' + widget_id).remove(); 185 } 186 $('.' + results[i].id).remove(); 187 } else if ( results[i].action.indexOf('filter' ) > -1) { 188 if ( results[i].value == true ) { 189 190 let audio_video = $('.' + results[i].id).find('audio.wp-audio-shortcode,video.wp-video-shortcode'); 191 192 if( audio_video.length ) { 193 $('.' + results[i].id).find('.mejs-container').replaceWith(audio_video); 194 has_media = true; 195 } 196 const html = $('.' + results[i].id).html(); 197 $('.' + results[i].id).replaceWith(html); 198 } 199 $('.' + results[i].id).remove(); 200 } else { 201 $('.' + results[i].id).replaceWith(results[i].value); 202 } 203 } 204 } 205 if( has_media ) { 206 window.wp.mediaelement.initialize(); 207 } 208 if (remove && remove.length) { 209 if( ! geot.is_singular || ( geot.is_singular && ! geot.disable_remove_on_singular ) ){ 210 for (i = 0; i < remove.length; ++i) { 211 let id = remove[i]; 212 let remove_class = '#post-' + id + ', .post-' + id + ',' + 213 '.elementor-jet-woo-products div[data-product-id="'+ id +'"]'; 214 if( geot.remove_class.length ) { 215 remove_class = remove_class + ',' + GeotWP.replaceAll(geot.remove_class,'%id', id); 216 } 217 if( geot.remove_override_class.length ) { 218 remove_class = GeotWP.replaceAll(geot.remove_override_class,'%id', id); 219 } 220 $(remove_class).remove(); 221 } 222 } 223 } 224 if (hide && hide.length) { 225 226 for (i = 0; i < hide.length; ++i) { 227 let id = hide[i].id; 228 let hide_class = '#post-' + id + ' .entry-content,' + 229 '#post-' + id + ' .woocommerce-product-details__short-description,' + 230 '.post-' + id + ' .entry-content,' + 231 '.elementor-widget-container .post-' + id + ',' + 232 '.jet-listing-dynamic-post-'+ id +',' + 233 '.elementor-jet-woo-products div[data-product-id="'+ id +'"]' + 234 '.post-' + id + ' .woocommerce-product-details__short-description'; 235 if( geot.hide_class.length ) { 236 hide_class = hide_class + ',' + GeotWP.replaceAll(geot.hide_class,'%id', id); 237 } 238 if( geot.hide_override_class.length ) { 239 hide_class = GeotWP.replaceAll(geot.hide_override_class,'%id', id); 240 } 241 $( hide_class ).html('<p>' + hide[i].msg + '</p>'); 242 } 243 } 244 if (debug && debug.length) { 245 $('#geot-debug-info').html(debug); 246 $('.geot-debug-data').html(debug.replace(/<!--|-->/gi, '')); 247 } 248 $(document).trigger('geotwp_ajax_success', response); 249 } 250 } 251 252 const error_cb = function (data, error, errorThrown) { 253 console.log('Geot Ajax error: ' + error + ' - ' + errorThrown); 254 } 255 if ( geot && geot.ajax ) 256 GeotWP.request(data, onSuccess, error_cb); 257 }, 258 replaceAll: function(str, find, replace) { 259 return str.replace(new RegExp(find, 'g'), replace); 260 }, 261 /** 262 * Start the geot dropdown widget 263 */ 264 initSelectize: function() { 265 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))) { 266 geot.dropdown_search = true; 267 } 268 let geot_options = { 269 onChange: function (country_code) { 270 if (!country_code.length) 271 return; 272 GeotWP.createCookie('geot_country', country_code, geot.geot_cookies_duration); 273 GeotWP.createCookie('geot_rocket_country', country_code, geot.geot_cookies_duration); 274 GeotWP.createCookie('STYXKEY_geot_country', country_code, geot.geot_cookies_duration); 275 if (geot.dropdown_redirect && geot.dropdown_redirect.length) { 276 window.location.replace(geot.dropdown_redirect); 277 } else { 278 window.location.reload(); 279 } 280 } 281 }; 282 if ($('.geot_dropdown').data('flags')) { 283 geot_options.render = { 284 option: function (data, escape) { 285 return '<div class="option">' + 286 '<span class="geot-flag flag-' + escape(data.value.toLowerCase()) + '"></span>' + 287 '<span class="url">' + escape(data.text) + '</span>' + 288 '</div>'; 289 }, 290 item: function (data, escape) { 291 return '<div class="item"><span class="geot-flag flag-' + escape(data.value.toLowerCase()) + '"></span>' + escape(data.text) + '</div>'; 292 } 293 }; 294 } 295 if ($('.geot_dropdown').length) { 296 window.geotWP.selectize = []; 297 $('.geot_dropdown').each(function () { 298 let $geot_select = $(this).selectize(geot_options); 299 window.geotWP.selectize.push($geot_select[0].selectize) 300 }) 301 if (GeotWP.readCookie('geot_country')) { 302 window.geotWP.selectize.forEach( function (sel) { 303 sel.addItem(GeotWP.readCookie('geot_country'), true); 304 }) 305 } 306 } 307 }, 308 isMobile : function() { 309 let check = false;
310 (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera); 311 return check; 312 }, 313 /** 314 * Detected Browser 315 * Source : https://jsfiddle.net/6spj1059/ 316 * @returns 317 */ 318 initBrowser: function() { 319 // Opera 8.0+ 320 const isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; 321 322 // Firefox 1.0+ 323 const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; 324 325 // Safari 3.0+ "[object HTMLElementConstructor]" 326 const isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification)); 327 328 // Internet Explorer 6-11 329 const isIE = /*@cc_on!@*/false || !!document.documentMode; 330 331 // Edge 20+ 332 const isEdge = !isIE && !!window.StyleMedia; 333 334 // Chrome 1 - 79 335 const isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime); 336 337 338 if( isOpera ) { 339 GeotWP.img_geoloc = geot.geoloc_img_opera; 340 GeotWP.img_consent = geot.geoloc_consent_opera; 341 } else if( isFirefox ) { 342 GeotWP.img_geoloc = geot.geoloc_img_firefox; 343 GeotWP.img_consent = geot.geoloc_consent_firefox; 344 } else if( isSafari ) { 345 GeotWP.img_geoloc = geot.geoloc_img_safari; 346 GeotWP.img_consent = geot.geoloc_consent_safari; 347 } else if( isEdge || isIE ) { 348 GeotWP.img_geoloc = geot.geoloc_img_edge; 349 GeotWP.img_consent = geot.geoloc_consent_edge; 350 } else { 351 GeotWP.img_geoloc = geot.geoloc_img_chrome; 352 GeotWP.img_consent = geot.geoloc_consent_chrome; 353 } 354 }, 355 /** 356 * Generate unique id 357 * @param prefix 358 * @returns {*} 359 */ 360 getUniqueName: function (prefix) { 361 if (! GeotWP.uniqueID) { 362 GeotWP.uniqueID = (new Date()).getTime(); 363 } 364 return prefix + (GeotWP.uniqueID++); 365 }, 366 /** 367 * When Geolocation get the coordinates successfully 368 * @return {[type]} [description] 369 */ 370 successPosition: function(position) { 371 GeotWP.createCookie('geot-gps', 'yes', 999); 372
373 const $overlay = $('div.geotloc_overlay_box'); 374 $overlay.fadeOut('fast'); 375 376 // If first time, refresh 377 if( GeotWP.readCookie('geotRefresh') == null ) { 378 GeotWP.createCookie('geotRefresh', 'yes'); 379 window.location.reload(); 380 } 381 382 GeotWP.lat = position.coords.latitude; 383 GeotWP.lng = position.coords.longitude; 384 sessionStorage.setItem('geot_cords', JSON.stringify({ lat: GeotWP.lat, lng: GeotWP.lng } ) ); 385 386 GeotWP.executeAjax(); 387 }, 388 /** 389 * When Geolocation not get the coordinates 390 * @param OBJ error 391 * @return mixed 392 */ 393 errorPosition: function(error) { 394 GeotWP.createCookie('geot-gps', 'no'); 395 396 const $overlay = $('div.geotloc_overlay_box'); 397 398 if( geot.geoloc_force ) { 399 400 if( ! $overlay.is(':visible') ) 401 GeotWP.show_overlay(); 402 } else { 403 $overlay.fadeOut('fast'); 404 } 405 406 // If first time, refresh 407 if( GeotWP.readCookie('geotRefresh') == null && ! geot.geoloc_force ) { 408 GeotWP.createCookie('geotRefresh', 'yes'); 409 window.location.reload(); 410 } 411 // only run once 412 if( ! window.sessionStorage.getItem('geot_error_position') ) { 413 GeotWP.executeAjax(); 414 } 415 window.sessionStorage.setItem('geot_error_position', 1); 416 }, 417 /** 418 * Put Shadow Overlay 419 * @return mixed 420 */ 421 maybe_overlay: function() { 422 423 const $overlay = $('div.geotloc_overlay_box'); 424 425 if( GeotWP.readCookie('geot-gps') == null && ! /bot|google|baidu|bing|msn|crawl|lteoma|slurp|yandex/i.test(navigator.userAgent) ) { 426 427 GeotWP.show_overlay(); 428 } 429 430 $overlay.find('.geotloc_overlay_remove').on('click', function() { 431 $overlay.fadeOut('fast'); 432 }); 433 }, 434 /** 435 * Show Overlay 436 * @return mixed 437 */ 438 show_overlay: function() { 439 const $overlay = $('div.geotloc_overlay_box'); 440 441 if( geot.geoloc_force ) 442 $overlay.find('div.geotloc_overlay_remove').hide(); 443 else 444 $overlay.find('div.geotloc_overlay_remove').show(); 445 446 $overlay.fadeIn('slow'); 447 }, 448 /** 449 * Create Cookies 450 * @param name 451 * @param value 452 * @param days 453 */ 454 createCookie: function(name, value, days) { 455 let expires = ""; 456 if (days) { 457 let date = new Date(); 458 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 459 expires = "; expires=" + date.toGMTString(); 460 } 461 document.cookie = name + "=" + value + expires + "; path=/"; 462 }, 463 /** 464 * Delete Cookies 465 * @param name 466 * @returns {string|null} 467 */ 468 deleteCookie: function(name) { 469 document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 470 }, 471 /** 472 * Read Cookies 473 * @param name 474 * @returns {string|null} 475 */ 476 readCookie: function(name) { 477 let nameEQ = name + "="; 478 let ca = document.cookie.split(';'); 479 for (let i = 0; i < ca.length; i++) { 480 let c = ca[i]; 481 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 482 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 483 } 484 return null; 485 }, 486 /** 487 * Perform Ajax requests 488 * @param data 489 * @param success_cb 490 * @param error_cb 491 * @param dataType 492 */ 493 request: function (data, success_cb, error_cb, dataType) { 494 // Prepare variables. 495 let ajax = { 496 url: geot.ajax_url, 497 data: data, 498 cache: false, 499 type: 'POST', 500 dataType: 'json', 501 timeout: 30000 502 }, 503 data_type = dataType || false, 504 success = success_cb || false, 505 error = error_cb || false; 506 507 // Set success callback if supplied.
508 if (success) { 509 ajax.success = success; 510 } 511 512 // Set error callback if supplied. 513 if (error) { 514 ajax.error = error; 515 } 516 517 // Change dataType if supplied. 518 if (data_type) { 519 ajax.dataType = data_type; 520 } 521 // Make the ajax request. 522 $.ajax(ajax); 523 524 }, 525 /** 526 * Get parameter from url 527 * @param name 528 * @returns {string} 529 */ 530 getUrlParameter: function(name) { 531 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 532 let regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 533 let results = regex.exec(window.location.search); 534 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); 535 } 536 } 537 538 GeotWP.init(); 539 540 window.geotWP = GeotWP; 541 542})(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.