forked from potomak/jquery-instagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.instagram.js
73 lines (61 loc) · 1.9 KB
/
jquery.instagram.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function($){
$.fn.instagram = function(options) {
var that = this,
apiEndpoint = "https://api.instagram.com/v1",
settings = {
hash: null,
accessToken: null,
clientId: null,
show: null,
onLoad: null,
onComplete: null,
maxId: null,
minId: null
};
options && $.extend(settings, options);
function createPhotoElement(photo) {
return $('<div>')
.addClass('instagram-placeholder')
.attr('id', photo.id)
.append(
$('<a>')
.attr('target', '_blank')
.attr('href', photo.link)
.append(
$('<img>')
.addClass('instagram-image')
.attr('src', photo.images.thumbnail.url)
)
);
}
function composeRequestURL() {
var url = apiEndpoint,
params = {};
if(settings.hash != null) {
url += "/tags/" + settings.hash + "/media/recent";
}
else {
url += "/media/popular";
}
settings.accessToken != null && (params.access_token = settings.accessToken);
settings.clientId != null && (params.client_id = settings.clientId);
url += "?" + $.param(params);
return url;
}
settings.onLoad != null && typeof settings.onLoad == 'function' && settings.onLoad();
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: composeRequestURL(),
success: function(res) {
settings.onComplete != null && typeof settings.onComplete == 'function' && settings.onComplete(res.data);
var limit = settings.show == null ? res.data.length : settings.show;
for(var i = 0; i < limit; i++) {
that.append(createPhotoElement(res.data[i]));
}
}
});
return this;
};
})(jQuery);