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

return [
        'Who Cares pressure map',
        'System: ' + profile.label,
        'Need: ' + goal.label,
        'Urgency: ' + urgency.label,
        'Proof: ' + evidence.label,
        '',
        'What is broken: ' + profile.broken,
        '',
        'Who cares: ' + profile.who,
        '',
        'Records to pull:',
        records,
        '',
        'Demand: ' + profile.demand,
        '',
        'First move: ' + goal.note + ' ' + urgency.note + ' ' + evidence.note,
        '',
        'Do not do this: ' + profile.avoid
      ].join('\n');
    }

    wizards.forEach(function (wizard) {
      var dataNode = wizard.querySelector('[data-who-cares-data]');
      var data;

      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 downloadButton = wizard.querySelector('[data-who-cares-download]');
      var printButton = wizard.querySelector('[data-who-cares-print]');
      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);
          });
        });
      }

      if (downloadButton) {
        downloadButton.addEventListener('click', function () {
          var text = currentPlanText || '';
          var blob;
          var url;
          var link;

          if (!text) {
            render();
            text = currentPlanText;
          }

          blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
          url = window.URL.createObjectURL(blob);
          link = document.createElement('a');
          link.href = url;
          link.download = '2ia-pressure-map.txt';
          document.body.appendChild(link);
          link.click();
          link.remove();
          window.setTimeout(function () {
            window.URL.revokeObjectURL(url);
          }, 1000);
        });
      }

      if (printButton) {
        printButton.addEventListener('click', function () {
          if (!currentPlanText) {
            render();
          }
          document.body.classList.add('who-cares-printing');
          window.print();
          window.setTimeout(function () {
            document.body.classList.remove('who-cares-printing');
          }, 500);
        });
      }

      render();
    });
  }

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