01.
$(document).on(
'pageinit'
,
'#home'
,
function
(){
03.
mode =
'search/movie?query='
,
04.
movieName =
'&query='
+encodeURI(
'Batman'
),
05.
key =
'&api_key=5fbddf6b517048e25bc3ac1bbeafb919'
;
06.
07.
$.ajax({
08.
url: url + mode + key + movieName ,
09.
dataType:
"jsonp"
,
10.
async:
true
,
11.
success:
function
(result) {
12.
ajax.parseJSONP(result);
13.
},
14.
error:
function
(request,error) {
15.
alert(
'Network error has occurred please try again!'
);
16.
}
17.
});
18.
});
19.
20.
$(document).on(
'pagebeforeshow'
,
'#headline'
,
function
(){
21.
$(
'#movie-data'
).empty();
22.
$.each(movieInfo.result,
function
(i, row) {
23.
if
(row.id == movieInfo.id) {
25.
$(
'#movie-data'
).append(
'<li>Title: '
+row.original_title+
'</li>'
);
26.
$(
'#movie-data'
).append(
'<li>Release date'
+row.release_date+
'</li>'
);
27.
$(
'#movie-data'
).append(
'<li>Popularity : '
+row.popularity+
'</li>'
);
28.
$(
'#movie-data'
).append(
'<li>Popularity : '
+row.vote_average+
'</li>'
);
29.
$(
'#movie-data'
).listview(
'refresh'
);
30.
}
31.
});
32.
});
33.
34.
$(document).on(
'vclick'
,
'#movie-list li a'
,
function
(){
35.
movieInfo.id = $(
this
).attr(
'data-id'
);
36.
$.mobile.changePage(
"#headline"
, { transition:
"slide"
, changeHash:
false
});
37.
});
38.
39.
var
movieInfo = {
40.
id :
null
,
41.
result :
null
42.
}
43.
44.
var
ajax = {
45.
parseJSONP:
function
(result){
46.
movieInfo.result = result.results;
47.
$.each(result.results,
function
(i, row) {
48.
console.log(JSON.stringify(row));
49.
$(
'#movie-list'
).append(
'<li><a href="" data-id="'
+ row.id +
'"><img src="http://image.tmdb.org/t/p/w92'
+row.poster_path+
'"/><h3>'
+ row.title +
'</h3><p>'
+ row.vote_average +
'/10</p></a></li>'
);
50.
});
51.
$(
'#movie-list'
).listview(
'refresh'
);
52.
}
53.
}