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 _this = $(this).children().first(); 97 98 if( _this.data('action') && _this.data('action').length ) { 99 const uniqid = GeotWP.getUniqueName('geot'); 100 _this.addClass(uniqid); 101 data.geots[uniqid] = { 102 'action': _this.data('action') || '', 103 'filter': _this.data('filter') || '', 104 'region': _this.data('region') || '', 105 'ex_filter': _this.data('ex_filter') || '',
106 'ex_region': _this.data('ex_region') || '', 107 'default': _this.data('default') || '', 108 'locale': _this.data('locale') || 'en', 109 'geo_mode': _this.data('geo_mode') || '', 110 } 111 } 112 }); 113 114 115 if( $('.geotr-ajax').length ) 116 data.geot_redirects = 1; 117 118 if( $('.geobl-ajax').length ) 119 data.geot_blockers = 1; 120 121 122 const onSuccess = function (response) { 123 if (response.success) { 124 125 $('.geot-placeholder').remove(); 126 127 let results = response.data, 128 i, 129 redirect = response.redirect, 130 blocker = response.blocker, 131 remove = response.posts.remove, 132 hide = response.posts.hide, 133 debug = response.debug; 134 if( window.geotWP.selectize && typeof response.geo.country != "undefined") { 135 window.geotWP.selectize.forEach( function (sel) { 136 sel.addItem(response.geo.country.data.iso_code.toUpperCase(), true); 137 }) 138 } 139 if( redirect && redirect.url ) { 140 let do_redirect = true; 141 if( parseInt( redirect.one_time_redirect ) == 1) { 142 if( localStorage.getItem('geo_redirect_' + redirect.id ) ){ 143 do_redirect = false; 144 } 145 localStorage.setItem( 'geo_redirect_' + redirect.id, true ); 146 } if( parseInt( redirect.one_time_redirect ) == 2) { 147 if( sessionStorage.getItem('geo_redirect_' + redirect.id ) ){ 148 do_redirect = false; 149 } 150 sessionStorage.setItem( 'geo_redirect_' + redirect.id, true ) 151 } 152 if( do_redirect ) { 153 $('.geotr-ajax').show(); 154 setTimeout(function () { 155 location.replace(redirect.url) 156 }, 2000); 157 } 158 } 159 160 if( blocker && blocker.length ) { 161 $('html').html(blocker); 162 } 163 if(! geot.disable_console ) { 164 console.log(response); 165 } 166 let has_media = false; 167 if ( results && results.length ) { 168 for ( i = 0; i < results.length; ++i ) { 169 if ( results[i].action == 'menu_filter' ) { 170 if (results[i].value != true) { 171 $('.' + results[i].id).parent('.geot_menu_item').removeClass('geot_menu_item'); 172 } else { 173 $('.' + results[i].id).parent('.geot_menu_item').remove(); 174 // if still not removed due to class being stripped try this 175 $('.' + results[i].id).parent('li').remove(); 176 } 177 } else if ( results[i].action == 'widget_filter' ) { 178 const widget_id = $('.' + results[i].id).data('widget'); 179 if ( results[i].value != true ) { 180 $('#css-' + widget_id).remove(); 181 } else { 182 $('#' + widget_id).remove(); 183 } 184 $('.' + results[i].id).remove(); 185 } else if ( results[i].action.indexOf('filter' ) > -1) { 186 if ( results[i].value == true ) { 187 188 let audio_video = $('.' + results[i].id).find('audio.wp-audio-shortcode,video.wp-video-shortcode'); 189 190 if( audio_video.length ) { 191 $('.' + results[i].id).find('.mejs-container').replaceWith(audio_video); 192 has_media = true; 193 } 194 const html = $('.' + results[i].id).html(); 195 $('.' + results[i].id).replaceWith(html); 196 } 197 $('.' + results[i].id).remove(); 198 } else { 199 $('.' + results[i].id).replaceWith(results[i].value); 200 } 201 } 202 } 203 if( has_media ) { 204 window.wp.mediaelement.initialize(); 205 } 206 if (remove && remove.length) { 207 if( ! geot.is_singular || ( geot.is_singular && ! geot.disable_remove_on_singular ) ){ 208 for (i = 0; i < remove.length; ++i) { 209 let id = remove[i]; 210 let remove_class = '#post-' + id + ', .post-' + id + ',' + 211 '.elementor-jet-woo-products div[data-product-id="'+ id +'"]'; 212 if( geot.remove_class.length ) { 213 remove_class = remove_class + ',' + GeotWP.replaceAll(geot.remove_class,'%id', id); 214 } 215 if( geot.remove_override_class.length ) { 216 remove_class = GeotWP.replaceAll(geot.remove_override_class,'%id', id); 217 } 218 $(remove_class).remove(); 219 } 220 } 221 } 222 if (hide && hide.length) { 223 224 for (i = 0; i < hide.length; ++i) { 225 let id = hide[i].id; 226 let hide_class = '#post-' + id + ' .entry-content,' + 227 '#post-' + id + ' .woocommerce-product-details__short-description,' + 228 '.post-' + id + ' .entry-content,' + 229 '.elementor-widget-container .post-' + id + ',' + 230 '.elementor-jet-woo-products div[data-product-id="'+ id +'"]' + 231 '.post-' + id + ' .woocommerce-product-details__short-description'; 232 if( geot.hide_class.length ) { 233 hide_class = hide_class + ',' + GeotWP.replaceAll(geot.hide_class,'%id', id); 234 } 235 if( geot.hide_override_class.length ) { 236 hide_class = GeotWP.replaceAll(geot.hide_override_class,'%id', id); 237 } 238 $( hide_class ).html('<p>' + hide[i].msg + '</p>'); 239 } 240 } 241 if (debug && debug.length) { 242 $('#geot-debug-info').html(debug); 243 $('.geot-debug-data').html(debug.replace(/<!--|-->/gi, '')); 244 } 245 $(document).trigger('geotwp_ajax_success', response); 246 } 247 } 248 249 const error_cb = function (data, error, errorThrown) { 250 console.log('Geot Ajax error: ' + error + ' - ' + errorThrown); 251 } 252 if ( geot && geot.ajax ) 253 GeotWP.request(data, onSuccess, error_cb); 254 }, 255 replaceAll: function(str, find, replace) { 256 return str.replace(new RegExp(find, 'g'), replace); 257 }, 258 /** 259 * Start the geot dropdown widget 260 */ 261 initSelectize: function() { 262 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))) { 263 geot.dropdown_search = true; 264 } 265 let geot_options = { 266 onChange: function (country_code) { 267 if (!country_code.length) 268 return; 269 GeotWP.createCookie('geot_country', country_code, geot.geot_cookies_duration); 270 GeotWP.createCookie('geot_rocket_country', country_code, geot.geot_cookies_duration); 271 GeotWP.createCookie('STYXKEY_geot_country', country_code, geot.geot_cookies_duration); 272 if (geot.dropdown_redirect && geot.dropdown_redirect.length) { 273 window.location.replace(geot.dropdown_redirect); 274 } else { 275 window.location.reload(); 276 } 277 } 278 }; 279 if ($('.geot_dropdown').data('flags')) { 280 geot_options.render = { 281 option: function (data, escape) { 282 return '<div class="option">' + 283 '<span class="geot-flag flag-' + escape(data.value.toLowerCase()) + '"></span>' + 284 '<span class="url">' + escape(data.text) + '</span>' + 285 '</div>'; 286 }, 287 item: function (data, escape) { 288 return '<div class="item"><span class="geot-flag flag-' + escape(data.value.toLowerCase()) + '"></span>' + escape(data.text) + '</div>'; 289 } 290 }; 291 } 292 if ($('.geot_dropdown').length) { 293 window.geotWP.selectize = []; 294 $('.geot_dropdown').each(function () { 295 let $geot_select = $(this).selectize(geot_options); 296 window.geotWP.selectize.push($geot_select[0].selectize) 297 }) 298 if (GeotWP.readCookie('geot_country')) { 299 window.geotWP.selectize.forEach( function (sel) { 300 sel.addItem(GeotWP.readCookie('geot_country'), true); 301 }) 302 } 303 } 304 }, 305 isMobile : function() { 306 let check = false;
307 (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); 308 return check; 309 }, 310 /** 311 * Detected Browser 312 * Source : https://jsfiddle.net/6spj1059/ 313 * @returns 314 */ 315 initBrowser: function() { 316 // Opera 8.0+ 317 const isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; 318 319 // Firefox 1.0+ 320 const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; 321 322 // Safari 3.0+ "[object HTMLElementConstructor]" 323 const isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification)); 324 325 // Internet Explorer 6-11 326 const isIE = /*@cc_on!@*/false || !!document.documentMode; 327 328 // Edge 20+ 329 const isEdge = !isIE && !!window.StyleMedia; 330 331 // Chrome 1 - 79 332 const isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime); 333 334 335 if( isOpera ) { 336 GeotWP.img_geoloc = geot.geoloc_img_opera; 337 GeotWP.img_consent = geot.geoloc_consent_opera; 338 } else if( isFirefox ) { 339 GeotWP.img_geoloc = geot.geoloc_img_firefox; 340 GeotWP.img_consent = geot.geoloc_consent_firefox; 341 } else if( isSafari ) { 342 GeotWP.img_geoloc = geot.geoloc_img_safari; 343 GeotWP.img_consent = geot.geoloc_consent_safari; 344 } else if( isEdge || isIE ) { 345 GeotWP.img_geoloc = geot.geoloc_img_edge; 346 GeotWP.img_consent = geot.geoloc_consent_edge; 347 } else { 348 GeotWP.img_geoloc = geot.geoloc_img_chrome; 349 GeotWP.img_consent = geot.geoloc_consent_chrome; 350 } 351 }, 352 /** 353 * Generate unique id 354 * @param prefix 355 * @returns {*} 356 */ 357 getUniqueName: function (prefix) { 358 if (! GeotWP.uniqueID) { 359 GeotWP.uniqueID = (new Date()).getTime(); 360 } 361 return prefix + (GeotWP.uniqueID++); 362 }, 363 /** 364 * When Geolocation get the coordinates successfully 365 * @return {[type]} [description] 366 */ 367 successPosition: function(position) { 368 GeotWP.createCookie('geot-gps', 'yes', 999); 369
370 const $overlay = $('div.geotloc_overlay_box'); 371 $overlay.fadeOut('fast'); 372 373 // If first time, refresh 374 if( GeotWP.readCookie('geotRefresh') == null ) { 375 GeotWP.createCookie('geotRefresh', 'yes'); 376 window.location.reload(); 377 } 378 379 GeotWP.lat = position.coords.latitude; 380 GeotWP.lng = position.coords.longitude; 381 sessionStorage.setItem('geot_cords', JSON.stringify({ lat: GeotWP.lat, lng: GeotWP.lng } ) ); 382 383 GeotWP.executeAjax(); 384 }, 385 /** 386 * When Geolocation not get the coordinates 387 * @param OBJ error 388 * @return mixed 389 */ 390 errorPosition: function(error) { 391 GeotWP.createCookie('geot-gps', 'no'); 392 393 const $overlay = $('div.geotloc_overlay_box'); 394 395 if( geot.geoloc_force ) { 396 397 if( ! $overlay.is(':visible') ) 398 GeotWP.show_overlay(); 399 } else { 400 $overlay.fadeOut('fast'); 401 } 402 403 // If first time, refresh 404 if( GeotWP.readCookie('geotRefresh') == null && ! geot.geoloc_force ) { 405 GeotWP.createCookie('geotRefresh', 'yes'); 406 window.location.reload(); 407 } 408 // only run once 409 if( ! window.sessionStorage.getItem('geot_error_position') ) { 410 GeotWP.executeAjax(); 411 } 412 window.sessionStorage.setItem('geot_error_position', 1); 413 }, 414 /** 415 * Put Shadow Overlay 416 * @return mixed 417 */ 418 maybe_overlay: function() { 419 420 const $overlay = $('div.geotloc_overlay_box'); 421 422 if( GeotWP.readCookie('geot-gps') == null && ! /bot|google|baidu|bing|msn|crawl|lteoma|slurp|yandex/i.test(navigator.userAgent) ) { 423 424 GeotWP.show_overlay(); 425 } 426 427 $overlay.find('.geotloc_overlay_remove').on('click', function() { 428 $overlay.fadeOut('fast'); 429 }); 430 }, 431 /** 432 * Show Overlay 433 * @return mixed 434 */ 435 show_overlay: function() { 436 const $overlay = $('div.geotloc_overlay_box'); 437 438 if( geot.geoloc_force ) 439 $overlay.find('div.geotloc_overlay_remove').hide(); 440 else 441 $overlay.find('div.geotloc_overlay_remove').show(); 442 443 $overlay.fadeIn('slow'); 444 }, 445 /** 446 * Create Cookies 447 * @param name 448 * @param value 449 * @param days 450 */ 451 createCookie: function(name, value, days) { 452 let expires = ""; 453 if (days) { 454 let date = new Date(); 455 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 456 expires = "; expires=" + date.toGMTString(); 457 } 458 document.cookie = name + "=" + value + expires + "; path=/"; 459 }, 460 /** 461 * Delete Cookies 462 * @param name 463 * @returns {string|null} 464 */ 465 deleteCookie: function(name) { 466 document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 467 }, 468 /** 469 * Read Cookies 470 * @param name 471 * @returns {string|null} 472 */ 473 readCookie: function(name) { 474 let nameEQ = name + "="; 475 let ca = document.cookie.split(';'); 476 for (let i = 0; i < ca.length; i++) { 477 let c = ca[i]; 478 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 479 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 480 } 481 return null; 482 }, 483 /** 484 * Perform Ajax requests 485 * @param data 486 * @param success_cb 487 * @param error_cb 488 * @param dataType 489 */ 490 request: function (data, success_cb, error_cb, dataType) { 491 // Prepare variables. 492 let ajax = { 493 url: geot.ajax_url, 494 data: data, 495 cache: false, 496 type: 'POST', 497 dataType: 'json', 498 timeout: 30000 499 }, 500 data_type = dataType || false, 501 success = success_cb || false, 502 error = error_cb || false; 503 504 // Set success callback if supplied.
505 if (success) { 506 ajax.success = success; 507 } 508 509 // Set error callback if supplied. 510 if (error) { 511 ajax.error = error; 512 } 513 514 // Change dataType if supplied. 515 if (data_type) { 516 ajax.dataType = data_type; 517 } 518 // Make the ajax request. 519 $.ajax(ajax); 520 521 }, 522 /** 523 * Get parameter from url 524 * @param name 525 * @returns {string} 526 */ 527 getUrlParameter: function(name) { 528 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 529 let regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 530 let results = regex.exec(window.location.search); 531 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); 532 } 533 } 534 535 GeotWP.init(); 536 537 window.geotWP = GeotWP; 538 539})(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.