forked from leotumwattana/omdb-fun-wdi3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.coffee
42 lines (26 loc) · 813 Bytes
/
main.coffee
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
$ ->
master = (title) ->
$.ajax
url: "http://www.omdbapi.com/?s=#{title}"
.done (data) ->
# console.log data
movies = $.parseJSON(data)['Search']
console.log movies
for movie in movies
# console.log movie.Title
$('#movies').append "<li data-imdb=#{movie.imdbID}>#{movie.Title}</li>"
.fail (j, t, e) ->
console.log j, t, e
master("Harry")
detail = (imdbID) ->
$.ajax
url: "http://www.omdbapi.com/?i=#{imdbID}&tomatoes=true&plot=full"
.done (data) ->
movie = $.parseJSON(data)
$('#detail').html '<span>' + movie.Plot + '</span>'
.fail (j, t, e) ->
console.log j, t, e
$('body').delegate 'li', 'click', (e) ->
console.log e.target
imdbID = $(e.target).data('imdb')
detail(imdbID)