Download tasks/etsy/environment/reference/clone/static/app.js from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 9.69 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/etsy/environment/reference/clone/static/app.js
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/etsy/environment/reference/clone/static/app.js
-
curl -L -o app.js https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/etsy/environment/reference/clone/static/app.js
9.69 kB
| /* Etsy storefront interactions. */ | |
| (function () { | |
| "use strict"; | |
| function ready(fn) { | |
| if (document.readyState !== "loading") { fn(); return; } | |
| document.addEventListener("DOMContentLoaded", fn); | |
| } | |
| ready(function () { | |
| // Source-faithful category menu. It is a real button/overlay on every | |
| // viewport, closes on outside click or Escape, and leaves each menu item | |
| // as a plain link when JavaScript is unavailable. | |
| var toggle = document.querySelector(".cat-toggle"); | |
| var nav = document.getElementById("category-menu"); | |
| var scrim = document.querySelector("[data-category-scrim]"); | |
| if (toggle && nav) { | |
| var setCategoryOpen = function (open) { | |
| toggle.setAttribute("aria-expanded", String(open)); | |
| nav.hidden = !open; | |
| if (scrim) { scrim.hidden = !open; } | |
| }; | |
| toggle.addEventListener("click", function (event) { | |
| event.stopPropagation(); | |
| setCategoryOpen(toggle.getAttribute("aria-expanded") !== "true"); | |
| }); | |
| if (scrim) { scrim.addEventListener("click", function () { setCategoryOpen(false); }); } | |
| document.addEventListener("click", function (event) { | |
| if (!nav.hidden && !nav.contains(event.target)) { setCategoryOpen(false); } | |
| }); | |
| document.addEventListener("keydown", function (event) { | |
| if (event.key === "Escape" && !nav.hidden) { | |
| setCategoryOpen(false); | |
| toggle.focus(); | |
| } | |
| }); | |
| } | |
| // Header search band: an ARIA combobox layered over the real GET form. | |
| // Debounced, single-flight via AbortController, with a monotonic sequence | |
| // guard so a slow early response cannot overwrite a newer one. Every | |
| // suggestion is a query this database actually resolves, so choosing one | |
| // always lands on a real results page. With scripting off the form | |
| // submits to /search exactly as before. | |
| var band = document.querySelector("[data-search-band]"); | |
| if (band) { | |
| var input = band.querySelector("[data-search-input]"); | |
| var list = band.querySelector("[data-search-list]"); | |
| var status = band.querySelector("[data-search-status]"); | |
| var endpoint = band.getAttribute("data-suggest-endpoint"); | |
| var timer = null; | |
| var controller = null; | |
| var sequence = 0; | |
| var settled = 0; | |
| var active = -1; | |
| var closeList = function () { | |
| list.hidden = true; | |
| list.innerHTML = ""; | |
| input.setAttribute("aria-expanded", "false"); | |
| input.removeAttribute("aria-activedescendant"); | |
| active = -1; | |
| }; | |
| var highlight = function (next) { | |
| var options = list.querySelectorAll("[role=option]"); | |
| if (!options.length) { return; } | |
| if (next < 0) { next = options.length - 1; } | |
| if (next >= options.length) { next = 0; } | |
| active = next; | |
| Array.prototype.forEach.call(options, function (option, index) { | |
| var on = index === active; | |
| option.setAttribute("aria-selected", String(on)); | |
| option.classList.toggle("active", on); | |
| if (on) { input.setAttribute("aria-activedescendant", option.id); } | |
| }); | |
| }; | |
| var draw = function (results) { | |
| if (!results.length) { | |
| closeList(); | |
| status.textContent = "No matching searches."; | |
| return; | |
| } | |
| list.innerHTML = ""; | |
| results.forEach(function (result, index) { | |
| var item = document.createElement("li"); | |
| item.id = "global-search-option-" + index; | |
| item.setAttribute("role", "option"); | |
| item.setAttribute("aria-selected", "false"); | |
| var link = document.createElement("a"); | |
| link.href = "/search?q=" + encodeURIComponent(result.query); | |
| link.textContent = result.query; | |
| var count = document.createElement("span"); | |
| count.className = "suggestion-count"; | |
| count.textContent = result.results + " results"; | |
| link.appendChild(count); | |
| item.appendChild(link); | |
| list.appendChild(item); | |
| }); | |
| list.hidden = false; | |
| input.setAttribute("aria-expanded", "true"); | |
| active = -1; | |
| status.textContent = | |
| results.length + (results.length === 1 ? " search" : " searches") + " suggested."; | |
| }; | |
| var fetchSuggestions = function (query) { | |
| if (controller) { controller.abort(); } | |
| controller = new AbortController(); | |
| var ticket = ++sequence; | |
| fetch(endpoint + "?q=" + encodeURIComponent(query), { | |
| signal: controller.signal, | |
| headers: { "Accept": "application/json" } | |
| }) | |
| .then(function (response) { | |
| if (!response.ok) { throw new Error("suggest failed"); } | |
| return response.json(); | |
| }) | |
| .then(function (payload) { | |
| if (ticket <= settled) { return; } | |
| settled = ticket; | |
| draw((payload && payload.results) || []); | |
| }) | |
| .catch(function (error) { | |
| if (error && error.name === "AbortError") { return; } | |
| closeList(); | |
| status.textContent = "Suggestions unavailable. Press Enter to search."; | |
| }); | |
| }; | |
| input.addEventListener("input", function () { | |
| var query = input.value.trim(); | |
| if (timer) { window.clearTimeout(timer); } | |
| if (query.length < 2) { | |
| if (controller) { controller.abort(); } | |
| closeList(); | |
| status.textContent = ""; | |
| return; | |
| } | |
| timer = window.setTimeout(function () { fetchSuggestions(query); }, 180); | |
| }); | |
| input.addEventListener("keydown", function (event) { | |
| if (list.hidden) { return; } | |
| if (event.key === "ArrowDown") { event.preventDefault(); highlight(active + 1); } | |
| else if (event.key === "ArrowUp") { event.preventDefault(); highlight(active - 1); } | |
| else if (event.key === "Escape") { closeList(); } | |
| else if (event.key === "Enter" && active >= 0) { | |
| var chosen = list.querySelectorAll("[role=option] a")[active]; | |
| if (chosen) { event.preventDefault(); window.location.assign(chosen.href); } | |
| } | |
| }); | |
| document.addEventListener("click", function (event) { | |
| if (!band.contains(event.target)) { closeList(); } | |
| }); | |
| closeList(); | |
| } | |
| // Homepage feature carousel. The source controls are buttons that cycle | |
| // through distinct image/copy/CTA panels without navigating away. There | |
| // is deliberately no autoplay, so the page remains stable for keyboard, | |
| // touch, and assistive-technology users. | |
| var carousel = document.querySelector("[data-hero-carousel]"); | |
| if (carousel) { | |
| var slides = Array.prototype.slice.call( | |
| carousel.querySelectorAll("[data-hero-slide]") | |
| ); | |
| var previous = carousel.querySelector('[data-carousel-direction="previous"]'); | |
| var next = carousel.querySelector('[data-carousel-direction="next"]'); | |
| var carouselStatus = carousel.querySelector("[data-carousel-status]"); | |
| var activeSlide = 0; | |
| var showSlide = function (index) { | |
| if (!slides.length) { return; } | |
| activeSlide = (index + slides.length) % slides.length; | |
| slides.forEach(function (slide, slideIndex) { | |
| var active = slideIndex === activeSlide; | |
| slide.hidden = !active; | |
| slide.setAttribute("aria-hidden", String(!active)); | |
| }); | |
| if (carouselStatus) { | |
| carouselStatus.textContent = | |
| "Feature " + (activeSlide + 1) + " of " + slides.length; | |
| } | |
| }; | |
| if (previous) { | |
| previous.addEventListener("click", function () { showSlide(activeSlide - 1); }); | |
| } | |
| if (next) { | |
| next.addEventListener("click", function () { showSlide(activeSlide + 1); }); | |
| } | |
| showSlide(0); | |
| } | |
| // Favourite controls stay real POST forms — this only announces the | |
| // outcome, which a full page navigation would otherwise leave silent for | |
| // a screen-reader user, and marks the toggle state for assistive tech. | |
| document.querySelectorAll(".favorite-form").forEach(function (form) { | |
| var button = form.querySelector("button[type=submit]"); | |
| if (!button) { return; } | |
| var action = form.querySelector("input[name=action]"); | |
| var adding = !action || action.value === "add"; | |
| button.setAttribute("aria-pressed", String(!adding)); | |
| form.addEventListener("submit", function () { | |
| button.setAttribute("data-submitting", "true"); | |
| var live = form.querySelector("[data-favorite-status]"); | |
| if (live) { | |
| live.textContent = adding ? "Adding to favorites…" : "Removing from favorites…"; | |
| } | |
| }); | |
| }); | |
| // First-visit cookie-consent overlay reproduction. Session-scoped | |
| // (sessionStorage) disposable UI state only; Escape and Okay dismiss it. | |
| var overlay = document.getElementById("cookie-overlay"); | |
| if (overlay) { | |
| var seen = false; | |
| try { seen = window.sessionStorage.getItem("cookie-overlay") === "1"; } | |
| catch (error) { seen = true; } | |
| if (!seen) { | |
| overlay.hidden = false; | |
| var okay = overlay.querySelector(".cookie-okay"); | |
| var dismiss = function () { | |
| overlay.hidden = true; | |
| try { window.sessionStorage.setItem("cookie-overlay", "1"); } | |
| catch (error) { /* disposable */ } | |
| }; | |
| if (okay) { | |
| okay.addEventListener("click", dismiss); | |
| okay.focus(); | |
| } | |
| document.addEventListener("keydown", function (event) { | |
| if (event.key === "Escape" && !overlay.hidden) { dismiss(); } | |
| }); | |
| } | |
| } | |
| }); | |
| })(); | |