ip-geolocation-api-jquery-sdk
Advanced tools
Comparing version 1.0.9 to 1.1.0
@@ -11,10 +11,14 @@ var _ipgeolocation = function() { | ||
var longitude = ""; | ||
var geolocationEndpoint = "ipgeo"; | ||
var timezoneEndpoint = "timezone"; | ||
var geolocationResponseName = "_ipgeolocation_geolocation"; | ||
var timezoneResponseName = "_ipgeolocation_timezone"; | ||
function request(subUrl, callback, apiKey = "") { | ||
if (useSessionStorage) { | ||
if (subUrl == "ipgeo" && sessionStorage.getItem("_ipGeolocation") && callback) { | ||
callback(JSON.parse(sessionStorage.getItem("_ipGeolocation"))); | ||
if (subUrl == geolocationEndpoint && sessionStorage.getItem(geolocationResponseName) && callback) { | ||
callback(JSON.parse(sessionStorage.getItem(geolocationResponseName))); | ||
return; | ||
} else if (subUrl == "timezone" && sessionStorage.getItem("_ipTimeZone") && callback) { | ||
callback(JSON.parse(sessionStorage.getItem("_ipTimeZone"))); | ||
} else if (subUrl == timezoneEndpoint && sessionStorage.getItem(timezoneResponseName) && callback) { | ||
callback(JSON.parse(sessionStorage.getItem(timezoneResponseName))); | ||
return; | ||
@@ -59,28 +63,32 @@ } | ||
} | ||
$.ajax ({ | ||
async: asyncCall, | ||
method: "GET", | ||
url: "https://api.ipgeolocation.io/".concat(subUrl, urlParameters, ""), | ||
contentType: "application/json", | ||
dataType: "json", | ||
success: function (result, status, xhr) { | ||
if (useSessionStorage) { | ||
if (subUrl == "ipgeo") { | ||
sessionStorage.setItem("_ipGeolocation", JSON.stringify(result)); | ||
} else if (subUrl == "timezone") { | ||
sessionStorage.setItem("_ipTimeZone", JSON.stringify(result)); | ||
var httpRequest; | ||
if (window.XMLHttpRequest) { | ||
httpRequest = new XMLHttpRequest(); | ||
} else if (window.ActiveXObject) { | ||
httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); | ||
} | ||
httpRequest.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
if (useSessionStorage && this.status == 200) { | ||
key = geolocationResponseName; | ||
if (subUrl == timezoneEndpoint) { | ||
key = timezoneResponseName; | ||
} | ||
sessionStorage.setItem(key, this.responseText); | ||
} | ||
if (callback) { | ||
callback(result); | ||
callback(JSON.parse(this.responseText)); | ||
} | ||
}, | ||
error: function (xhr, status, error) { | ||
if (callback) { | ||
callback(JSON.parse(xhr.responseText)); | ||
} | ||
} | ||
}); | ||
}; | ||
httpRequest.open("GET", "https://api.ipgeolocation.io/".concat(subUrl, urlParameters, ""), asyncCall); | ||
httpRequest.setRequestHeader("Accept", "application/json"); | ||
httpRequest.send(); | ||
} | ||
@@ -125,8 +133,8 @@ | ||
getGeolocation: function(callback, apiKey = "") { | ||
request("ipgeo", callback, apiKey); | ||
request(geolocationEndpoint, callback, apiKey); | ||
}, | ||
getTimezone: function(callback, apikey = "") { | ||
request("timezone", callback, apikey); | ||
request(timezoneEndpoint, callback, apikey); | ||
} | ||
} | ||
}(); |
@@ -21,3 +21,3 @@ { | ||
], | ||
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.0.9.tgz", | ||
"_resolved": "https://registry.npmjs.org/ip-geolocation-api-jquery-sdk/-/ip-geolocation-api-jquery-sdk-1.1.0.tgz", | ||
"_shasum": "7afe1f670ee1309eb9effb25818c481c5d855593", | ||
@@ -49,3 +49,3 @@ "_spec": "ip-geolocation-api-jquery-sdk", | ||
}, | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -52,0 +52,0 @@ "type": "git", |
@@ -7,2 +7,4 @@ # IP Geolocation API JQuery SDK | ||
Note: This SDK is compatible with Vanilla JS and doesn't require JQuery as we have dropped the JQuery dependencies from v1.1.0 in this SDK. | ||
Developers can use this JQuery SDK for software and web projects related to, but not limited to: | ||
@@ -34,3 +36,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.9/ipgeolocation.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.1.0/ipgeolocation.min.js"></script> | ||
``` | ||
@@ -123,4 +125,3 @@ | ||
```javascript | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.9/ipgeolocation.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.1.0/ipgeolocation.min.js"></script> | ||
@@ -127,0 +128,0 @@ <script> |
13405
116
162