|
230 | 230 | return markdown; |
231 | 231 | } |
232 | 232 |
|
| 233 | + function initProjectTechTicker() { |
| 234 | + const techNodes = document.querySelectorAll(".project-tech"); |
| 235 | + |
| 236 | + function isDesktop() { |
| 237 | + return window.matchMedia("(min-width: 769px)").matches; |
| 238 | + } |
| 239 | + |
| 240 | + function prepareNode(node) { |
| 241 | + // Only prepare marquee for desktop |
| 242 | + if (!isDesktop()) { |
| 243 | + return; |
| 244 | + } |
| 245 | + |
| 246 | + if (node.querySelector(".project-tech-marquee")) { |
| 247 | + return; |
| 248 | + } |
| 249 | + |
| 250 | + const rawText = node.textContent.trim(); |
| 251 | + node.textContent = ""; |
| 252 | + |
| 253 | + const marquee = document.createElement("div"); |
| 254 | + marquee.className = "project-tech-marquee"; |
| 255 | + |
| 256 | + const itemA = document.createElement("span"); |
| 257 | + itemA.className = "project-tech-item"; |
| 258 | + itemA.textContent = "• " + rawText; |
| 259 | + |
| 260 | + const itemB = document.createElement("span"); |
| 261 | + itemB.className = "project-tech-item"; |
| 262 | + itemB.textContent = "• " + rawText; |
| 263 | + itemB.setAttribute("aria-hidden", "true"); |
| 264 | + |
| 265 | + marquee.appendChild(itemA); |
| 266 | + marquee.appendChild(itemB); |
| 267 | + node.appendChild(marquee); |
| 268 | + } |
| 269 | + |
| 270 | + function removeMarquee(node) { |
| 271 | + const marquee = node.querySelector(".project-tech-marquee"); |
| 272 | + if (marquee) { |
| 273 | + const text = marquee.textContent; |
| 274 | + node.textContent = text; |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + function updateNode(node) { |
| 279 | + const marquee = node.querySelector(".project-tech-marquee"); |
| 280 | + const firstItem = marquee ? marquee.querySelector(".project-tech-item") : null; |
| 281 | + if (!marquee || !firstItem) { |
| 282 | + return; |
| 283 | + } |
| 284 | + |
| 285 | + const itemWidth = Math.max(40, Math.ceil(firstItem.scrollWidth)); |
| 286 | + const pxPerSecond = 30; |
| 287 | + const duration = Math.max(8, itemWidth / pxPerSecond); |
| 288 | + |
| 289 | + node.style.setProperty("--marquee-item-width", itemWidth + "px"); |
| 290 | + node.style.setProperty("--marquee-duration", duration.toFixed(2) + "s"); |
| 291 | + } |
| 292 | + |
| 293 | + techNodes.forEach(function (node) { |
| 294 | + if (isDesktop()) { |
| 295 | + prepareNode(node); |
| 296 | + updateNode(node); |
| 297 | + } else { |
| 298 | + removeMarquee(node); |
| 299 | + } |
| 300 | + }); |
| 301 | + |
| 302 | + let resizeTimeout = null; |
| 303 | + window.addEventListener("resize", function () { |
| 304 | + if (resizeTimeout) { |
| 305 | + window.clearTimeout(resizeTimeout); |
| 306 | + } |
| 307 | + resizeTimeout = window.setTimeout(function () { |
| 308 | + techNodes.forEach(function (node) { |
| 309 | + if (isDesktop()) { |
| 310 | + prepareNode(node); |
| 311 | + updateNode(node); |
| 312 | + } else { |
| 313 | + removeMarquee(node); |
| 314 | + } |
| 315 | + }); |
| 316 | + }, 150); |
| 317 | + }); |
| 318 | + } |
| 319 | + |
233 | 320 | function createReadMoreForCard(card, index) { |
234 | 321 | const titleNode = card.querySelector("h2"); |
235 | 322 | const featuresNode = card.querySelector(".project-features"); |
|
250 | 337 | return; |
251 | 338 | } |
252 | 339 |
|
| 340 | + if (!card.querySelector(".project-description")) { |
| 341 | + const directParagraphs = Array.from(card.children).filter(function (child) { |
| 342 | + return child.tagName === "P"; |
| 343 | + }); |
| 344 | + |
| 345 | + if (directParagraphs.length > 0) { |
| 346 | + const descriptionBlock = document.createElement("div"); |
| 347 | + descriptionBlock.className = "project-description"; |
| 348 | + card.insertBefore(descriptionBlock, directParagraphs[0]); |
| 349 | + directParagraphs.forEach(function (paragraph) { |
| 350 | + descriptionBlock.appendChild(paragraph); |
| 351 | + }); |
| 352 | + } |
| 353 | + } |
| 354 | + |
253 | 355 | const toggleWrap = document.createElement("div"); |
254 | 356 | toggleWrap.className = "project-readmore-toggle-wrap"; |
255 | 357 |
|
|
284 | 386 | } |
285 | 387 |
|
286 | 388 | const cards = document.querySelectorAll(".project-card"); |
| 389 | + initProjectTechTicker(); |
287 | 390 | cards.forEach(createReadMoreForCard); |
288 | 391 | })(); |
0 commit comments