Main 6

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

/*document.querySelector("[data-toggle='offcanvas']").

addEventListener("click",
function () {
document.getElementById("sidebar").classList.toggle("open");
});

$(document).ready(function () {
// Add a click event listener to the post menu button
$('.custom-icon-btn').on('click', function () {
// Get the post ID from the data attribute
var postId = $(this).parent().data('post-id');

// Toggle the display of the sliding menu for the specific post
$('[data-post-id="' + postId + '"] .sliding-menu').slideToggle();
});
});

$(document).ready(function () {
// Add a click event listener to the post menu button
$('.custom-icon-btn').on('click', function (e) {
e.stopPropagation(); // Prevent the click event from bubbling up to the
document

// Get the post ID and author ID from the data attributes


var postId = $(this).data('post-id');
var postAuthorId = $(this).data('post-author');
var slidingMenu = $('[data-post-id="' + postId + '"] .sliding-menu');

// Toggle the display of the sliding menu for the specific post
slidingMenu.slideToggle();
});

// Add click event listeners for "Edit" and "Delete"


$('.edit-post').on('click', function (e) {
e.preventDefault();
var postId = $(this).closest('.post-menu').data('post-id');
var postAuthorId = $(this).closest('.post-menu').data('post-author');

if (currentUserId == postAuthorId) {
// User is the author, handle edit logic
console.log('Edit post clicked');
} else {
// User is not the author, handle unauthorized access
console.log('Unauthorized access to edit post');
}
});

$('.delete-post').on('click', function (e) {


e.preventDefault();
var postId = $(this).closest('.post-menu').data('post-id');
var postAuthorId = $(this).closest('.post-menu').data('post-author');

if (currentUserId == postAuthorId) {
// User is the author, handle delete logic
console.log('Delete post clicked');
} else {
// User is not the author, handle unauthorized access
console.log('Unauthorized access to delete post');
}
});
});
*/
function deletep() {
if (confirm("Do you really want to delete your account permanently?"))
{
window.location.href = "../waste1/remove_account.php";
}
}

function logout() {
if (confirm("Are you sure you want to log out?")) {
// Add your logout logic here
// For example, you can redirect to a logout page or clear user
session data.
window.location.href = "logs/logout.php";
}
}

$(document).ready(function () {
// Fetch user profile picture using AJAX
$.ajax({
url: 'profile/get_images.php', // Path to your PHP script for fetching
profile picture
type: 'GET',
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
// Check if the profile picture path is empty or null
if (profilePicPath && profilePicPath.trim() !== '') {
// If not empty, display the fetched profile picture
var imgElement = $('<img>').attr('src', 'profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');
$('#profile-picture-container').html(imgElement);
} else {
// If empty, display a default image
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; // Path
to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
$('#profile-picture-container').html(imgElement);
}
} else {
// Handle errors when profile picture is not fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture: ' + error);
}
});
});

const darkModeToggle = document.getElementById('dark-mode-toggle');


const body = document.body;
const navbar = document.querySelector('.navbar');
const sideMenu = document.querySelector('.side-menu');
const menuToggle = document.getElementById('menu-toggle');

// Function to enable dark mode


function enableDarkMode() {
body.classList.add('dark-mode');
navbar.classList.add('navbar-dark', 'bg-dark');
sideMenu.classList.add('bg-dark', 'text-light');
darkModeToggle.textContent = 'Light Mode';
localStorage.setItem('darkMode', 'enabled');
}

// Function to disable dark mode


function disableDarkMode() {
body.classList.remove('dark-mode');
navbar.classList.remove('navbar-dark', 'bg-dark');
sideMenu.classList.remove('bg-dark', 'text-light');
darkModeToggle.textContent = 'Dark Mode';
localStorage.removeItem('darkMode');
}

// Check if user has a preference for dark mode in localStorage


const isDarkMode = localStorage.getItem('darkMode') === 'enabled';

// Set initial dark mode state based on user preference


if (isDarkMode) {
enableDarkMode();
}

darkModeToggle.addEventListener('click', function () {
if (body.classList.contains('dark-mode')) {
disableDarkMode();
} else {
enableDarkMode();
}
});

const navbarCollapse = document.querySelector('.navbar-collapse');


menuToggle.addEventListener('click', function (event) {
event.stopPropagation(); // Prevent the click event from propagating to the
document body
sideMenu.classList.toggle('open');

if (navbarCollapse.classList.contains('show')) {
navbarCollapse.classList.remove('show');
}
});

// Close side menu when user taps anywhere outside of it


document.addEventListener('click', function (event) {
if (sideMenu.classList.contains('open') && !event.target.closest('.side-menu'))
{
sideMenu.classList.remove('open');

}
});

/*

$(document).ready(function () {
// Find all elements with the class 'profile-picture-container'
var profilePictureContainers = document.querySelectorAll('.profile-picture-
container');

// Iterate through each container and make AJAX request for profile picture
profilePictureContainers.forEach(function(container) {
var userId = container.getAttribute('data-user-id');
$.ajax({
url: 'profile/get_image.php', // Path to your PHP script for fetching
profile picture
type: 'GET',
data: { user_id: userId }, // Pass user ID as data to the server-side
script
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
// Check if the profile picture path is empty or null
if (profilePicPath && profilePicPath.trim() !== '') {
// If not empty, display the fetched profile picture
var imgElement = $('<img>').attr('src','profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');
$(container).html(imgElement);
} else {
// If empty, display a default image
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; //
Path to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
$(container).html(imgElement);
}
} else {
// Handle errors when profile picture is not fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture: ' + error);
}
});
});
});

*/

$(document).ready(function () {
// Find all elements with the class 'profile-picture-container'
var profilePictureContainers = document.querySelectorAll('.profile-picture-
container');

// Iterate through each container and make AJAX request for profile picture and
username
profilePictureContainers.forEach(function(container) {
var userId = container.getAttribute('data-user-id');
$.ajax({
url: 'profile/get_image.php', // Path to your PHP script for fetching
profile picture and username
type: 'GET',
data: { user_id: userId }, // Pass user ID as data to the server-side
script
dataType: 'json',
success: function (data) {
if (data.success) {
var profilePicPath = data.profilePicPath;
var username = data.username;

// Check if the profile picture path and username are not empty
or null
if (profilePicPath && profilePicPath.trim() !== '' && username
&& username.trim() !== '') {
// If not empty, display the fetched profile picture and
username

var usernameElement = $
('<span>').text(username).addClass('profile-username');
var imgElement = $('<img>').attr('src', 'profile/' +
profilePicPath).addClass('img-fluid rounded-circle profile-avatar');

$(container).html(usernameElement).append(imgElement);

} else {
// If empty, display a default image and a placeholder
username
var defaultImgPath = 'messages/profile_pics/5022.jpeg'; //
Path to your default profile picture
var imgElement = $('<img>').attr('src',
defaultImgPath).addClass('img-fluid rounded-circle profile-avatar');
var placeholderUsername = 'Unknown User';
var usernameElement = $
('<span>').text(username).addClass('profile-username');
$(container).html(usernameElement).append(imgElement);
}
} else {
// Handle errors when profile picture and username are not
fetched
console.error(data.message);
}
},
error: function (xhr, status, error) {
// Handle AJAX errors, such as network issues
console.error('Error fetching profile picture and username: ' +
error);
}
});
});
});

You might also like