forked from leotumwattana/omdb-fun-wdi3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (41 loc) · 1.27 KB
/
main.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
// Generated by CoffeeScript 1.6.3
(function() {
$(function() {
var detail, master;
master = function(title) {
return $.ajax({
url: "http://www.omdbapi.com/?s=" + title
}).done(function(data) {
var movie, movies, _i, _len, _results;
movies = $.parseJSON(data)['Search'];
console.log(movies);
_results = [];
for (_i = 0, _len = movies.length; _i < _len; _i++) {
movie = movies[_i];
_results.push($('#movies').append("<li data-imdb=" + movie.imdbID + ">" + movie.Title + "</li>"));
}
return _results;
}).fail(function(j, t, e) {
return console.log(j, t, e);
});
};
master("Harry");
detail = function(imdbID) {
return $.ajax({
url: "http://www.omdbapi.com/?i=" + imdbID + "&tomatoes=true&plot=full"
}).done(function(data) {
var movie;
movie = $.parseJSON(data);
return $('#detail').html('<span>' + movie.Plot + '</span>');
}).fail(function(j, t, e) {
return console.log(j, t, e);
});
};
return $('body').delegate('li', 'click', function(e) {
var imdbID;
console.log(e.target);
imdbID = $(e.target).data('imdb');
return detail(imdbID);
});
});
}).call(this);