-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofilesPosts.php
124 lines (112 loc) · 7.27 KB
/
profilesPosts.php
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
<?php
session_start();
if(isset($_SESSION['username'])){
$userLoggedIn = $_SESSION['username'];
if(isset($_REQUEST['username'])){
$profile_username = $_REQUEST['username'];
}
}else{
header("Location: register.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- add jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<!-- add popper.js -->
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<!-- add bootstrap -->
<link rel="stylesheet" href="assets/css/bootstrap.css">
<script src="assets/js/bootstrap.js"></script>
<!-- add font awesome -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/js/all.min.js"></script>
<!-- custom css -->
<link rel="stylesheet" href="assets/css/style.css">
<style>
body{
background-color:#2d2846;
}
</style>
<!-- <script>
if(localStorage.getItem("timeThrottle") !== null){localStorage.removeItem("timeThrottle")};
</script> -->
</head>
<body>
<div class="profile_posts">
<img src="assets/images/icons/loading.gif" style="margin:auto;" id="loadingProfilePosts" alt="">
</div>
<script id="profileScript" type="text/javascript">
var page = "";
var noMorePosts = "";
var userLoggedIn = "<?php echo $profile_username; ?>";
loadAjaxProfilePosts();
function loadAjaxProfilePosts(){
document.querySelector("#loadingProfilePosts").style.display = "block";
//Original ajax request for loading first posts
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
document.querySelector("#loadingProfilePosts").style.display = "none";
document.querySelector(".profile_posts").innerHTML = this.responseText;
page = document.querySelector(".nextProfilePostsPage").value;
page = parseInt(page);
window.parent.postMessage({winHeight:document.body.offsetHeight,winName: window.name},"*");
}
}
xhttp.open("POST","includes/handlers/fetch_profile_posts.php?page=0&profile_username=<?php echo $profile_username;?>",true);
xhttp.setRequestHeader("Cache-Control","no-store");
xhttp.send();
}
//loading remaining posts on scroll
window.addEventListener('message',(e)=>{
if(e.data.isscrolled == "yes"){
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
var tempVar = document.querySelector(".profile_posts").lastElementChild.className;
if(toString(tempVar) == toString("noMoreProfilePosts")){
var noMorePosts = document.querySelector(".profile_posts").lastElementChild.value;
}
if(noMorePosts == "false"){
if(document.querySelector("#loadingProfilePosts") == null){
document.querySelector(".profile_posts").innerHTML += "<img src='assets/images/icons/loading.gif' id='loadingProfilePosts' style='margin-left:33vw;' alt=''>";
window.parent.postMessage({winHeight:document.body.offsetHeight,winName: window.name},"*");
}
//Original ajax request for loading first posts
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
if(document.querySelector(".nextProfilePostsPage") !== null){
var tempArr = document.querySelectorAll(".profile_posts > input");
var noMorePosts = tempArr[1];
var profileNextPage = tempArr[0];
if(noMorePosts.value == "false"){
document.querySelector(".profile_posts").removeChild(profileNextPage);
var x = document.querySelector(".profile_posts");
document.querySelector(".profile_posts").removeChild(noMorePosts);
document.querySelector("#loadingProfilePosts").style.display = "none";
document.querySelector(".profile_posts").innerHTML += this.responseText;
window.parent.postMessage({winHeight:document.body.offsetHeight,winName: window.name},"*");
}
}
}
}
page = document.querySelector(".nextProfilePostsPage").value;
page = parseInt(page);
xhttp.open("POST","includes/handlers/fetch_profile_posts.php?page=" + page + "&profile_username=<?php echo $profile_username;?>",true);
xhttp.setRequestHeader("Cache-Control","no-store");
xhttp.send();
}
}
return false;
}else if(e.data.rHeight !== null && e.data.rHeight == "true"){
window.parent.postMessage({winHeight:document.body.offsetHeight,winName: window.name},"*");
}else if(e.data.winHeight !== null){
document.getElementsByName(`${e.data.winName}`)[0].height = e.data.winHeight + 10;
window.parent.postMessage({winHeight:document.body.offsetHeight,winName: window.name},"*");
}
});
</script>
</body>
</html>