Loading...
(function() {
var box = document.querySelector('.civic-action-box');
if (!box) return;
var checks = box.querySelectorAll('.civic-checkbox');
checks.forEach(function(cb) {
cb.addEventListener('change', function() {
var action = cb.getAttribute('data-action');
var label = cb.getAttribute('data-label');
if (typeof gtag !== 'undefined') {
gtag('event', cb.checked ? 'civic_action_taken' : 'civic_action_untaken', {
action_label: action,
action_detail: label,
article_url: window.location.href
});
}
});
});
})();
(function() {
var form = document.getElementById('civic-response-submit');
var thanks = document.getElementById('civic-response-thanks');
if (!form) return;
form.addEventListener('submit', function(e) {
e.preventDefault();
var msg = document.getElementById('civic-response-message').value.trim();
var email = document.getElementById('civic-response-email').value.trim();
if (!msg) return;
var payload = {
message: msg,
article_url: window.location.href,
article_title: document.title
};
if (email) payload.email = email;
fetch('https://ask-planet-detroit-production.up.railway.app/api/civic-responses', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
}).then(function() {
form.style.display = 'none';
if (thanks) thanks.style.display = 'block';
}).catch(function() {
form.style.display = 'none';
if (thanks) thanks.style.display = 'block';
});
});
})();