-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewalbum.html
143 lines (115 loc) · 4.73 KB
/
viewalbum.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
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
133
134
135
136
137
138
139
140
141
142
143
<html>
<head>
<link rel="stylesheet" href="css/viewalbum.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<script>
var albumId = localStorage.getItem("albumId");
var username = localStorage.getItem("userDisp");
$(document).ready(function(){
$("#photoDetails").hide();
albumdetails();
for(x = 0; x < 50; x++)
displayphotos(x);
});
function albumdetails(){
var root = 'https://jsonplaceholder.typicode.com/';
$.ajax({
url: root + 'albums',
data: {
id: albumId
},
dataType: 'json',
method: 'GET',
success: function(data){
var title = data[0].title;
var user = data[0].userId;
$("#albumTitle").append(title);
$.ajax({
url: root + 'users',
data: {
username: username
},
dataType: 'json',
method: 'GET',
success: function(data){
var owner = data[0].name;
console.log(owner);
$("#owner").append("By: " + owner);
}
});
}
});
}
function displayphotos(x){
var root = 'https://jsonplaceholder.typicode.com/';
$.ajax({
url: root + 'photos',
data: {
albumId: albumId
},
dataType: 'json',
method: 'GET',
success: function(data){
var disp = data[x].thumbnailUrl;
var photoId = data[x].id;
$("#thumbnails").append('<a id="photos" onclick="photoClick(this);" photoId="' + photoId + '" ><img src="'+ disp +'" ></a>');
}
});
}
function photoClick(k){
var id = $(k).attr("photoId");
var root = 'https://jsonplaceholder.typicode.com/';
$.ajax({
url: root + 'photos',
data: {
id: id
},
dataType: 'json',
method: 'GET',
success: function(data){
var photo = data[0].url;
var title = data[0].title;
$("#fullsize").replaceWith('<img id="fullsize" src="'+ photo +'">');
$("#photoTitle").replaceWith('<p id="photoTitle">'+ title +'</p><br>');
}
});
$(".container2").hide();
$("#photoDetails").show();
}
function alBack(){
$(".container2").show();
$("#photoDetails").hide();
}
</script>
</head>
<body>
<div class="container">
<div class="navbar1">
<a href="moments.html">Home</a>
<a href="photos.html">Photos</a>
</div>
</div>
<div class="container2">
<div id="top">
<h1 id="albumTitle"></h1>
<h3 id="owner"></h3>
</div>
<div id="thumbnails">
</div>
</div>
<div id="photoDetails">
<div class="backtopage">
<button onclick="alBack();" class="btn">Back to Album</button>
</div>
<div class="photo">
<img id="fullsize" src="">
</div>
<div class="details">
<p id="photoTitle"></p>
</div>
</div>
<div class="footer">
<span>Moments.co</span>
</div>
</body>
</html>