Skip to content

Commit cd1bf6e

Browse files
committed
Removed jQuery dependecy
1 parent 471fc21 commit cd1bf6e

File tree

6 files changed

+92
-78
lines changed

6 files changed

+92
-78
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.0.1] - 01 Nov 2019
5+
- Removed jQuery dependency.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Javascript SDK for [ImageKit.io](https://imagekit.io) that implements the client
44

55
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
66

7-
This SDK required jQuery, or more specifically the `$.ajax()`, method to be accessible globally.
7+
This SDK has no dependency.
88

99
## Installation
1010

@@ -14,10 +14,9 @@ Download the `imagekit.js` file from the dist directory or using the following c
1414
npm install imagekit-javascript
1515
```
1616

17-
Load it using a `<script>` tag after loading jQuery.
17+
Load it using a `<script>` tag.
1818

1919
```
20-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
2120
<script type="text/javascript" src="imagekit.js"></script>
2221
```
2322

demo/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<input type="file" id="file1" />
77
<input type="submit" />
88
</form>
9-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
109
<script type="text/javascript" src="../dist/imagekit.js"></script>
1110
<script>
1211
try {

dist/imagekit.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3681,44 +3681,51 @@ module.exports = {
36813681

36823682

36833683
module.exports = function(formData, defaultOptions, callback) {
3684-
$.ajax({
3685-
url : defaultOptions.authenticationEndpoint,
3686-
method : "GET",
3687-
dataType : "json",
3688-
success : function(body) {
3689-
if(typeof callback != "function") return;
3690-
3691-
formData.append("signature", body.signature || "");
3692-
formData.append("expire", body.expire || 0);
3693-
formData.append("token", body.token);
3694-
3695-
$.ajax({
3696-
url : "https://api.imagekit.io/v1/files/upload",
3697-
method : "POST",
3698-
mimeType : "multipart/form-data",
3699-
dataType : "json",
3700-
data : formData,
3701-
processData : false,
3702-
contentType : false,
3703-
error : function(jqxhr, text, error) {
3704-
if(typeof callback != "function") return;
3705-
3706-
callback(error);
3707-
},
3708-
success : function(body) {
3709-
if(typeof callback != "function") return;
3710-
3711-
callback(null, body);
3712-
}
3713-
});
3714-
},
3715-
error : function(jqxhr, text, error) {
3716-
console.log(arguments);
3717-
if(typeof callback != "function") return;
3718-
3719-
callback(error);
3684+
var xhr = new XMLHttpRequest();
3685+
xhr.open('GET', defaultOptions.authenticationEndpoint);
3686+
xhr.onload = function() {
3687+
if (xhr.status === 200) {
3688+
try {
3689+
var body = JSON.parse(xhr.responseText);
3690+
formData.append("signature", body.signature || "");
3691+
formData.append("expire", body.expire || 0);
3692+
formData.append("token", body.token);
3693+
3694+
var uploadFileXHR= new XMLHttpRequest();
3695+
uploadFileXHR.open('POST', 'https://api.imagekit.io/v1/files/upload');
3696+
uploadFileXHR.onload = function() {
3697+
if (uploadFileXHR.status === 200) {
3698+
if(typeof callback != "function") return;
3699+
var uploadResponse = JSON.parse(uploadFileXHR.responseText);
3700+
callback(null, uploadResponse);
3701+
}
3702+
else if (uploadFileXHR.status !== 200) {
3703+
if(typeof callback != "function") return;
3704+
callback(JSON.parse(uploadFileXHR.responseText));
3705+
}
3706+
};
3707+
uploadFileXHR.send(formData);
3708+
} catch(ex) {
3709+
console.log(ex);
3710+
if(typeof callback != "function") return;
3711+
callback(ex);
3712+
}
37203713
}
3721-
});
3714+
else {
3715+
try {
3716+
var error = JSON.parse(xhr.responseText);
3717+
console.log(error);
3718+
if(typeof callback != "function") return;
3719+
callback(error);
3720+
} catch (ex) {
3721+
console.log(ex);
3722+
if(typeof callback != "function") return;
3723+
callback(ex);
3724+
}
3725+
}
3726+
};
3727+
xhr.send();
3728+
return;
37223729
}
37233730

37243731

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "index.js",
66
"dependencies": {

utils/request.js

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11

22

33
module.exports = function(formData, defaultOptions, callback) {
4-
$.ajax({
5-
url : defaultOptions.authenticationEndpoint,
6-
method : "GET",
7-
dataType : "json",
8-
success : function(body) {
9-
if(typeof callback != "function") return;
4+
var xhr = new XMLHttpRequest();
5+
xhr.open('GET', defaultOptions.authenticationEndpoint);
6+
xhr.onload = function() {
7+
if (xhr.status === 200) {
8+
try {
9+
var body = JSON.parse(xhr.responseText);
10+
formData.append("signature", body.signature || "");
11+
formData.append("expire", body.expire || 0);
12+
formData.append("token", body.token);
1013

11-
formData.append("signature", body.signature || "");
12-
formData.append("expire", body.expire || 0);
13-
formData.append("token", body.token);
14-
15-
$.ajax({
16-
url : "https://api.imagekit.io/v1/files/upload",
17-
method : "POST",
18-
mimeType : "multipart/form-data",
19-
dataType : "json",
20-
data : formData,
21-
processData : false,
22-
contentType : false,
23-
error : function(jqxhr, text, error) {
24-
if(typeof callback != "function") return;
25-
26-
callback(error);
27-
},
28-
success : function(body) {
29-
if(typeof callback != "function") return;
30-
31-
callback(null, body);
32-
}
33-
});
34-
},
35-
error : function(jqxhr, text, error) {
36-
console.log(arguments);
37-
if(typeof callback != "function") return;
38-
39-
callback(error);
14+
var uploadFileXHR= new XMLHttpRequest();
15+
uploadFileXHR.open('POST', 'https://api.imagekit.io/v1/files/upload');
16+
uploadFileXHR.onload = function() {
17+
if (uploadFileXHR.status === 200) {
18+
if(typeof callback != "function") return;
19+
var uploadResponse = JSON.parse(uploadFileXHR.responseText);
20+
callback(null, uploadResponse);
21+
}
22+
else if (uploadFileXHR.status !== 200) {
23+
if(typeof callback != "function") return;
24+
callback(JSON.parse(uploadFileXHR.responseText));
25+
}
26+
};
27+
uploadFileXHR.send(formData);
28+
} catch(ex) {
29+
console.log(ex);
30+
if(typeof callback != "function") return;
31+
callback(ex);
32+
}
33+
}
34+
else {
35+
try {
36+
var error = JSON.parse(xhr.responseText);
37+
console.log(error);
38+
if(typeof callback != "function") return;
39+
callback(error);
40+
} catch (ex) {
41+
console.log(ex);
42+
if(typeof callback != "function") return;
43+
callback(ex);
44+
}
4045
}
41-
});
46+
};
47+
xhr.send();
48+
return;
4249
}
4350

0 commit comments

Comments
 (0)