diff --git a/script.js b/script.js index bf24f36..4ad39e1 100644 --- a/script.js +++ b/script.js @@ -288,6 +288,23 @@ var pads = document.querySelectorAll('div.luxtools-scratchpad[data-luxtools-scratchpad="1"]'); if (!pads || !pads.length) return; + function setEditMode(root, isEditing) { + if (!root || !root.classList) return; + + var view = root.querySelector('.luxtools-scratchpad-view'); + var editor = root.querySelector('.luxtools-scratchpad-editor'); + + if (isEditing) { + root.classList.add('is-editing'); + if (view) view.hidden = true; + if (editor) editor.hidden = false; + } else { + root.classList.remove('is-editing'); + if (view) view.hidden = false; + if (editor) editor.hidden = true; + } + } + function setStatus(root, msg) { var el = root.querySelector('.luxtools-scratchpad-status'); if (!el) return; @@ -372,7 +389,7 @@ var textarea = root.querySelector('textarea.luxtools-scratchpad-text'); if (!editor || !textarea) return; - editor.hidden = false; + setEditMode(root, true); setStatus(root, 'Loading…'); textarea.disabled = true; @@ -390,7 +407,8 @@ function closeEditor(root) { var editor = root.querySelector('.luxtools-scratchpad-editor'); if (!editor) return; - editor.hidden = true; + + setEditMode(root, false); setStatus(root, ''); } diff --git a/style.css b/style.css index d8f9749..3036892 100644 --- a/style.css +++ b/style.css @@ -101,22 +101,55 @@ div.luxtools-scratchpad { position: relative; } +/* Template hook: stable wrapper around scratchpad content + controls. */ +div.luxtools-scratchpad .luxtools-scratchpad-frame { + position: relative; +} + div.luxtools-scratchpad .luxtools-scratchpad-bar { display: flex; - justify-content: flex-end; + align-items: center; + justify-content: flex-start; + gap: 0.4em; margin-bottom: 0.2em; } +div.luxtools-scratchpad .luxtools-scratchpad-name { + flex: 0 1 auto; + min-width: 0; + opacity: 0.65; + font-size: 90%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + div.luxtools-scratchpad a.luxtools-scratchpad-edit { text-decoration: none; - opacity: 0.7; - padding: 0 0.2em; + opacity: 0.75; + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 2em; + min-height: 2em; + line-height: 1; + font-style: italic; + color: inherit; } div.luxtools-scratchpad a.luxtools-scratchpad-edit:hover, div.luxtools-scratchpad a.luxtools-scratchpad-edit:focus { opacity: 1; } +/* Edit mode: replace rendered view with editor. */ +div.luxtools-scratchpad.is-editing .luxtools-scratchpad-view { + display: none; +} + +div.luxtools-scratchpad.is-editing .luxtools-scratchpad-bar { + display: none; +} + div.luxtools-scratchpad .luxtools-scratchpad-editor { margin-top: 0.4em; } diff --git a/syntax/scratchpad.php b/syntax/scratchpad.php index f05813e..0c6b41d 100644 --- a/syntax/scratchpad.php +++ b/syntax/scratchpad.php @@ -133,11 +133,22 @@ class syntax_plugin_luxtools_scratchpad extends SyntaxPlugin . ' data-sectok="' . hsc($sectok) . '"' . '>'; + // Stable, template-friendly container around the scratchpad. + $renderer->doc .= '