/** * Scheduling Poll Block Hydration for MkDocs * * Scans for .scheduling-poll-block elements, fetches poll data from the API, * and renders a read-only poll summary with a "Vote Now" link to the full * interactive voting page on the app. * * Follows the gancio-events.js hydration pattern. */ (function () { 'use strict'; function getApiUrl() { // env-config.js injects these globals if (window.PAYMENT_API_URL) return window.PAYMENT_API_URL; if (window.API_URL) return window.API_URL; var host = window.location.hostname; if (host !== 'localhost' && host.indexOf('.') !== -1) { var parts = host.split('.'); var base = parts.slice(-2).join('.'); return window.location.protocol + '//api.' + base; } return 'http://localhost:4000'; } function getAppUrl() { if (window.APP_URL) return window.APP_URL; var host = window.location.hostname; if (host !== 'localhost' && host.indexOf('.') !== -1) { var parts = host.split('.'); var base = parts.slice(-2).join('.'); return window.location.protocol + '//app.' + base; } return 'http://localhost:3000'; } var STATUS_COLORS = { OPEN: '#52c41a', CLOSED: '#fa8c16', FINALIZED: '#1890ff', CANCELLED: '#ff4d4f', }; var STATUS_LABELS = { OPEN: 'Open for Voting', CLOSED: 'Closed', FINALIZED: 'Date Confirmed', CANCELLED: 'Cancelled', }; function formatDate(dateStr) { var d = new Date(dateStr + 'T00:00:00'); var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; return days[d.getDay()] + ', ' + months[d.getMonth()] + ' ' + d.getDate(); } function hydrateBlocks() { var blocks = document.querySelectorAll('.scheduling-poll-block'); if (blocks.length === 0) return; var apiUrl = getApiUrl(); var appUrl = getAppUrl(); blocks.forEach(function (block) { // Skip if already hydrated if (block.getAttribute('data-hydrated') === 'true') return; var slug = block.getAttribute('data-poll-slug'); if (!slug) return; var showComments = block.getAttribute('data-show-comments') !== 'false'; var title = block.getAttribute('data-title') || ''; block.setAttribute('data-hydrated', 'true'); block.innerHTML = '
' + poll.description + '
'; } html += '| Date / Time | '; html += 'Yes | '; html += 'If Need Be | '; html += 'No | '; html += 'Score | '; html += '
|---|---|---|---|---|
| ';
html += '' + formatDate(opt.date) + ' ' + opt.startTime + '–' + opt.endTime + ''; if (isConfirmed) html += ' ✓'; html += ' | ';
html += '' + (opt.yesCount || 0) + ' | '; html += '' + (opt.ifNeedBeCount || 0) + ' | '; html += '' + (opt.noCount || 0) + ' | '; html += '' + (opt.score || 0) + ' | '; html += '
' + poll.comments.length + ' comment' + (poll.comments.length !== 1 ? 's' : '') + '
'; } // Vote Now CTA if (poll.status === 'OPEN') { html += 'Poll unavailable
' + 'View poll →' + '