Social network theme minor changes

This commit is contained in:
Diego Najar 2019-09-25 20:19:01 +02:00
parent b35172b286
commit 21a48609c2
3 changed files with 85 additions and 18 deletions

View File

@ -85,6 +85,10 @@ blockquote {
height: 64px; height: 64px;
} }
#jsloadMorePosts {
cursor: pointer;
}
/* Image Gallery */ /* Image Gallery */
.image-gallery img { .image-gallery img {
width: 120px; width: 120px;

View File

@ -34,6 +34,11 @@
</div> </div>
</div> </div>
<footer class="container">
<p class="float-right"><a href="#">Back to top</a></p>
<p>© 2017-2018 Company, Inc. · <a href="#">Privacy</a> · <a href="#">Terms</a></p>
</footer>
<!-- Javascript --> <!-- Javascript -->
<?php <?php
// Include Jquery file from Bludit Core // Include Jquery file from Bludit Core
@ -48,7 +53,8 @@
?> ?>
<script> <script>
// Apply to all galleries // Load Light Gallery to all .image-gallery
function loadGallery() {
var galleries = document.getElementsByClassName("image-gallery"); var galleries = document.getElementsByClassName("image-gallery");
for(let i = 0 ; i < galleries.length; i++){ for(let i = 0 ; i < galleries.length; i++){
lightGallery(galleries[i],{ lightGallery(galleries[i],{
@ -57,6 +63,15 @@
download: true download: true
}) })
} }
}
// After page is loaded
window.onload = function() {
// Get all users
getUsers();
// Load Light Gallery
loadGallery()
};
</script> </script>
<!-- Load Bludit Plugins: Site Body End --> <!-- Load Bludit Plugins: Site Body End -->

View File

@ -30,27 +30,72 @@
<script> <script>
// Global variables // Global variables
var _apiToken = "<?php echo $apiToken ?>" var _apiToken = "<?php echo $apiToken ?>";
var _userToken = "<?php echo $user->tokenAuth() ?>" var _userToken = "<?php echo $user->tokenAuth() ?>";
var _pageUUID = Date.now().toString(36) + Math.random().toString(36).substr(2, 15); var _pageUUID = Date.now().toString(36) + Math.random().toString(36).substr(2, 15);
var _pageNumber = 1;
var _itemsPerPage = <?php echo $site->itemsPerPage() ?>;
var _users = {}
function insertPostInTimeline(args) { function getUsers() {
console.log("Getting users.");
fetch("http://localhost:8000/api/users?token="+_apiToken, {
method: "GET"
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log("Getting user. Response >");
console.log(data);
if (data.status=="0") {
_users = data.data;
}
});
}
function getPosts() {
console.log("Getting posts.");
_pageNumber = _pageNumber + 1;
fetch("http://localhost:8000/api/pages?token="+_apiToken+"&pageNumber="+_pageNumber+"&numberOfItems="+_itemsPerPage, {
method: "GET"
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log("Getting posts. Response >");
console.log(data);
if (data.status=="0") {
var posts = data.data;
if (posts.length > 0) {
for (var i = 0; i < posts.length; i++) {
insertPostInTimeline(posts[i], false);
}
}
}
}).then(function() {
loadGallery();
});
}
function insertPostInTimeline(args, beginning=true) {
console.log("Insert post in timeline.");
const postTemplate = ` const postTemplate = `
<div class="card my-2 p-2"> <div class="card my-2 p-2">
<div class="card-body"> <div class="card-body">
<img class="float-left rounded-circle" style="width: 48px" src="${args.srcProfilePicture}" /> <img class="float-left rounded-circle" style="width: 48px" src="${_users[args.username].profilePicture}" />
<div style="padding-left: 56px"> <div style="padding-left: 56px">
<p class="mb-2 text-muted"> <p class="mb-2 text-muted">
@${args.nickname} - ${args.date} @${_users[args.username].nickname} - ${args.date}
</p> </p>
${args.content} ${args.content}
</div> </div>
</div> </div>
</div> </div>
`; `;
console.log(postTemplate);
var listOfPosts = document.getElementById("jslistOfPosts"); var listOfPosts = document.getElementById("jslistOfPosts");
if (beginning) {
listOfPosts.innerHTML = postTemplate + listOfPosts.innerHTML; listOfPosts.innerHTML = postTemplate + listOfPosts.innerHTML;
} else {
listOfPosts.innerHTML = listOfPosts.innerHTML + postTemplate;
}
} }
function getPost(key) { function getPost(key) {
@ -63,8 +108,6 @@ function getPost(key) {
console.log("Getting post. Response >"); console.log("Getting post. Response >");
console.log(data); console.log(data);
if (data.status=="0") { if (data.status=="0") {
data.data.nickname = "<?php echo $user->nickname() ?>";
data.data.srcProfilePicture = "<?php echo $user->profilePicture() ?>";
insertPostInTimeline(data.data); insertPostInTimeline(data.data);
} }
}); });
@ -139,7 +182,6 @@ document.getElementById("jspostButton").onclick = function(event) {
document.getElementById("jspreviewImages").innerHTML = ""; document.getElementById("jspreviewImages").innerHTML = "";
} }
</script> </script>
<?php endif; ?> <?php endif; ?>
@ -187,3 +229,9 @@ document.getElementById("jspostButton").onclick = function(event) {
</div> </div>
<?php endforeach ?> <?php endforeach ?>
</div> </div>
<div id="jsloadMorePosts" onclick="getPosts()" class="card my-2 p-2">
<div class="card-body text-center">
<p class="m-0">Load more posts</p>
</div>
</div>