-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoments.html
More file actions
123 lines (88 loc) · 2.95 KB
/
moments.html
File metadata and controls
123 lines (88 loc) · 2.95 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
<html>
<header>
<title>Moments</title>
<link rel="stylesheet" href="css/moments.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).on('click','#userAnchor',function(){
var username = $(this).text();
localStorage.setItem("userDisp", username);
});
$(document).ready(function(){
var x = 99;
for(i=x;i>89;i--)
body(i);
x=i;
$("#next").click(function(){
if(x>=0){
for(i=x;i>x-10;i--)
body(i);
x-=10;
}
else{
alert("No more posts to show");
}
$('html,body').animate({
scrollTop: $(this).offset().top
}, 1500);
});
console.log(x);
});
function username(content2, userId){
var root = 'https://jsonplaceholder.typicode.com';
var username;
$.ajax({
url: root + '/users',
method: 'GET'
})
.done(function(data) {
userId--;
username = data[userId].username;
var content1 = $('<div id = "post_container"><div id = "usernames">' + '@' +'<a id="userAnchor" href="userprofile.html">'+ username + '</a>' + '<br>');
$("#container3").append(content1);
$("#container3").append(content2);
});
}
function body(i){
var root = 'https://jsonplaceholder.typicode.com';
var title;
var body;
$.ajax({
url: root + '/posts',
method: 'GET'
})
.done(function(data) {
title = data[i].title;
body = data[i].body;
var content2 = ('<div id="post">' +title + '<br>' + body + '<br><br>' + '<span></span></div></div></div>');
username(content2, data[i].userId);
});
}
</script>
</header>
<body class="main">
<div class="container">
<div class="navbar1">
<a href="moments.html">Home</a>
<a href="photos.html">Photos</a>
</div>
</div>
<div class="wrapper">
<div class="container3" id="container3">
<div class="headline">
<h1>Recent Posts</h1>
</div>
<div class="contentPost">
<div id="username">
</div>
</div>
</div>
<div class="buttons">
<div><button id = "next">Next 10 posts</button></div>
</div>
</div>
<div class="footer">
<span>Moments.co</span>
</div>
</body>
</html>