-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.js
More file actions
50 lines (46 loc) · 1.62 KB
/
Code.js
File metadata and controls
50 lines (46 loc) · 1.62 KB
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
var vm;
function Pic(data) {
var self = this;
self.id = data.id;
self.farmid = data.farm;
self.serverid = data.server;
self.secret = data.secret;
self.generatedUrl = "https://farm"+self.farmid+".staticflickr.com/"+self.serverid+"/"+self.id+"_"+self.secret+".jpg";
};
function viewModel(data) {
var self = this;
self.orders = ko.observableArray([]);
self.searchstring = ko.observable("winter");
};
$(document).ready(function() {
vm = new viewModel();
ko.applyBindings(vm);
$.ajax({
dataType: "jsonp",
url: "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=613027bbd85c6531eb248c30795029fb&tags="+vm.searchstring()+"&safe_search=1&per_page=5&format=json&jsoncallback=?",
success: function(data) {
$.each(data.photos.photo, function(idx, obj) {
vm.orders.push(new Pic(obj));
});
},
error: function (xhr, ajaxOptions, thrownError) {
alert('failed');
alert(xhr.responseText);
alert(xhr.status);
alert(ajaxOptions);
alert(thrownError);
}
});
$("#searchbtn").click(function(){
vm.orders([]);
$.ajax({
dataType: "jsonp",
url: "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=613027bbd85c6531eb248c30795029fb&tags="+vm.searchstring()+"&safe_search=1&per_page=5&format=json&jsoncallback=?",
success: function(data) {
$.each(data.photos.photo, function(idx, obj) {
vm.orders.push(new Pic(obj));
});
}
});
});
});