forked from IRON-M4N/pair-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
264 lines (238 loc) · 9.42 KB
/
docs.html
File metadata and controls
264 lines (238 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wanzofc Docs</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #121212;
color: #eee;
margin: 0;
}
.container {
max-width: 1200px; /* Larger container */
width: 90%;
padding: 2rem 1rem; /* Responsive padding */
margin: 0 auto;
}
h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1rem;
color: #f59e0b;
text-align: center; /* Center the title */
}
/* Product Grid */
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); /* Responsive grid, slightly larger items */
gap: 1.5rem; /* More gap */
margin-top: 2rem;
}
.product {
background-color: #1e1e1e;
border-radius: 0.75rem;
overflow: hidden; /* Hide overflowing content */
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5); /* Stronger shadow */
transition: transform 0.3s ease;
position: relative; /* For parallax */
}
.product:hover {
transform: translateY(-5px); /* Lift on hover */
}
.product img {
width: 100%;
height: 200px; /* Fixed height for consistent layout */
object-fit: cover; /* Ensure images cover the area */
display: block; /* Remove extra space below image */
border-bottom: 3px solid #f59e0b; /* Accent border */
}
.product-info {
padding: 1rem;
text-align: center;
}
.product h2 {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: #eee;
}
.product p {
font-size: 1rem;
color: #aaa;
margin-bottom: 0.75rem;
}
.buyButton, .shareButton {
display: inline-block;
padding: 0.5rem 1rem;
margin: 0.25rem;
border: none;
border-radius: 0.375rem;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
font-weight: 500;
}
.buyButton {
background-color: #22c55e; /* Green */
color: #121212;
}
.buyButton:hover {
background-color: #16a34a; /* Darker green */
}
.shareButton {
background-color: #3b82f6; /* Blue */
color: #fff;
}
.shareButton:hover {
background-color: #2563eb; /* Darker blue */
}
#logoutButton {
position: fixed; /* Fixed positioning */
top: 1rem;
right: 1rem;
z-index: 1000;
background-color: #ef4444; /* Red */
color: #fff;
padding: 0.5rem 1rem;
border-radius: 0.375rem;
font-weight: 500;
transition: background-color 0.3s ease;
}
#logoutButton:hover {
background-color: #dc2626; /* Darker red */
}
#logoutButton i {
margin-right: 0.5rem;
}
.parallax-img {
transition: transform 0.8s ease-out; /* Smooth transition */
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11">
</head>
<body>
<div class="container">
<h1 class="animate-title">Daftar Produk</h1>
<button id="logoutButton" class="animate-button"><i class="fas fa-sign-out-alt"></i>Logout</button>
<div id="productContainer" class="product-grid">
<!-- Products will be loaded here -->
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
const productContainer = document.getElementById('productContainer');
const logoutButton = document.getElementById('logoutButton');
// --- GSAP Animations ---
gsap.from(".animate-title", { opacity: 0, y: -50, duration: 1, ease: "power2.out", delay: 0.2 });
gsap.from("#logoutButton", { opacity: 0, x: 50, duration: 1, ease: "power2.out", delay: 0.4 });
// --- Logout ---
logoutButton.addEventListener('click', function() {
localStorage.removeItem('username');
localStorage.removeItem('password');
// Consider also clearing any session cookies here if you implement sessions
window.location.href = '/login/';
});
// --- Display Products ---
function displayProducts(products) {
productContainer.innerHTML = ''; // Clear previous products
products.forEach(product => {
const productDiv = document.createElement('div');
productDiv.classList.add('product', 'animate-product');
productDiv.innerHTML = `
<img src="${product.image}" alt="${product.title}" class="parallax-img">
<div class="product-info">
<h2>${product.title}</h2>
<p>Harga: Rp ${product.price}</p>
<button class="buyButton" data-product-id="${product.id}">Buy</button>
<button class="shareButton" data-product-id="${product.id}">Share</button>
</div>
`;
productContainer.appendChild(productDiv);
// --- Parallax Setup (inside displayProducts) ---
gsap.to(productDiv.querySelector('.parallax-img'), {
yPercent: -10, // Adjust for desired parallax amount
ease: "none",
scrollTrigger: {
trigger: productDiv,
start: "top bottom", // Start when top of product hits bottom of viewport
end: "bottom top", // End when bottom of product hits top of viewport
scrub: true // Smoothly animate based on scroll position
}
});
});
// --- Event delegation for Buy and Share buttons ---
productContainer.addEventListener('click', function(event) {
if (event.target.classList.contains('buyButton')) {
const productId = event.target.dataset.productId;
localStorage.setItem('selectedProductId', productId);
window.location.href = '/message/';
} else if (event.target.classList.contains('shareButton')) {
const productId = event.target.dataset.productId;
const shareUrl = `${window.location.origin}/${generateShortCode(productId)}/${productId}`;
handleShare(shareUrl)
}
});
// --- GSAP animation for products (after adding to DOM) ---
gsap.from(".animate-product", {
opacity: 0,
y: 50,
duration: 0.6,
ease: "power2.out",
stagger: 0.15, // Stagger the appearance of each product
scrollTrigger: { // Trigger when product container comes into view
trigger: "#productContainer",
start: "top 80%", // Start when 80% of the container is visible
}
});
}
async function handleShare(shareUrl) {
const { value: copySuccess } = await Swal.fire({
title: 'Share Product',
input: 'text',
inputValue: shareUrl,
showCancelButton: true,
confirmButtonText: 'Copy URL',
cancelButtonText: 'Cancel',
inputAttributes: {
readonly: true
}
});
if (copySuccess) {
try {
await navigator.clipboard.writeText(shareUrl);
Swal.fire('Copied!', 'The URL has been copied to your clipboard.', 'success');
} catch (err) {
Swal.fire('Error', 'Failed to copy URL: ' + err, 'error');
}
}
}
// --- Helper: Generate Short Code ---
function generateShortCode(productId) {
return Math.random().toString(36).substring(2, 8);
}
// --- Fetch Products ---
fetch('/getProducts')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(products => {
displayProducts(products);
})
.catch(error => {
console.error('Error fetching products:', error);
productContainer.innerHTML = `<p class="text-red-500">Gagal memuat produk: ${error.message}</p>`;
});
// --- Register ScrollTrigger (after GSAP is loaded) ---
gsap.registerPlugin(ScrollTrigger);
</script>
</body>
</html>