Monarth commited on
Commit
ec18068
·
verified ·
1 Parent(s): d601e9f

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +153 -0
script.js ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // --- CONFIGURATION & STATE ---
2
+ const config = {
3
+ localApiUrl: localStorage.getItem('motif_api_url') || null,
4
+ };
5
+
6
+ // --- DOM ELEMENTS ---
7
+ const modal = document.getElementById('guide-modal');
8
+ const showGuideBtn = document.getElementById('show-guide');
9
+ const closeModalBtn = document.querySelector('.close-modal');
10
+ const saveConnectionBtn = document.getElementById('save-connection');
11
+ const apiUrlInput = document.getElementById('api-url');
12
+ const navItems = document.querySelectorAll('.nav-item');
13
+ const sections = document.querySelectorAll('main section');
14
+
15
+ // --- STARTUP BEHAVIOR ---
16
+ document.addEventListener('DOMContentLoaded', () => {
17
+ // 1. Mandatory Setup Guide - Show popup if no API is saved
18
+ if (!config.localApiUrl) {
19
+ openModal();
20
+ } else {
21
+ apiUrlInput.value = config.localApiUrl;
22
+ }
23
+
24
+ // 2. Initialize Cool Cursor Trail Effect
25
+ initializeCursorTrail();
26
+ });
27
+
28
+ // --- UI / NAVIGATION HANDLERS ---
29
+ navItems.forEach(item => {
30
+ item.addEventListener('click', (e) => {
31
+ // Handle Sidebar active state
32
+ navItems.forEach(nav => nav.classList.remove('active'));
33
+ item.classList.add('active');
34
+
35
+ // Handle Main Section visibility (Scrolling effect control)
36
+ const targetSectionId = item.getAttribute('data-target');
37
+ sections.forEach(sec => sec.classList.remove('active-section'));
38
+ document.getElementById(targetSectionId).classList.add('active-section');
39
+ });
40
+ });
41
+
42
+ // --- MODAL / CONNECTION GUIDE LOGIC ---
43
+ function openModal() { modal.classList.add('active-modal'); }
44
+ function closeModal() { modal.classList.remove('active-modal'); }
45
+
46
+ showGuideBtn.addEventListener('click', openModal);
47
+ closeModalBtn.addEventListener('click', closeModal);
48
+ modal.addEventListener('click', (e) => {
49
+ // Close if clicking overlay area outside the content box
50
+ if (e.target === modal) closeModal();
51
+ });
52
+
53
+ saveConnectionBtn.addEventListener('click', () => {
54
+ const enteredUrl = apiUrlInput.value.trim();
55
+ if (enteredUrl) {
56
+ localStorage.setItem('motif_api_url', enteredUrl);
57
+ config.localApiUrl = enteredUrl;
58
+ closeModal();
59
+ alert(`Setup Complete! 🦄 Portal connected to backend at: ${enteredUrl}`);
60
+ } else {
61
+ alert('Please enter your local API address (e.g., http://localhost:7860)');
62
+ }
63
+ });
64
+
65
+ // --- COOL MOUSE EFFECTS (PASTEL CURSOR TRAIL) ---
66
+ function initializeCursorTrail() {
67
+ const trailContainer = document.getElementById('cursor-trail');
68
+ const dots = [];
69
+ const numDots = 12;
70
+
71
+ // Create dots with alternating pastel colors
72
+ for (let i = 0; i < numDots; i++) {
73
+ const dot = document.createElement('div');
74
+ dot.className = 'trail-dot';
75
+ dot.style.backgroundColor = getPastelColor(i);
76
+ trailContainer.appendChild(dot);
77
+ dots.push({ element: dot, x: 0, y: 0 });
78
+ }
79
+
80
+ let mouseX = 0, mouseY = 0;
81
+
82
+ window.addEventListener('mousemove', (e) => {
83
+ mouseX = e.clientX;
84
+ mouseY = e.clientY;
85
+ });
86
+
87
+ // Animation loop for dots lagging smoothly behind cursor
88
+ function animateTrail() {
89
+ let x = mouseX;
90
+ let y = mouseY;
91
+
92
+ dots.forEach((dot, index) => {
93
+ const nextDot = dots[index + 1] || dots[0];
94
+
95
+ dot.x = x;
96
+ dot.y = y;
97
+ dot.element.style.left = x + 'px';
98
+ dot.element.style.top = y + 'px';
99
+ dot.element.style.opacity = 1 - (index / numDots); // Trail fades out
100
+
101
+ // Apply smooth lag effect
102
+ x += (nextDot.x - x) * 0.3;
103
+ y += (nextDot.y - y) * 0.3;
104
+ });
105
+ requestAnimationFrame(animateTrail);
106
+ }
107
+ animateTrail();
108
+ }
109
+
110
+ function getPastelColor(index) {
111
+ const colors = ['#ffe6d9', '#d6eaff', '#fbe0e6', '#e1f7f1']; // Peach, Blue, Pink, Mint
112
+ return colors[index % colors.length];
113
+ }
114
+
115
+ // --- GENERATION LOGIC (CONNECTION PLACEHOLDER) ---
116
+ const generateButtons = document.querySelectorAll('.generate-btn');
117
+ generateButtons.forEach(btn => {
118
+ btn.addEventListener('click', handleGeneration);
119
+ });
120
+
121
+ async function handleGeneration(e) {
122
+ if (!config.localApiUrl) {
123
+ alert("Wait! 🛑 To keep this portal unlimited and free, you must connect to your own powerful local computer first. Click 'Connection Guide'.");
124
+ openModal();
125
+ return;
126
+ }
127
+
128
+ const outputArea = document.getElementById('video-output');
129
+
130
+ // Add loading animation and swell effect
131
+ outputArea.innerHTML = '<span class="status-text">Connecting to local GPU...</span><div class="loading-spinner"></div>';
132
+ outputArea.closest('.animated-frame').classList.add('generating-active');
133
+
134
+ // PLACEHOLDER GENERATION SIMULATION
135
+ // In a real application, you would send a POST request to ${config.localApiUrl} here.
136
+ console.log(`Sending generation request to local backend: ${config.localApiUrl}`);
137
+
138
+ // Simulate backend processing time (4 seconds)
139
+ setTimeout(() => {
140
+ outputArea.innerHTML = ''; // Clear status spinner
141
+
142
+ // Use placeholder output from model card
143
+ const video = document.createElement('video');
144
+ video.src = 'https://huggingface.co/Motif-Technologies/Motif-Video-2B/resolve/main/assets/banner.mp4';
145
+ video.autoplay = true;
146
+ video.loop = true;
147
+ video.controls = true;
148
+ video.style.width = '100%';
149
+ outputArea.appendChild(video);
150
+
151
+ outputArea.closest('.animated-frame').classList.remove('generating-active');
152
+ }, 4000);
153
+ }