| 1 | // The Thinking words page: a live preview of the chosen set on the |
| 2 | // Stardust line, cycling the phrases used between tools. Words are content, so |
| 3 | // they keep changing under reduced motion; only the sparkle is still. |
| 4 | (function () { |
| 5 | "use strict"; |
| 6 | var root = document.querySelector("[data-thinking-words]"); |
| 7 | var line = root && root.querySelector("[data-preview-line]"); |
| 8 | if (!line || !window.EquipoStardust) return; |
| 9 | var words = {}; |
| 10 | try { words = JSON.parse(root.dataset.thinkingWords || "{}"); } catch (e) {} |
| 11 | var situations = ["think"]; |
| 12 | var out = line.querySelector("[data-preview-phrase]"); |
| 13 | line.prepend(window.EquipoStardust.spark(window.EquipoStardust.look)); |
| 14 | var step = 0, randomSet = ""; |
| 15 | function chosen() { |
| 16 | var c = root.querySelector('input[name="set"]:checked'); |
| 17 | return c ? c.value : "professional"; |
| 18 | } |
| 19 | function show() { |
| 20 | var set = chosen(); |
| 21 | if (set === "random") { |
| 22 | // Random: another set each "turn" (each round of situations). |
| 23 | var ids = Object.keys(words).filter(function (k) { return k !== "random"; }); |
| 24 | if (!randomSet || step % situations.length === 0) randomSet = ids[Math.floor(Math.random() * ids.length)]; |
| 25 | set = randomSet; |
| 26 | } |
| 27 | var phrases = (words[set] || {})[situations[step % situations.length]] || []; |
| 28 | var round = Math.floor(step / situations.length); |
| 29 | out.textContent = phrases.length ? phrases[round % phrases.length] : ""; |
| 30 | line.dataset.set = set; |
| 31 | step++; |
| 32 | } |
| 33 | // Picking a set saves it at once (on a phone the button below is easy |
| 34 | // to miss): the page returns with "Saved." and the preview of that set. |
| 35 | root.addEventListener("change", function (e) { |
| 36 | if (e.target.name !== "set") return; |
| 37 | step = 0; randomSet = ""; show(); |
| 38 | var form = e.target.form; |
| 39 | if (form && form.requestSubmit) form.requestSubmit(); |
| 40 | }); |
| 41 | show(); |
| 42 | setInterval(show, 2200); |
| 43 | })(); |
| 44 | |