1const STORAGE_KEY = "unga-event-view" 2const VIEWS = ["list", "grid"] 3 4function setView(view, buttons) { 5 if (!VIEWS.includes(view)) { 6 return 7 } 8 9 document.body.classList.remove(...VIEWS) 10 document.body.classList.add(view) 11 12 buttons.forEach((button) => { 13 button.setAttribute("aria-pressed", String(button.dataset.eventView === view)) 14 }) 15} 16 17function getSavedView() { 18 try { 19 const view = window.localStorage.getItem(STORAGE_KEY) 20 return VIEWS.includes(view) ? view : null 21 } catch (error) { 22 console.warn("Unable to read the saved event view.", error) 23 return null 24 } 25} 26 27function saveView(view) { 28 try { 29 window.localStorage.setItem(STORAGE_KEY, view) 30 } catch (error) { 31 console.warn("Unable to save the selected event view.", error) 32 } 33} 34 35export default function eventViewToggle() { 36 const toggle = document.querySelector(".events-view-toggle") 37 38 if (!toggle) { 39 return 40 } 41 42 const buttons = [...toggle.querySelectorAll("[data-event-view]")] 43 const savedView = getSavedView() 44 45 if (savedView) { 46 setView(savedView, buttons) 47 } 48 49 buttons.forEach((button) => { 50 button.addEventListener("click", () => { 51 const view = button.dataset.eventView 52 53 if (!VIEWS.includes(view)) { 54 return 55 } 56 57 setView(view, buttons) 58 saveView(view) 59 }) 60 }) 61}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.