diff --git a/assets/editor/main.html b/assets/editor/main.html index 4dd0c30..3a7ede2 100644 --- a/assets/editor/main.html +++ b/assets/editor/main.html @@ -4,30 +4,71 @@ {{end}} {{define "content"}} +
diff --git a/assets/editor/main.js b/assets/editor/main.js index 4be5a5f..91b17ca 100644 --- a/assets/editor/main.js +++ b/assets/editor/main.js @@ -124,6 +124,7 @@ wikilink: insertWikilink, ul: function () { linePrefix('- '); }, ol: function () { linePrefix('1. '); }, + task: function () { linePrefix('- [ ] '); }, hr: function () { wrap('\n\n---\n\n', '', ''); }, fmttable: function () { applyTableOp(T.formatTableText); }, tblalignleft: function () { applyTableOp(T.setColumnAlignment, 'left'); }, @@ -136,6 +137,11 @@ dateiso: function () { insertAtCursor(D.isoDate()); }, datelong: function () { insertAtCursor(D.longDate()); }, movie: function () { M.run(textarea); }, + wide: function () { + var enabled = !document.body.classList.contains('editor-wide'); + document.body.classList.toggle('editor-wide', enabled); + sessionStorage.setItem('editor-wide', enabled ? '1' : '0'); + }, }; // --- Keyboard shortcut registration --- @@ -151,10 +157,6 @@ } }); - keyMap['T'] = actions.fmttable; - keyMap['D'] = actions.dateiso; - keyMap['W'] = actions.datelong; - document.addEventListener('keydown', function (e) { if (!e.altKey || !e.shiftKey) return; // Shift+digit produces a layout-dependent character in e.key (e.g. "!" @@ -192,69 +194,7 @@ applyResult(result); }); - // --- Dropdown helper --- + // --- Dropdowns --- - var openMenus = []; - - function makeDropdown(triggerBtn, items) { - var menu = document.createElement('div'); - menu.className = 'dropdown-menu'; - items.forEach(function (item) { - var btn = document.createElement('button'); - btn.type = 'button'; - btn.className = 'btn btn-tool dropdown-item'; - btn.textContent = item.label; - btn.addEventListener('mousedown', function (e) { - e.preventDefault(); - actions[item.action](); - menu.classList.remove('is-open'); - }); - menu.appendChild(btn); - }); - triggerBtn.appendChild(menu); - openMenus.push(menu); - - triggerBtn.addEventListener('click', function (e) { - if (e.target !== triggerBtn) return; - var wasOpen = menu.classList.contains('is-open'); - openMenus.forEach(function (m) { m.classList.remove('is-open'); }); - if (!wasOpen) menu.classList.add('is-open'); - }); - } - - document.addEventListener('click', function (e) { - var insideAny = openMenus.some(function (m) { - return m.parentElement && m.parentElement.contains(e.target); - }); - if (!insideAny) openMenus.forEach(function (m) { m.classList.remove('is-open'); }); - }); - document.addEventListener('keydown', function (e) { - if (e.key === 'Escape') openMenus.forEach(function (m) { m.classList.remove('is-open'); }); - }); - - // --- Table dropdown --- - - var tblDropBtn = document.querySelector('[data-action="tbldrop"]'); - if (tblDropBtn) { - makeDropdown(tblDropBtn, [ - { label: 'Format table', action: 'fmttable' }, - { label: 'Align left', action: 'tblalignleft' }, - { label: 'Align center', action: 'tblaligncenter' }, - { label: 'Align right', action: 'tblalignright' }, - { label: 'Insert column', action: 'tblinsertcol' }, - { label: 'Delete column', action: 'tbldeletecol' }, - { label: 'Insert row', action: 'tblinsertrow' }, - { label: 'Delete row', action: 'tbldeleterow' }, - ]); - } - - // --- Date dropdown --- - - var dateDropBtn = document.querySelector('[data-action="datedrop"]'); - if (dateDropBtn) { - makeDropdown(dateDropBtn, [ - { label: 'YYYY-MM-DD', action: 'dateiso' }, - { label: 'DE Long', action: 'datelong' }, - ]); - } + document.querySelectorAll('.dropdown-toggle').forEach(wireDropdown); })(); diff --git a/assets/style.css b/assets/style.css index 9fa929e..81cda44 100644 --- a/assets/style.css +++ b/assets/style.css @@ -379,6 +379,10 @@ main > h2 { flex-direction: column; } +body.editor-wide main { + max-width: none; +} + textarea { width: 100%; min-height: 60vh;