Spaces:
Running
Running
Download script.js from torexdev/telegram-clone-turbo: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/spaces/torexdev/telegram-clone-turbo/resolve/main/script.js
- Command line
-
hf download hf://spaces/torexdev/telegram-clone-turbo/script.js
-
curl -L -o script.js https://huggingface.co/spaces/torexdev/telegram-clone-turbo/resolve/main/script.js
2.53 kB
| document.addEventListener('DOMContentLoaded', () => { | |
| // Sample data for demonstration | |
| const contacts = [ | |
| { id: 1, name: 'John Doe', avatar: 'http://static.photos/people/200x200/1', lastMessage: 'Hey, how are you?', time: '12:30 PM', unread: 2 }, | |
| { id: 2, name: 'Jane Smith', avatar: 'http://static.photos/people/200x200/2', lastMessage: 'Meeting at 3pm', time: '11:45 AM', unread: 0 }, | |
| { id: 3, name: 'Mike Johnson', avatar: 'http://static.photos/people/200x200/3', lastMessage: 'Please send the files', time: 'Yesterday', unread: 5 }, | |
| ]; | |
| // Sample chat messages | |
| const messages = [ | |
| { id: 1, sender: 'them', text: 'Hey there!', time: '12:30 PM' }, | |
| { id: 2, sender: 'me', text: 'Hi! How are you?', time: '12:31 PM' }, | |
| { id: 3, sender: 'them', text: 'I\'m good, thanks for asking. How about you?', time: '12:32 PM' }, | |
| ]; | |
| // Render contacts in sidebar | |
| const renderContacts = () => { | |
| const sidebar = document.querySelector('custom-sidebar'); | |
| if (sidebar) { | |
| sidebar.setAttribute('contacts', JSON.stringify(contacts)); | |
| } | |
| }; | |
| // Render messages in chat area | |
| const renderMessages = () => { | |
| const chatArea = document.querySelector('custom-chat-area'); | |
| if (chatArea) { | |
| chatArea.setAttribute('messages', JSON.stringify(messages)); | |
| chatArea.setAttribute('current-contact', 'John Doe'); | |
| } | |
| }; | |
| renderContacts(); | |
| renderMessages(); | |
| // Mobile menu toggle | |
| document.addEventListener('click', (e) => { | |
| if (e.target.closest('.mobile-menu-toggle')) { | |
| document.querySelector('custom-sidebar').classList.toggle('active'); | |
| } | |
| // Contact item click handler for mobile | |
| if (e.target.closest('.contact-item') && window.innerWidth <= 768) { | |
| document.querySelector('custom-sidebar').classList.remove('active'); | |
| } | |
| }); | |
| // Handle back button in chat area | |
| document.addEventListener('click', (e) => { | |
| if (e.target.closest('.mobile-back-btn')) { | |
| document.querySelector('custom-sidebar').classList.add('active'); | |
| } | |
| }); | |
| // Better touch handling | |
| document.querySelectorAll('.contact-item').forEach(item => { | |
| item.addEventListener('touchstart', () => { | |
| item.classList.add('bg-gray-200'); | |
| }); | |
| item.addEventListener('touchend', () => { | |
| item.classList.remove('bg-gray-200'); | |
| }); | |
| }); | |
| }); |