forked from sgd122/django-site-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_melon.html
105 lines (88 loc) · 3.61 KB
/
test_melon.html
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Melon 검색</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12">
<form id="melon-query-form" class="input-group" style="margin: 20px 0;">
<input type="text" name="q" class="form-control" autocomplete="off" />
<span class="input-group-btn">
<input type="submit" class="btn btn-default" />
</span>
</form>
<ul id="media-list">
</ul>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script id="song-template" type="text/x-template">
<div class="media">
<div class="media-left">
<a href="http://www.melon.com/song/detail.htm?songId=<%= SONGID %>" target="_blank">
<img src="<%= ALBUMIMG %>" class="media-object" style="widwth: 64px; height: 64px;" />
</a>
</div>
<div class="media-body">
<h4>
<a href="http://www.melon.com/song/detail.htm?songId=<%= SONGID %>" target="_blank">
<%= SONGNAME %>
</a>
</h4>
<%= ALBUMNAME %> by
<%= ARTISTNAME %>
</div>
</div>
</script>
<script>
function melon_search(query) {
var params = {
'query': query,
};
$.getJSON('http://www.melon.com/search/keyword/index.json?jscallback=?', params)
.done(function (resp) {
console.log(resp);
$('#media-list').html('');
var tpl = _.template($('#song-template').html());
$(resp.SONGCONTENTS).each(function () {
console.log(this);
// var html = tpl(this);
// $(html).appendTo('#media-list');
$('<div class="media">' +
'<div class="media-left">' +
'<a href="http://www.melon.com/song/detail.htm?songId=' + this.SONGID +
'" target="_blank">' +
'<img src="' + this.ALBUMIMG +
'" class="media-object" style="widwth: 64px; height: 64px;" />' +
'</a>' +
'</div>' +
'<div class="media-body">' +
'<h4>' +
'<a href="http://www.melon.com/song/detail.htm?songId=' + this.SONGID +
'" target="_blank">' +
this.SONGNAME +
'</a>' +
'</h4>' +
this.ALBUMNAME + ' by ' + this.ARTISTNAME +
'</div>' +
'</div>').appendTo('#media-list');
});
});
};
$(function () {
$('#melon-query-form').submit(function (e) {
e.preventDefault()
var q = $(this).find('input[name=q]').val();
melon_search(q);
});
});
</script>
</body>
</html>