// Working previews on the home page: the editor window and the agent session. // Each control sets a data attribute; the stylesheet does the rest. (function () { function press(group, button) { group.forEach(function (b) { b.setAttribute('aria-pressed', String(b === button)); }); } var win = document.querySelector('.win'); if (win) { document.querySelectorAll('[data-open]').forEach(function (button) { button.addEventListener('click', function () { win.dataset.file = button.dataset.open; }); }); var views = Array.prototype.slice.call(document.querySelectorAll('[data-view-to]')); views.forEach(function (button) { button.addEventListener('click', function () { win.dataset.view = button.dataset.viewTo; press(views, button); }); }); var looks = Array.prototype.slice.call(document.querySelectorAll('[data-look]')); looks.forEach(function (button) { button.addEventListener('click', function () { win.dataset.appearance = button.dataset.look; press(looks, button); }); }); // ⌥⌘P switches Markdown and Preview, as it does in the app. document.addEventListener('keydown', function (event) { if (event.altKey && event.metaKey && event.code === 'KeyP' && win.dataset.file === 'log') { event.preventDefault(); var next = win.dataset.view === 'source' ? 'preview' : 'source'; win.dataset.view = next; press(views, views.filter(function (b) { return b.dataset.viewTo === next; })[0]); } }); } var session = document.querySelector('.session'); if (session) { var modes = Array.prototype.slice.call(document.querySelectorAll('[data-mode-to]')); modes.forEach(function (button) { button.addEventListener('click', function () { session.dataset.mode = button.dataset.modeTo; press(modes, button); }); }); } })();