1293 lines
39 KiB
Smarty
1293 lines
39 KiB
Smarty
{include file='header.tpl'}
|
||
{literal}
|
||
<style>input[type=button], input[type=submit] {
|
||
border: none;
|
||
}</style>
|
||
<link rel="stylesheet" href="/sam/messages/Notifications.css">
|
||
<link rel="stylesheet" href="/sam/messages/results.css">
|
||
<link rel="stylesheet" href="/sam/messages/profiles.css">
|
||
<link rel="stylesheet" href="/sam/messages/messages_rev2.css?s=1">
|
||
<link rel="stylesheet" href="/sam/messages/mobile_account_tab.css">
|
||
|
||
|
||
|
||
|
||
<!-- <link rel="stylesheet" href="interesttags.css"> for future interest tagging system (pick your iterests) -->
|
||
|
||
|
||
|
||
<div class="messaging-grid">
|
||
<!-- left of the messages -->
|
||
<div class="messages-notifications" id="messagesLayout">
|
||
|
||
|
||
<div class="messages-actions">
|
||
|
||
<div class="title">Messages <div class="badge-unread">{/literal}{capture assign='unread_messages'}{if $user_unread_pms > 0}{$user_unread_pms}{else}0{/if}{/capture}
|
||
{$unread_messages}{literal}</div></div>
|
||
<!-- search icon -->
|
||
<div class="search-icon"><svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 640 640"><!--!Font Awesome Free v7.0.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#ffffff" d="M480 272C480 317.9 465.1 360.3 440 394.7L566.6 521.4C579.1 533.9 579.1 554.2 566.6 566.7C554.1 579.2 533.8 579.2 521.3 566.7L394.7 440C360.3 465.1 317.9 480 272 480C157.1 480 64 386.9 64 272C64 157.1 157.1 64 272 64C386.9 64 480 157.1 480 272zM272 416C351.5 416 416 351.5 416 272C416 192.5 351.5 128 272 128C192.5 128 128 192.5 128 272C128 351.5 192.5 416 272 416z"/></svg></div>
|
||
<!-- search bar -->
|
||
<div class="messages-search" role="dialog" aria-hidden="true">
|
||
<div class="messages-search__inner">
|
||
<span class="messages-search__icon" aria-hidden="true">
|
||
|
||
<svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 640 640">
|
||
<path fill="#ff5a5a" d="M480 272C480 317.9 465.1 360.3 440 394.7L566.6 521.4C579.1 533.9 579.1 554.2 566.6 566.7C554.1 579.2 533.8 579.2 521.3 566.7L394.7 440C360.3 465.1 317.9 480 272 480C157.1 480 64 386.9 64 272C64 157.1 157.1 64 272 64C386.9 64 480 157.1 480 272zM272 416C351.5 416 416 351.5 416 272C416 192.5 351.5 128 272 128C192.5 128 128 192.5 128 272C128 351.5 192.5 416 272 416z"/>
|
||
</svg>
|
||
</span>
|
||
<input type="text" style="display:none" autocomplete="username" />
|
||
|
||
<input id="messagesSearchInput" name="messagesSearchInput" type="text" placeholder="Search messages…" autocomplete="new-search" value="" />
|
||
<button type="button" class="messages-search__clear" aria-label="Close search">
|
||
<i class="fa fa-times"></i>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<!-- "filter by" buttons -->
|
||
<div class="action-buttons">
|
||
<a class="active" href="#" onclick="filteremails(this, 0);">All</a>
|
||
<a href="#" onclick="filteremails(this, 1);">Unread</a>
|
||
<a href="#" onclick="filteremails(this, 2);">Friends</a>
|
||
<a href="#" onclick="filteremails(this, 3);">Clubs</a>
|
||
</div>
|
||
|
||
|
||
<!-- edit menu + dropdown -->
|
||
<div class="filter-button">
|
||
<button type="button" class="filter-toggle">
|
||
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 640 640"><!--!Font Awesome Free v7.0.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#ffffff" d="M96 128C78.3 128 64 142.3 64 160C64 177.7 78.3 192 96 192L182.7 192C195 220.3 223.2 240 256 240C288.8 240 317 220.3 329.3 192L544 192C561.7 192 576 177.7 576 160C576 142.3 561.7 128 544 128L329.3 128C317 99.7 288.8 80 256 80C223.2 80 195 99.7 182.7 128L96 128zM96 288C78.3 288 64 302.3 64 320C64 337.7 78.3 352 96 352L342.7 352C355 380.3 383.2 400 416 400C448.8 400 477 380.3 489.3 352L544 352C561.7 352 576 337.7 576 320C576 302.3 561.7 288 544 288L489.3 288C477 259.7 448.8 240 416 240C383.2 240 355 259.7 342.7 288L96 288zM96 448C78.3 448 64 462.3 64 480C64 497.7 78.3 512 96 512L150.7 512C163 540.3 191.2 560 224 560C256.8 560 285 540.3 297.3 512L544 512C561.7 512 576 497.7 576 480C576 462.3 561.7 448 544 448L297.3 448C285 419.7 256.8 400 224 400C191.2 400 163 419.7 150.7 448L96 448z"/></svg>
|
||
</button>
|
||
<div class="filter-menu" hidden>
|
||
<div class="filter-item edit-toggle" role="button" tabindex="0" aria-pressed="false" onclick="jQuery('.custom-box').toggle()">Select Messages</div>
|
||
<div class="filter-item" onclick="mark_as_read();">Mark all as Read</div>
|
||
<div class="filter-item"><a href="/settings.php#a05" style="font-weight:normal; color:white;">Settings</a></div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<div class="messages-list" id="messages-list">
|
||
{/literal}
|
||
|
||
{literal}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
<div class="bulk-actions">
|
||
|
||
<button type="button" class="bulk-unread" data-bulk-delete onclick="set_to_unread();jQuery('.custom-box').toggle();">
|
||
Set to Unread
|
||
</button>
|
||
<button type="button" class="bulk-delete" data-bulk-delete onclick="delete_messages(); jQuery('.custom-box').toggle()">
|
||
Delete Messages
|
||
</button>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<!-- chat area -->
|
||
<div class="messages-chat" id="messagesChat">
|
||
<!-- action buttons on top -->
|
||
<div class="action-buttons">
|
||
<button type="button" data-close-chat>← Back</button>
|
||
<button type="button" data-toggle-read onclick="mark_as_unread();">Mark as Unread</button>
|
||
</div>
|
||
|
||
<!-- placeholder before a chat is selected -->
|
||
<div class="messages-chat__placeholder" >
|
||
<h3>Get chatting</h3>
|
||
<p>Select a conversation from the left to start messaging.</p>
|
||
</div>
|
||
|
||
<!-- Chat that appears on the right -->
|
||
<!-- linked via "chat-sophie" -->
|
||
<div class="messages-chat__content " hidden data-chat="chat-sophie">
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
function set_to_unread()
|
||
{
|
||
|
||
var marked = [];
|
||
// Iterate over all checked checkboxes with the class 'myCheckbox'
|
||
jQuery('.bulk-checkbox:checked').each(function() {
|
||
marked.push(jQuery(this).val()); // Push the value to the array
|
||
});
|
||
|
||
if (marked.length > 0) {
|
||
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "misc_js.php",
|
||
data: {
|
||
marked:marked,
|
||
pmconvo_id: "{/literal}{$pmconvo_info.pmconvo_id}{literal}",
|
||
task: "mark_messages_as_unread"
|
||
|
||
}
|
||
}).done(function(data) {
|
||
marked.forEach(function(id) {
|
||
jQuery('article[data-id="'+id+'"]').addClass("unread");
|
||
});
|
||
|
||
});
|
||
}
|
||
}
|
||
function delete_messages()
|
||
{
|
||
|
||
var marked = [];
|
||
// Iterate over all checked checkboxes with the class 'myCheckbox'
|
||
jQuery('.bulk-checkbox:checked').each(function() {
|
||
marked.push(jQuery(this).val()); // Push the value to the array
|
||
});
|
||
|
||
if (marked.length > 0) {
|
||
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "misc_js.php",
|
||
data: {
|
||
marked:marked,
|
||
pmconvo_id: "{/literal}{$pmconvo_info.pmconvo_id}{literal}",
|
||
task: "delete_marked_messages"
|
||
|
||
}
|
||
}).done(function(data) {
|
||
marked.forEach(function(id) {
|
||
jQuery('article[data-id="'+id+'"]').fadeOut();
|
||
});
|
||
|
||
});
|
||
}
|
||
}
|
||
function mark_as_read()
|
||
{
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "user_messages.php?task=markallasread",
|
||
|
||
}).done(function(data) {
|
||
jQuery('article').removeClass("unread");
|
||
|
||
|
||
});
|
||
|
||
}
|
||
function filteremails(clicked, id)
|
||
{
|
||
|
||
jQuery("a").removeClass('active');
|
||
clicked.addClass("active");
|
||
|
||
jQuery("a").removeClass('hidden');
|
||
jQuery(".messages-notification").removeClass('hidden');
|
||
|
||
if(id==1){
|
||
jQuery(".messages-notification").not('.unread').addClass('hidden');
|
||
//jQuery(".noothers").addClass('hidden');
|
||
//jQuery(".club1").addClass('hidden');
|
||
//jQuery(".friend").addClass('hidden');
|
||
}
|
||
else if(id==2){
|
||
jQuery(".messages-notification").not('.friend').addClass('hidden');
|
||
//jQuery(".noothers").addClass('hidden');
|
||
//jQuery(".unread").addClass('hidden');
|
||
//jQuery(".club1").addClass('hidden');
|
||
}
|
||
else if(id==3){
|
||
|
||
jQuery(".messages-notification").not('.club1').addClass('hidden');
|
||
//jQuery(".noothers").addClass('hidden');
|
||
//jQuery(".friend").addClass('hidden');
|
||
//jQuery(".unread").addClass('hidden');
|
||
}
|
||
|
||
}
|
||
|
||
function search_messages()
|
||
{
|
||
|
||
let search=jQuery("#messagesSearchInput").val();
|
||
|
||
|
||
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "misc_js.php",
|
||
data: {
|
||
searchfor: search,
|
||
task: "search_messages"
|
||
|
||
}
|
||
|
||
|
||
}).done(function(data) {
|
||
jQuery( "#messages-list" ).html( data );
|
||
let observer = lozad();
|
||
observer.observe();
|
||
|
||
});
|
||
|
||
|
||
}
|
||
function changecheck(){
|
||
|
||
if (jQuery('#checkAll').is(':checked')) {
|
||
jQuery('.delete').prop('checked',true);
|
||
} else {
|
||
jQuery('.delete').prop('checked', false);
|
||
}
|
||
}
|
||
</script>{/literal}
|
||
|
||
|
||
|
||
|
||
{literal}
|
||
|
||
<!-- stop entering chat when edit mode entered (messages)-->
|
||
<script>
|
||
// Block clicks/taps that start in the checkbox area so links underneath don't fire
|
||
['click','mousedown','mouseup','touchstart','touchend'].forEach(evt => {
|
||
document.addEventListener(evt, (e) => {
|
||
if (e.target.closest('.select-wrap')) {
|
||
e.stopPropagation();
|
||
// If the checkbox/label sits inside an <a>, also cancel navigation:
|
||
const a = e.target.closest('a');
|
||
if (a) e.preventDefault();
|
||
}
|
||
}, true); // <-- capture phase so we beat the anchor's handler/default
|
||
});
|
||
</script>
|
||
|
||
|
||
<!-- Enter bulk edit mode (messages)-->
|
||
<script>
|
||
|
||
(function () {
|
||
|
||
const container = document.querySelector('.messages-notifications');
|
||
if (!container) return;
|
||
|
||
const editBtn = container.querySelector('.filter-item.edit-toggle');
|
||
const deleteBtn = container.querySelector('[data-bulk-delete]');
|
||
const checkboxSelector = '.messages-notification .bulk-checkbox';
|
||
|
||
if (!editBtn || !deleteBtn) return;
|
||
|
||
const getCheckboxes = () =>
|
||
Array.from(container.querySelectorAll(checkboxSelector));
|
||
|
||
function anyChecked() {
|
||
return getCheckboxes().some(cb => cb.checked);
|
||
}
|
||
|
||
function updateSelectionState() {
|
||
const selected = anyChecked();
|
||
container.classList.toggle('has-selection', selected);
|
||
// You can also disable the button when no selection if you like:
|
||
deleteBtn.disabled = !selected;
|
||
}
|
||
|
||
function enterBulkMode() {
|
||
container.classList.add('bulk-mode');
|
||
editBtn.setAttribute('aria-pressed', 'true');
|
||
updateSelectionState(); // make sure state is synced
|
||
}
|
||
|
||
function exitBulkMode({ clear = true } = {}) {
|
||
if (clear) getCheckboxes().forEach(cb => (cb.checked = false));
|
||
container.classList.remove('bulk-mode', 'has-selection');
|
||
editBtn.setAttribute('aria-pressed', 'false');
|
||
deleteBtn.disabled = true;
|
||
}
|
||
|
||
// Toggle Edit Messages
|
||
editBtn.addEventListener('click', () => {
|
||
const inBulk = container.classList.contains('bulk-mode');
|
||
if (inBulk) {
|
||
// leave bulk mode, hide checkboxes and bottom row
|
||
exitBulkMode({ clear: true });
|
||
} else {
|
||
enterBulkMode();
|
||
}
|
||
});
|
||
|
||
// Keyboard support
|
||
editBtn.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Enter' || e.key === ' ') {
|
||
e.preventDefault();
|
||
editBtn.click();
|
||
}
|
||
});
|
||
|
||
// Handle checkbox changes (only inside this container)
|
||
container.addEventListener('change', (e) => {
|
||
const target = e.target;
|
||
if (!(target instanceof HTMLInputElement)) return;
|
||
if (!target.matches(checkboxSelector)) return;
|
||
|
||
// If user hits a checkbox without explicitly pressing edit (edge case)
|
||
if (!container.classList.contains('bulk-mode')) {
|
||
enterBulkMode();
|
||
}
|
||
|
||
updateSelectionState();
|
||
});
|
||
|
||
// Delete button – do your delete logic, then reset UI
|
||
deleteBtn.addEventListener('click', () => {
|
||
// Example: actually remove selected messages (optional)
|
||
// getCheckboxes()
|
||
// .filter(cb => cb.checked)
|
||
// .forEach(cb => cb.closest('.messages-notification')?.remove());
|
||
|
||
// Then reset state as per your spec
|
||
exitBulkMode({ clear: true });
|
||
});
|
||
|
||
// Stop checkbox clicks from triggering links underneath
|
||
['click','mousedown','mouseup','touchstart','touchend'].forEach(evt => {
|
||
container.addEventListener(evt, (e) => {
|
||
if (e.target.closest('.select-wrap')) {
|
||
e.stopPropagation();
|
||
const a = e.target.closest('a');
|
||
if (a) e.preventDefault();
|
||
}
|
||
}, true); // capture phase
|
||
});
|
||
})();
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- Drop downs and mark as read (messages)-->
|
||
<script>
|
||
let loadedmessage=0;
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
search_messages();
|
||
/* ===== Core refs ===== */
|
||
const grid = document.querySelector('.messaging-grid');
|
||
const chatPane = document.getElementById('messagesChat');
|
||
const list = document.querySelector('.messages-notifications .messages-list');
|
||
const backBtn = chatPane?.querySelector('.action-buttons [data-close-chat]');
|
||
const markUnreadBtn = chatPane?.querySelector('.action-buttons [data-toggle-read]');
|
||
const mql = window.matchMedia('(max-width: 1050px)');
|
||
|
||
// Make chatPane keyboard-focusable for ESC handling on mobile
|
||
if (chatPane && !chatPane.hasAttribute('tabindex')) chatPane.setAttribute('tabindex', '-1');
|
||
|
||
/* ===== Mobile tab icon flip ===== */
|
||
function updateMobileTabsByCount(unreadCount) {
|
||
const hasUnread = unreadCount > 0 ? 'true' : 'false';
|
||
const msgs = document.querySelector('.mobile-notifications .messages');
|
||
if (msgs) msgs.setAttribute('data-has-unread', hasUnread);
|
||
|
||
// Optional mirror on notifications tab
|
||
const noti = document.querySelector('.mobile-notifications .notfications');
|
||
if (noti) noti.setAttribute('data-has-unread', hasUnread);
|
||
}
|
||
|
||
/* ===== Read/Unread helpers (multi-instance safe) ===== */
|
||
function dedupUnreadCount() {
|
||
const ids = new Set();
|
||
document.querySelectorAll('.messages-notification.unread[data-chat]').forEach(card => ids.add(card.dataset.chat));
|
||
return ids.size;
|
||
}
|
||
|
||
// Single, canonical version
|
||
function updateUnreadBadges() {
|
||
const count = dedupUnreadCount();
|
||
document.querySelectorAll('[data-unread-count]').forEach(badge => {
|
||
badge.textContent = count;
|
||
badge.style.display = count ? 'inline-flex' : 'none';
|
||
});
|
||
updateMobileTabsByCount(count);
|
||
}
|
||
|
||
function setUnreadForAll(chatId, isUnread) {
|
||
if (!chatId) return;
|
||
document.querySelectorAll(`.messages-notification[data-chat="${chatId}"]`).forEach(card => {
|
||
card.classList.toggle('unread', isUnread);
|
||
const btn = card.querySelector('[data-toggle-read]');
|
||
if (btn) btn.textContent = isUnread ? 'Mark as read' : 'Mark as unread';
|
||
});
|
||
updateUnreadBadges();
|
||
}
|
||
|
||
function deleteChatEverywhere(chatId) {
|
||
if (!chatId) return;
|
||
document.querySelectorAll(`.messages-notification[data-chat="${chatId}"]`).forEach(el => el.remove());
|
||
const content = chatPane?.querySelector(`.messages-chat__content[data-chat="${chatId}"]`);
|
||
if (content) content.remove();
|
||
updateUnreadBadges();
|
||
}
|
||
|
||
/* ===== Chat open/close ===== */
|
||
function showChatContent(chatId) {
|
||
if (!chatPane) return false;
|
||
const blocks = chatPane.querySelectorAll('.messages-chat__content');
|
||
let found = false;
|
||
blocks.forEach(b => {
|
||
if (b.dataset.chat === chatId) { b.removeAttribute('hidden'); found = true; }
|
||
else { b.setAttribute('hidden', ''); }
|
||
});
|
||
return found;
|
||
}
|
||
|
||
function activateChat(chatId, messageId) {
|
||
if (!grid) return;
|
||
const ok = showChatContent(chatId);
|
||
if (!ok) return;
|
||
loadedmessage=messageId;
|
||
jQuery.ajax({
|
||
url: "homestorage/message_view.php?pmconvo_id="+messageId
|
||
//context: document.body
|
||
}).done(function(data) {
|
||
jQuery( ".messages-chat__content" ).html( data );
|
||
|
||
let observer = lozad();
|
||
observer.observe();
|
||
scrollto("#chatContainer-sophie");
|
||
load_page_content();
|
||
});
|
||
|
||
grid.classList.add('has-active-chat');
|
||
if (mql.matches) {
|
||
grid.classList.add('is-chat-open');
|
||
// Move focus so ESC works on mobile
|
||
chatPane?.focus({ preventScroll: true });
|
||
backBtn?.focus();
|
||
|
||
}
|
||
}
|
||
|
||
function closeChat() {
|
||
if (!grid || !chatPane) return;
|
||
if (mql.matches) {
|
||
grid.classList.remove('is-chat-open');
|
||
} else {
|
||
grid.classList.remove('has-active-chat');
|
||
chatPane.querySelectorAll('.messages-chat__content').forEach(b => b.setAttribute('hidden', ''));
|
||
}
|
||
}
|
||
|
||
function getActiveChatId() {
|
||
//const active = chatPane?.querySelector('.messages-chat__content:not([hidden])');
|
||
//return active ? active.dataset.chat : null;
|
||
}
|
||
|
||
/* ===== List interactions ===== */
|
||
if (list) {
|
||
// Open chat from list (ignore controls & dropdowns)
|
||
list.addEventListener('click', (e) => {
|
||
// If the click is on an interactive element or anything tagged not-to-open, skip.
|
||
if (e.target.closest('a, button, input, textarea, [role="button"], [data-no-open]')) return;
|
||
const card = e.target.closest('.messages-notification:not(.inactiveuser)');
|
||
if (!card) return; // click happened in spacing; ignore
|
||
const chatId = card.dataset.chat;
|
||
const messageId = card.dataset.id;
|
||
if (!chatId) return;
|
||
|
||
if (card.classList.contains('unread')) setUnreadForAll(chatId, false); // auto mark read on open
|
||
// Force close any open dropdowns to avoid event interference on mobile
|
||
closeAllMenus();
|
||
activateChat(chatId, messageId);
|
||
});
|
||
|
||
// Per-item toggle read/unread (does NOT open chat)
|
||
list.addEventListener('click', (e) => {
|
||
const toggle = e.target.closest('[data-toggle-read]');
|
||
if (!toggle) return;
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
const card = toggle.closest('.messages-notification[data-chat]');
|
||
if (!card) return;
|
||
const chatId = card.dataset.chat;
|
||
setUnreadForAll(chatId, !card.classList.contains('unread'));
|
||
});
|
||
}
|
||
|
||
/* ===== Action-bar buttons ===== */
|
||
backBtn?.addEventListener('click', (e) => {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
closeChat();
|
||
});
|
||
|
||
// Mark as Unread (in action bar): mark active chat unread + close
|
||
markUnreadBtn?.addEventListener('click', (e) => {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
const chatId = getActiveChatId();
|
||
if (!chatId) return;
|
||
setUnreadForAll(chatId, true);
|
||
closeChat();
|
||
});
|
||
|
||
// ESC closes overlay on mobile
|
||
chatPane?.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Escape' && mql.matches) closeChat();
|
||
});
|
||
|
||
// Resize handling
|
||
mql.addEventListener('change', () => {
|
||
if (!grid || !chatPane) return;
|
||
if (!mql.matches) {
|
||
grid.classList.remove('is-chat-open');
|
||
if (!grid.classList.contains('has-active-chat')) {
|
||
chatPane.querySelectorAll('.messages-chat__content').forEach(b => b.setAttribute('hidden', ''));
|
||
}
|
||
} else {
|
||
// On entering mobile, just ensure overlay is closed until user taps
|
||
grid.classList.remove('is-chat-open');
|
||
}
|
||
});
|
||
|
||
// Initial state
|
||
if (grid && chatPane) {
|
||
if (mql.matches) {
|
||
grid.classList.remove('is-chat-open');
|
||
} else {
|
||
grid.classList.remove('has-active-chat');
|
||
chatPane.querySelectorAll('.messages-chat__content').forEach(b => b.setAttribute('hidden', ''));
|
||
}
|
||
}
|
||
updateUnreadBadges();
|
||
|
||
/* ===== Multi-instance dropdowns attached to .filter-button ===== */
|
||
function menuParts(wrapper) {
|
||
const toggle = wrapper.querySelector('.filter-toggle') || wrapper.querySelector(':scope > button');
|
||
const menu = wrapper.querySelector('.filter-menu') || wrapper.querySelector('.dropdown-menu');
|
||
return { toggle, menu };
|
||
}
|
||
|
||
function openMenu(wrapper) {
|
||
document.querySelectorAll('.filter-button[data-open="true"]').forEach(el => { if (el !== wrapper) closeMenu(el); });
|
||
wrapper.setAttribute('data-open', 'true');
|
||
const { menu } = menuParts(wrapper);
|
||
if (menu) { menu.hidden = false; menu.setAttribute('data-no-open',''); } // prevent list opener
|
||
}
|
||
|
||
function closeMenu(wrapper) {
|
||
wrapper.removeAttribute('data-open');
|
||
const { menu } = menuParts(wrapper);
|
||
if (menu) menu.hidden = true;
|
||
}
|
||
|
||
function closeAllMenus() {
|
||
document.querySelectorAll('.filter-button[data-open="true"]').forEach(closeMenu);
|
||
}
|
||
|
||
// Start closed
|
||
document.querySelectorAll('.filter-button').forEach(wrap => {
|
||
wrap.removeAttribute('data-open');
|
||
const { menu } = menuParts(wrap);
|
||
if (menu) { menu.hidden = true; menu.setAttribute('data-no-open',''); }
|
||
});
|
||
|
||
// Toggle only clicked menu; don’t let menu clicks open chat
|
||
document.addEventListener('click', (e) => {
|
||
const tog = e.target.closest('.filter-button > .filter-toggle, .filter-button > button');
|
||
if (tog) {
|
||
e.preventDefault(); e.stopPropagation();
|
||
const wrap = tog.closest('.filter-button');
|
||
const open = wrap?.getAttribute('data-open') === 'true';
|
||
open ? closeMenu(wrap) : openMenu(wrap);
|
||
return;
|
||
}
|
||
if (e.target.closest('.filter-button .filter-menu, .filter-button .dropdown-menu')) {
|
||
e.stopPropagation(); // block bubbling to list opener
|
||
return;
|
||
}
|
||
closeAllMenus();
|
||
});
|
||
|
||
// Menu item actions (won't open chat)
|
||
document.addEventListener('click', (e) => {
|
||
const item = e.target.closest('.filter-button .dropdown-item, .filter-button .filter-item');
|
||
if (!item || !item.dataset.action) return;
|
||
e.preventDefault(); e.stopPropagation();
|
||
const wrap = item.closest('.filter-button');
|
||
if (item.dataset.action === 'mark-unread') {
|
||
const chatId = getActiveChatId();
|
||
if (chatId) { setUnreadForAll(chatId, true); closeChat(); }
|
||
if (wrap) closeMenu(wrap);
|
||
} else if (item.dataset.action === 'delete') {
|
||
const chatId = getActiveChatId();
|
||
if (chatId) { deleteChatEverywhere(chatId); closeChat(); }
|
||
if (wrap) closeMenu(wrap);
|
||
}
|
||
});
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
<!-- automatically scroll to bottom (messages) -->
|
||
<script>
|
||
function scrollto(el) {
|
||
|
||
|
||
|
||
|
||
var $div = jQuery(el);
|
||
$div.animate({
|
||
scrollTop: $div.get(0).scrollHeight
|
||
}, 100); // 1000ms (1 second) for the animation
|
||
|
||
|
||
}
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
const CHAT_SELECTOR = '.chat[id^="chatContainer-"]';
|
||
|
||
function scrollToBottom(el) {
|
||
requestAnimationFrame(() => {
|
||
el.scrollTop = el.scrollHeight;
|
||
});
|
||
}
|
||
|
||
// Detect when chat containers become visible
|
||
const io = new IntersectionObserver((entries) => {
|
||
entries.forEach(({ target, isIntersecting }) => {
|
||
if (isIntersecting) {
|
||
scrollToBottom(target);
|
||
}
|
||
});
|
||
}, {
|
||
root: null,
|
||
threshold: 0.2
|
||
});
|
||
|
||
// Observe all chat containers on the page
|
||
document.querySelectorAll(CHAT_SELECTOR).forEach((chat) => {
|
||
chat.style.overflowY ||= 'auto';
|
||
io.observe(chat);
|
||
});
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- search bar js (Messages) -->
|
||
<script>
|
||
(() => {
|
||
const bar = document.querySelector('.messages-search');
|
||
const input = document.getElementById('messagesSearchInput');
|
||
const clear = bar?.querySelector('.messages-search__clear');
|
||
const trigger = document.querySelector('.messages-actions .search-icon');
|
||
|
||
if (!bar || !trigger) return;
|
||
|
||
const open = () => {
|
||
bar.classList.add('open');
|
||
trigger.classList.add('active');
|
||
bar.style.top = '0';
|
||
requestAnimationFrame(() => input?.focus());
|
||
};
|
||
|
||
const close = () => {
|
||
bar.classList.remove('open');
|
||
trigger.classList.remove('active');
|
||
if (input) input.value = '';
|
||
};
|
||
|
||
trigger.addEventListener('click', (e) => {
|
||
e.preventDefault();
|
||
bar.classList.contains('open') ? close() : open();
|
||
});
|
||
|
||
clear?.addEventListener('click', (e) => {
|
||
e.preventDefault();
|
||
close();
|
||
});
|
||
|
||
document.addEventListener('click', (e) => {
|
||
if (!bar.classList.contains('open')) return;
|
||
const withinBar = bar.contains(e.target);
|
||
const onTrigger = trigger.contains(e.target);
|
||
if (!withinBar && !onTrigger) close();
|
||
});
|
||
|
||
document.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Escape' && bar.classList.contains('open')) close();
|
||
});
|
||
})();
|
||
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- fade item from unread to read (notifications) -->
|
||
<script>
|
||
|
||
(function () {
|
||
const STORAGE_KEY = "readNotifs_viewSeen:v1";
|
||
const list = document.getElementById("notifList");
|
||
const badge = document.getElementById("badge");
|
||
const markAllBtn = document.getElementById("markAll");
|
||
|
||
const getRead = () => {
|
||
try { return new Set(JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]")); }
|
||
catch { return new Set(); }
|
||
};
|
||
const saveRead = (set) => localStorage.setItem(STORAGE_KEY, JSON.stringify([...set]));
|
||
const readSet = getRead();
|
||
|
||
const items = [...list.querySelectorAll(".notification")];
|
||
|
||
|
||
items.forEach(el => { if (readSet.has(el.dataset.id)) makeRead(el, { persist: false, animate: false }); });
|
||
|
||
|
||
const io = new IntersectionObserver((entries) => {
|
||
entries.forEach(entry => {
|
||
const el = entry.target;
|
||
if (!el.classList.contains("unread")) { io.unobserve(el); return; }
|
||
if (entry.isIntersecting && entry.intersectionRatio >= 0.6) {
|
||
|
||
void el.offsetWidth;
|
||
makeRead(el, { persist: true, animate: true });
|
||
io.unobserve(el);
|
||
}
|
||
});
|
||
}, {
|
||
threshold: [0, 0.6, 1],
|
||
root: null,
|
||
rootMargin: "0px"
|
||
});
|
||
|
||
|
||
items.filter(el => el.classList.contains("unread") && !readSet.has(el.dataset.id))
|
||
.forEach(el => io.observe(el));
|
||
|
||
|
||
list.addEventListener("click", (e) => {
|
||
const card = e.target.closest(".notification");
|
||
if (!card) return;
|
||
|
||
if (e.target.classList.contains("btn-unread")) {
|
||
makeUnread(card, { persist: true });
|
||
|
||
io.observe(card);
|
||
} else {
|
||
makeRead(card, { persist: true, animate: true });
|
||
io.unobserve(card);
|
||
}
|
||
});
|
||
|
||
list.addEventListener("keydown", (e) => {
|
||
if ((e.key === "Enter" || e.key === " ") && e.target.classList.contains("notification")) {
|
||
e.preventDefault();
|
||
makeRead(e.target, { persist: true, animate: true });
|
||
io.unobserve(e.target);
|
||
}
|
||
});
|
||
|
||
function updateBadge() {
|
||
const unreadCount = list.querySelectorAll(".notification.unread").length;
|
||
badge.textContent = unreadCount;
|
||
badge.style.display = unreadCount ? "inline-grid" : "none";
|
||
}
|
||
|
||
// Flip to read; optional animation depends on class ".transition-slow"
|
||
function makeRead(el, { persist = true, animate = true } = {}) {
|
||
if (!el.classList.contains("unread")) return;
|
||
|
||
// Ensure the controllable transition class is present for the 5s fade
|
||
if (animate && !el.classList.contains("transition-slow")) {
|
||
el.classList.add("transition-slow");
|
||
}
|
||
|
||
// Remove transition if we don't want animation (e.g., restoring from storage)
|
||
if (!animate) {
|
||
el.classList.remove("transition-slow");
|
||
}
|
||
|
||
el.classList.remove("unread");
|
||
el.classList.add("read");
|
||
|
||
// Re-attach transition class for future interactions if needed
|
||
if (!animate) {
|
||
// next frame, restore the class so future changes can animate
|
||
requestAnimationFrame(() => el.classList.add("transition-slow"));
|
||
}
|
||
|
||
if (persist) {
|
||
readSet.add(el.dataset.id);
|
||
saveRead(readSet);
|
||
}
|
||
updateBadge();
|
||
}
|
||
|
||
function makeUnread(el, { persist = true } = {}) {
|
||
el.classList.remove("read");
|
||
el.classList.add("unread");
|
||
// keep the transition class so it will animate next time it becomes visible
|
||
if (persist) {
|
||
readSet.delete(el.dataset.id);
|
||
saveRead(readSet);
|
||
}
|
||
updateBadge();
|
||
}
|
||
|
||
// Initial badge render
|
||
updateBadge();
|
||
})();
|
||
</script>
|
||
|
||
|
||
<!-- drop down menu for likes (notifcations)-->
|
||
<script>
|
||
document.addEventListener("DOMContentLoaded", () => {
|
||
const MAX_VISIBLE = 5;
|
||
|
||
const setupUserContainer = (container) => {
|
||
const links = Array.from(container.querySelectorAll("a"));
|
||
if (links.length <= MAX_VISIBLE) return;
|
||
|
||
// Hide all after the 5th
|
||
for (let i = MAX_VISIBLE; i < links.length; i++) {
|
||
links[i].classList.add("hidden");
|
||
}
|
||
|
||
// Create the inline toggle button
|
||
const btn = document.createElement("button");
|
||
btn.type = "button";
|
||
btn.className = "expand-toggle";
|
||
btn.setAttribute("aria-expanded", "false");
|
||
|
||
btn.textContent = `+${links.length - MAX_VISIBLE}`;
|
||
|
||
// Helpers to position the button
|
||
const placeButtonAfterFifth = () => {
|
||
const currentLinks = Array.from(container.querySelectorAll("a"));
|
||
const ref = currentLinks[MAX_VISIBLE]; // node after the 5th <a>
|
||
if (ref) container.insertBefore(btn, ref);
|
||
else container.appendChild(btn);
|
||
};
|
||
|
||
const placeButtonAtEnd = () => {
|
||
container.appendChild(btn);
|
||
};
|
||
|
||
// Initial placement (right after the 5th avatar)
|
||
placeButtonAfterFifth();
|
||
|
||
const expand = () => {
|
||
const currentLinks = Array.from(container.querySelectorAll("a"));
|
||
currentLinks.forEach(a => a.classList.remove("hidden"));
|
||
btn.textContent = "Show Less";
|
||
btn.setAttribute("aria-expanded", "true");
|
||
|
||
// Move the button to the end when expanded
|
||
placeButtonAtEnd();
|
||
};
|
||
|
||
const reduce = () => {
|
||
const currentLinks = Array.from(container.querySelectorAll("a"));
|
||
for (let i = MAX_VISIBLE; i < currentLinks.length; i++) {
|
||
currentLinks[i].classList.add("hidden");
|
||
}
|
||
btn.textContent = `+${currentLinks.length - MAX_VISIBLE}`;
|
||
btn.setAttribute("aria-expanded", "false");
|
||
|
||
// Return the button to the 6th position
|
||
placeButtonAfterFifth();
|
||
};
|
||
|
||
btn.addEventListener("click", () => {
|
||
const expanded = btn.getAttribute("aria-expanded") === "true";
|
||
expanded ? reduce() : expand();
|
||
});
|
||
};
|
||
|
||
document.querySelectorAll(".notification-users").forEach(setupUserContainer);
|
||
});
|
||
</script>
|
||
|
||
<!-- Friend request prompt menu (notifcations)-->
|
||
<script>
|
||
document.addEventListener("DOMContentLoaded", function () {
|
||
document.querySelectorAll('.notification').forEach(notification => {
|
||
const friendsSection = notification.querySelector('.notification-friends');
|
||
if (!friendsSection) return;
|
||
|
||
const confirmBtn = friendsSection.querySelector('.confirm-btn');
|
||
const removeBtn = friendsSection.querySelector('.remove-btn');
|
||
const confirmLink = confirmBtn ? confirmBtn.querySelector('a') : null;
|
||
const removeLink = removeBtn ? removeBtn.querySelector('a') : null;
|
||
|
||
if (!confirmLink || !removeLink) return;
|
||
|
||
// Helper function: update UI based on friendship status
|
||
function setFriendState(isFriends) {
|
||
if (isFriends) {
|
||
// Hide the confirm button
|
||
if (confirmBtn) confirmBtn.style.display = 'none';
|
||
|
||
// Change "Remove" → "Send Message"
|
||
removeLink.textContent = 'Send Message';
|
||
removeLink.setAttribute('href', 'messages.php?to=ThatBiGuy'); // ← adjust dynamically if needed
|
||
removeLink.setAttribute('data-toggle', ''); // remove modal behaviour
|
||
removeLink.setAttribute('data-target', '');
|
||
notification.dataset.friends = 'true';
|
||
|
||
// Optional visual feedback
|
||
notification.classList.add('friend-confirmed');
|
||
} else {
|
||
// Reset to initial state
|
||
if (confirmBtn) confirmBtn.style.display = 'inline-block';
|
||
removeLink.textContent = 'Remove';
|
||
removeLink.setAttribute('href', 'user_friends_manage.php?task=reject&user=ThatBiGuy');
|
||
removeLink.setAttribute('data-toggle', 'modal');
|
||
removeLink.setAttribute('data-target', '#myModal');
|
||
notification.dataset.friends = 'false';
|
||
notification.classList.remove('friend-confirmed');
|
||
}
|
||
}
|
||
|
||
// Initial state setup
|
||
setFriendState(notification.dataset.friends === 'true');
|
||
|
||
// Confirm → switch to "Send Message"
|
||
confirmLink.addEventListener('click', function (e) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
|
||
// TODO: handle backend confirmation call here if desired
|
||
setFriendState(true);
|
||
});
|
||
|
||
// Optional: clicking "Send Message" resets back (for testing/demo)
|
||
removeLink.addEventListener('click', function (e) {
|
||
const isFriends = notification.dataset.friends === 'true';
|
||
if (isFriends) {
|
||
// You can remove this preventDefault() if you want it to open a message page
|
||
// e.preventDefault();
|
||
// e.stopPropagation();
|
||
|
||
// Example: you could redirect manually:
|
||
// window.location.href = removeLink.href;
|
||
}
|
||
});
|
||
});
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<!-- messages drop down -->
|
||
<script>
|
||
const filterBtn = document.querySelector(".notifications-mobile-filters");
|
||
const menu = document.querySelector(".notifications-mobile-filters-menu");
|
||
const closeBtn = document.querySelector(".notifications-close");
|
||
|
||
filterBtn.addEventListener("click", () => {
|
||
menu.classList.add("active-mobile");
|
||
});
|
||
|
||
closeBtn.addEventListener("click", () => {
|
||
menu.classList.remove("active-mobile");
|
||
});
|
||
</script>
|
||
|
||
|
||
<script>
|
||
(function () {
|
||
|
||
|
||
jQuery("#messagesSearchInput").on('keyup', function() {
|
||
search_messages();
|
||
});
|
||
|
||
|
||
|
||
function initPortalDropdown({ btnId, menuId, placement = 'bottom-end', offsetX = 0, offsetY = 8 }) {
|
||
const btn = document.getElementById(btnId);
|
||
const menu = document.getElementById(menuId);
|
||
if (!btn || !menu) return;
|
||
|
||
// Move menu to <body> once
|
||
if (menu.parentNode !== document.body) document.body.appendChild(menu);
|
||
|
||
// Ensure fixed + z-index
|
||
menu.style.position = 'fixed';
|
||
if (!menu.style.zIndex) menu.style.zIndex = 2000;
|
||
|
||
function measureMenu() {
|
||
const hidden = !menu.classList.contains('show');
|
||
if (hidden) {
|
||
menu.style.visibility = 'hidden';
|
||
menu.style.display = 'block';
|
||
}
|
||
const rect = menu.getBoundingClientRect();
|
||
if (hidden) {
|
||
menu.style.display = '';
|
||
menu.style.visibility = '';
|
||
}
|
||
return rect;
|
||
}
|
||
|
||
function positionMenu() {
|
||
const br = btn.getBoundingClientRect();
|
||
const mr = measureMenu();
|
||
let top, left;
|
||
|
||
switch (placement) {
|
||
case 'bottom-start':
|
||
top = br.bottom + offsetY;
|
||
left = br.left + offsetX;
|
||
menu.style.transformOrigin = 'top left';
|
||
break;
|
||
case 'bottom-end': // right aligned under button
|
||
top = br.bottom + offsetY;
|
||
left = br.right - mr.width + offsetX;
|
||
menu.style.transformOrigin = 'top right';
|
||
break;
|
||
case 'top-start':
|
||
top = br.top - mr.height - offsetY;
|
||
left = br.left + offsetX;
|
||
menu.style.transformOrigin = 'bottom left';
|
||
break;
|
||
case 'top-end':
|
||
top = br.top - mr.height - offsetY;
|
||
left = br.right - mr.width + offsetX;
|
||
menu.style.transformOrigin = 'bottom right';
|
||
break;
|
||
default:
|
||
top = br.bottom + offsetY;
|
||
left = br.left + offsetX;
|
||
menu.style.transformOrigin = 'top left';
|
||
}
|
||
|
||
// keep on-screen (simple clamps)
|
||
const minLeft = 8;
|
||
const maxLeft = Math.max(8, window.innerWidth - mr.width - 8);
|
||
left = Math.min(maxLeft, Math.max(minLeft, left));
|
||
|
||
const minTop = 8;
|
||
const maxTop = Math.max(8, window.innerHeight - mr.height - 8);
|
||
top = Math.min(maxTop, Math.max(minTop, top));
|
||
|
||
menu.style.top = `${Math.round(top)}px`;
|
||
menu.style.left = `${Math.round(left)}px`;
|
||
}
|
||
|
||
function openMenu() {
|
||
menu.classList.add('show');
|
||
positionMenu();
|
||
}
|
||
function closeMenu() {
|
||
menu.classList.remove('show');
|
||
}
|
||
|
||
// Toggle this menu only
|
||
btn.addEventListener('click', (e) => {
|
||
e.stopPropagation();
|
||
menu.classList.contains('show') ? closeMenu() : openMenu();
|
||
});
|
||
|
||
// Close this menu when clicking outside of BOTH its button and panel
|
||
/*window.addEventListener('click', (e) => {
|
||
if (!menu.contains(e.target) && !btn.contains(e.target)) closeMenu();
|
||
});*/
|
||
//This prevents a blank messages-list when a mouse click happens
|
||
window.addEventListener('click', (e) => {
|
||
if (!menu.contains(e.target) && !btn.contains(e.target)) {
|
||
// only hide the dropdown menu, not other panels
|
||
menu.classList.remove('show');
|
||
}
|
||
});
|
||
|
||
|
||
// Keep aligned on scroll/resize/orientation
|
||
['resize', 'scroll', 'orientationchange'].forEach(evt => {
|
||
window.addEventListener(evt, () => {
|
||
if (menu.classList.contains('show')) positionMenu();
|
||
});
|
||
});
|
||
|
||
// Escape key closes only this menu
|
||
window.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Escape' && menu.classList.contains('show')) closeMenu();
|
||
});
|
||
|
||
return { openMenu, closeMenu, positionMenu };
|
||
}
|
||
|
||
// Initialise BOTH dropdowns
|
||
window._messagesDD = initPortalDropdown({
|
||
btnId: 'messagesBtn',
|
||
menuId: 'messagesMenu',
|
||
placement: 'bottom-end', // right-align under button
|
||
offsetY: 8
|
||
});
|
||
|
||
window._notificationsDD = initPortalDropdown({
|
||
btnId: 'notificationsBtn',
|
||
menuId: 'notificationsMenu',
|
||
placement: 'bottom-end',
|
||
offsetY: 8
|
||
});
|
||
})();
|
||
</script>
|
||
<script>
|
||
//var host1 = 'wss://vidchat.bateworld.com/ws/';
|
||
//var socket1 = null;
|
||
//var reconnect1=null;
|
||
//var pingInterval1=null;
|
||
|
||
//var socket = new WebSocket(host);
|
||
|
||
function stoptyping(){
|
||
jQuery(".typing").html('');
|
||
}
|
||
|
||
function connect(){
|
||
/*host = 'wss://vidchat.bateworld.com/ws/';
|
||
socket = new WebSocket(host1);
|
||
|
||
socket.onopen = function(e) {
|
||
|
||
if(reconnect1)
|
||
{
|
||
clearTimeout(reconnect1);
|
||
}
|
||
|
||
console.log("[open] Connection established");
|
||
|
||
socket.send(
|
||
JSON.stringify({
|
||
type: "auth",
|
||
authid: "{/literal}{$sessionuser}{literal}"
|
||
}));
|
||
pingInterval=setInterval(function() {
|
||
socket.send(JSON.stringify({ type: "ping" }));console.log("pingto");
|
||
}, 30000);
|
||
|
||
|
||
|
||
};*/
|
||
|
||
|
||
|
||
|
||
//socket.onmessage = function(event) {};
|
||
/*
|
||
socket.onclose = function(event) {
|
||
|
||
|
||
clearInterval(pingInterval);
|
||
|
||
console.log("[close] Connection lost, retrying in 10s...");
|
||
reconnectTimeout1 = setTimeout(connect, 10000);
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
};*/
|
||
|
||
socket.onerror = function(error) {
|
||
//alert("[error] "+error.message);
|
||
};
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
//connect();
|
||
</script>
|
||
{/literal}
|
||
{include file='footer.tpl'} |