1jQuery(document).ready(function($){ 2 function usePosition(position) { 3 window.latitude = position.coords.latitude; 4 window.longitude = position.coords.longitude; 5 const now = new Date(); 6 const geo_location = { 7 latitude: position.coords.latitude, 8 longitude: position.coords.longitude, 9 accuracy: position.coords.accuracy, 10 timestamp: position.timestamp 11 }; 12 sessionStorage.setItem("owm_weather_geo_location", JSON.stringify(geo_location)); 13 owmw_get_my_weather(position.coords.latitude, position.coords.longitude); 14 } 15 16 function useIP(err) { 17 const geo_location_no_permission = { 18 permission: "no" 19 } 20 console.warn('ERROR(' + err.code + '): ' + err.message); 21 if (err.code == 1) { 22 sessionStorage.setItem("owm_weather_geo_location_no_permission", JSON.stringify(geo_location_no_permission)); 23 }; 24 owmw_get_my_weather(0, 0); 25 } 26 27 var owm_weather_id = document.getElementsByClassName('owm-weather-id'); 28 var use_geo_location = false; 29 for (var i = 0; i < owm_weather_id.length; i++) { 30 if (jQuery(owm_weather_id[i]).data("geo_location")) { 31 use_geo_location = true; 32 } 33 } 34 35 const geo_location_no_permission_str = sessionStorage.getItem("owm_weather_geo_location_no_permission"); 36 if (!geo_location_no_permission_str && use_geo_location && navigator.geolocation) { 37 const geo_location_str = sessionStorage.getItem("owm_weather_geo_location"); 38 if (!geo_location_str) { 39 navigator.geolocation.getCurrentPosition(usePosition, useIP); 40 } else { 41 const geo_location = JSON.parse(geo_location_str); 42 window.latitude = geo_location.latitude; 43 window.longitude = geo_location.longitude; 44 owmw_get_my_weather(geo_location.latitude, geo_location.longitude); 45 } 46 } else { 47 owmw_get_my_weather(0, 0); 48 } 49}); 50 51function owmw_get_my_weather(latitude, longitude) { 52 var owm_weather_id = document.getElementsByClassName('owm-weather-id'); 53 for(var i = 0; i < owm_weather_id.length; i++) { 54 if (latitude == 0 && longitude == 0) { 55 lat = jQuery(owm_weather_id[i]).data("lat"); 56 lon = jQuery(owm_weather_id[i]).data("lon"); 57 if (lat) { 58 latitude = lat; 59 jQuery(owm_weather_id[i]).removeData("lat"); 60 } 61 if (lon) { 62 longitude = lon; 63 jQuery(owm_weather_id[i]).removeData("lon"); 64 } 65 } 66 jQuery.ajax({ 67 url : owmwAjax.owmw_url, 68 method : 'POST', 69 data : { 70 action: 'owmw_get_my_weather', 71 counter: i, 72 owmw_params : jQuery(owm_weather_id[i]).data(), 73 _ajax_nonce: owmwAjax.owmw_nonce, 74 latitude: latitude, 75 longitude: longitude, 76 }, 77 dataType: 'json', 78 success : function( xhr ) { 79 jQuery('#' + xhr.data.weather).html(xhr.data.html); 80 }, 81 error: function(xhr, status, error){ 82 if (xhr.responseJSON !== undefined) { 83 var data = xhr.responseJSON.data; 84 jQuery('#' + data.weather).append(data.html); 85 } else { 86 var errorMessage = xhr.status + ': ' + xhr.statusText; 87 console.log('OWMW Error - ' + errorMessage); 88 } 89 }, 90 }); 91 } 92} 93 94function owmw_refresh_weather(id) { 95 var owm_weather_id = jQuery("#"+id).closest(".owm-weather-id"); 96 jQuery.ajax({ 97 url : owmwAjax.owmw_url, 98 method : 'POST', 99 data : { 100 action: 'owmw_get_my_weather', 101 counter: 1001, /*bugbug*/ 102 owmw_params : jQuery(owm_weather_id).data(), 103 _ajax_nonce: owmwAjax.owmw_nonce, 104 latitude: window.latitude, 105 longitude: window.longitude, 106 }, 107 dataType: 'json', 108 success : function( xhr ) { 109 jQuery('#' + xhr.data.weather).html(xhr.data.html); 110 }, 111 error: function(xhr, status, error){ 112 if (xhr.responseJSON !== undefined) { 113 var data = xhr.responseJSON.data; 114 jQuery('#' + data.weather).append(data.html); 115 } else { 116 var errorMessage = xhr.status + ': ' + xhr.statusText; 117 console.log('OWMW Error - ' + errorMessage); 118 } 119 }, 120 }); 121}
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.