Skip to content
wiki.fftac.org

Theme - Source Excerpt 02

Back to Theme

Summary

This source excerpt preserves a bounded section of 2IA.org/wp-content/themes/twoia-intelligence/assets/js/theme.js so readers can inspect the evidence without opening the full source file.

**Source path:** 2IA.org/wp-content/themes/twoia-intelligence/assets/js/theme.js

if (!dataNode) {
        return;
      }

      try {
        data = JSON.parse(dataNode.textContent || '{}');
      } catch (error) {
        return;
      }

      var state = {
        issue: data.default && data.default.issue ? data.default.issue : 'records',
        goal: data.default && data.default.goal ? data.default.goal : 'records',
        urgency: data.default && data.default.urgency ? data.default.urgency : 'research',
        evidence: data.default && data.default.evidence ? data.default.evidence : 'none'
      };

      var copyButton = wizard.querySelector('[data-who-cares-copy]');
      var currentPlanText = '';

      function updateButtons() {
        var buttons = wizard.querySelectorAll('[data-choice-type]');

        buttons.forEach(function (button) {
          var type = button.getAttribute('data-choice-type');
          var value = button.getAttribute('data-choice-value');
          var active = state[type] === value;

          button.setAttribute('aria-pressed', active ? 'true' : 'false');
          button.classList.toggle('is-active', active);
        });
      }

      function render() {
        var profile = getChoice(data, 'profiles', state.issue) || getChoice(data, 'profiles', 'records');
        var goal = getChoice(data, 'goals', state.goal) || getChoice(data, 'goals', 'records');
        var urgency = getChoice(data, 'urgency', state.urgency) || getChoice(data, 'urgency', 'research');
        var evidence = getChoice(data, 'evidence', state.evidence) || getChoice(data, 'evidence', 'none');
        var firstMove = goal.note + ' ' + urgency.note + ' ' + evidence.note;

        setText(wizard, '[data-who-cares-route]', profile.short + ' / ' + goal.label);
        setText(wizard, '[data-who-cares-title]', profile.label);
        setText(wizard, '[data-who-cares-broken]', profile.broken);
        setText(wizard, '[data-who-cares-who]', profile.who);
        setText(wizard, '[data-who-cares-demand]', profile.demand);
        setText(wizard, '[data-who-cares-first]', firstMove);
        setText(wizard, '[data-who-cares-avoid]', profile.avoid);
        renderTextList(wizard, '[data-who-cares-records]', profile.records);
        renderLinkList(wizard, '[data-who-cares-internal]', profile.internal, false);
        renderLinkList(wizard, '[data-who-cares-external]', profile.external, true);

        currentPlanText = buildPlanText(state, profile, goal, urgency, evidence);

        if (copyButton) {
          copyButton.textContent = copyButton.getAttribute('data-default-label') || 'Copy pressure map';
        }

        updateButtons();
      }

      wizard.querySelectorAll('[data-choice-type]').forEach(function (button) {
        button.addEventListener('click', function () {
          var type = button.getAttribute('data-choice-type');
          var value = button.getAttribute('data-choice-value');

          if (!type || !value) {
            return;
          }

          state[type] = value;

          if (type === 'issue' && value === 'safety') {
            state.urgency = 'now';
          }

          render();
        });
      });

      if (copyButton) {
        copyButton.setAttribute('data-default-label', copyButton.textContent);
        copyButton.addEventListener('click', function () {
          var successText = 'Pressure map copied';

          if (!currentPlanText) {
            render();
          }

          if (!navigator.clipboard) {
            window.prompt('Copy this pressure map:', currentPlanText);
            return;
          }

          navigator.clipboard.writeText(currentPlanText).then(function () {
            copyButton.textContent = successText;
            window.setTimeout(function () {
              copyButton.textContent = copyButton.getAttribute('data-default-label') || 'Copy pressure map';
            }, 1800);
          }).catch(function () {
            window.prompt('Copy this pressure map:', currentPlanText);
          });
        });
      }

      render();
    });
  }

  ready(function () {
    setupMobileMenu();
    setupSearchOverlay();
    setupAnnouncementBar();
    setupCopyLink();
    setupCopyTextButtons();
    setupTableOfContents();
    setupSignalMotion();
    setupWhoCaresWizard();
  });
}());