-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.php
More file actions
89 lines (76 loc) · 2.92 KB
/
index.php
File metadata and controls
89 lines (76 loc) · 2.92 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
<?php
include('includes/header.php');
if(isset($_POST['post'])) {
//if post button has been pressed ...
$post = new Post($con, $userLoggedIn); //New instance of Post class
$post->submitPost($_POST['post_text'], 'none'); //SubmitPost from Post.php, post_text from form
}
?>
<div class="user_details column">
<a href="<?php echo $userLoggedIn; ?>"> <img src="<?php echo $user['profile_pic']; ?>"> </a>
<div class="user_details_left_right">
<a href="<?php echo $userLoggedIn; ?>">
<?php echo $user['first_name'] . " " . $user['last_name'];?>
</a>
<br>
<?php echo "Posts: " . $user['num_posts']. "<br>";
echo "Likes: " . $user['num_likes']; ?>
</div>
</div>
<div class="main_column column">
<form class="post_form" action="index.php" method="POST">
<textarea name="post_text" id="post_text" placeholder="Thoughts?"></textarea>
<input type="submit" name="post" id="post_button" value="POST">
<hr>
</form>
<div class="posts_area">
</div>
<img src="assets/images/icons/loading.gif" id="loading" alt="loading">
</div>
<!-- INFINITE LOADING -->
<script>
//Loading Icon
var userLoggedIn = '<?php echo $userLoggedIn; ?>';
$(document).ready(function() {
$('#loading').show();
//Ajax Request
$.ajax({
url: 'includes/handlers/ajax_load_posts.php',
type: 'POST',
data: 'page=1&userLoggedIn=' + userLoggedIn,
cache: false,
success: function(data) {
$('#loading').hide();
$('.posts_area').html(data); //Returned data from AJAX
}
});
$(window).scroll(function() {
var height = $('.posts_area').height; //Height of posts container div
var scroll_top = $(this).scrollTop(); //Top of page at any time
var page = $('.posts_area').find('.nextPage').val();
var noMorePosts = $('.posts_area').find('.noMorePosts').val();
if ((document.body.scrollHeight == document.body.scrollTop + window.innerHeight) && noMorePosts == 'false') {
//If height scrolled is top of window plus the height of the window and more posts available
$('#loading').show();
//Ajax Request
var ajaxReq = $.ajax({
url: 'includes/handlers/ajax_load_posts.php',
type: 'POST',
data: 'page=' + page + '&userLoggedIn=' + userLoggedIn,
cache: false,
success: function(data) {
$('.posts_area').find('.nextPage').remove(); //Removes current next page
$('.posts_area').find('.noMorePosts').remove();
$('#loading').hide();
$('.posts_area').append(data); //Returned data from AJAX
}
});
} //End if statement
return false;
}); //End $(window).scroll(function()
}); //Document Ready Close
</script>
<!-- WRAPPER BELOW CLOSE FROM header.php -->
</div>
</body>
</html>