-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
90 lines (79 loc) · 2.27 KB
/
Copy pathindex.js
File metadata and controls
90 lines (79 loc) · 2.27 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fetchDataFromApi = async (search) => {
const result = await axios.get(' http://www.omdbapi.com/', {
params: {
apikey: 'dea96a50',
s: search
}
})
return result.data.Error ? [] : result.data.Search;
}
const fetchElement = async (search) => {
const result = await axios.get(' http://www.omdbapi.com/', {
params: {
apikey: 'dea96a50',
i: search
}
})
return result.data;
}
// debounce
// intit autocomplite
createAutocomplete({
root:document.querySelector('.autocomplete'),
fetchData:fetchDataFromApi,
renderItem(item){
let imgSrc = item.Poster === 'N/A' ? ' ' : item.Poster;
return `
<img src=${imgSrc} />
<h2>${item.Title}(${item.Year})<h2/>
`;
},
onItemSelect(item){onItemSelect(item)},
inputValue(item){
return item.Title;
}
})
// itemDetailTemplete and on select item
const itemDetailTemplete=(itemDetail)=>{
return `
<article class="media">
<figure class="media-img">
<img src="${itemDetail.Poster}" alt="Trulli" style="height: 100px;">
<figcaption>Fig.1 - Trulli, Puglia, Italy.</figcaption>
</figure>
<div class="media-content">
<div class="content">
<h2>${itemDetail.Title}</h2>
<h2>${itemDetail.Genre}</h2>
<p>${itemDetail.Plot}</p>
</div>
</div>
</article>
<article class="notification">
<p>${itemDetail.Awards}</p>
<p>Awards</p>
</article>
<article class="notification">
<p>${itemDetail.BoxOffice}</p>
<p>BoxO ffice</p>
</article>
<article class="notification">
<p>${itemDetail.Metascore}</p>
<p>Meta score</p>
</article>
<article class="notification">
<p>${itemDetail.imdbRating}</p>
<p> imdb Rating</p>
</article>
<article class="notification">
<p>${itemDetail.imdbVotes}</p>
<p> imdb Votes</p>
</article>
`
}
const onItemSelect=async(item)=>{
const itemDetail=await fetchElement(item.imdbID);
let summary=document.getElementById('summary');
summary.innerHTML=itemDetailTemplete(itemDetail);
}
// search