-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexo7.html
More file actions
132 lines (103 loc) · 3.89 KB
/
exo7.html
File metadata and controls
132 lines (103 loc) · 3.89 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Kit de Survie JS</title>
<meta name="description" content="">
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<style>
body{ font-family: 'Quicksand', sans-serif;
margin: 0; }
.leftPanel{
float: left;
width: 200px;
padding: 25px;
background-color: #F9F9F9;
}
.leftPanel input[type=text]{ width: 178px; border: 1px solid #C1C2CC; padding: 10px; font-size: 16px; }
.leftPanel input[type=submit]{ width: 200px; border: none; background-color: orange; color: white; padding: 10px; margin-top: 10px; text-transform: uppercase; font-size: 14px;}
.leftPanel input[type=submit]:hover{ cursor: pointer; }
.leftPanel form{ border-bottom: 1px solid #F1F1F1; padding-bottom: 10px; margin-bottom: 10px;}
.leftPanel a{color: #C1C2CC; }
.centerPanel{padding: 25px; margin-left: 250px; }
</style>
<script src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var items;
$('li[data-id=test]');
var listCharacter = $('.leftPanel > ul');
$.getJSON("http://www.labri.fr/perso/pbiasutt/Cours/KDJS/TD02/characters.php", function(data) {
items = data;
});
//filter
$('form > input[name=search]').keyup(function() {
var filter = $(this).val();
listCharacter.html("");
$.each(items, function(key, val) {
if(val.name.indexOf(filter) != -1)
listCharacter.append("<li><a href='#' data-id='" + val.id + "'>" + val.name + ", id: " + val.id + "</li>");
});
$("a[data-id]").click(function(e) {
e.preventDefault();
charsInfo($(this).attr("data-id"));
});
});
function charsInfo(id) {
var recipient = $('.centerPanel');
//getList
$.getJSON("https://cors.io/?https://anapioficeandfire.com/api/characters/" + id, function(data) {
console.log(data);
recipient.html("<h3><strong>" + data.name + "</strong></h3>");
var charsResult = $("<div class='character-infos'></div>");
charsResult.append($("<p>Gender: " + data.gender + "</p>"));
charsResult.append($("<p>Born: " + data.born + "</p>"));
charsResult.append($("<p>Died: " + data.died + "</p>"));
charsResult.append($("<p>Culture: " + data.culture + "</p>"));
if (data.titles.length != 0) {
charsResult.append($("<p>Titles</p>"));
var titlesList = $("<ul></ul>");
data.titles.forEach(title => { titlesList.append($("<li>" + title + "</li>")); });
charsResult.append(titlesList);
}
if (data.aliases.length != 0) {
charsResult.append($("<p>Aliases</p>"));
var aliasesList = $("<ul></ul>");
data.aliases.forEach(alias => { aliasesList.append($("<li>" + alias + "</li>")); });
charsResult.append(aliasesList);
}
if (data.playedBy.length != 0) {
charsResult.append($("<p>Played By</p>"));
var playedByList = $("<ul></ul>");
data.playedBy.forEach(people => { playedByList.append($("<li>" + people + "</li>")); });
charsResult.append(playedByList);
}
charsResult.append($("<a href='" + data.url + "'>Lien du Personnage - API</a>"));
recipient.append(charsResult);
});
}
});
</script>
</head>
<body>
<div class="leftPanel">
<form action="#" method="get">
<input type="text" name="search" placeholder="Jon Snow ..." />
</form>
Résultats:
<ul>
<li>
<a href="#">R1</a>
</li>
<li>
<a href="#">R2</a>
</li>
<li>
<a href="#">R3</a>
</li>
</ul>
</div>
<div class="centerPanel">
Résultat
</div>
</body>
</html>