improve scratchpad editing
This commit is contained in:
22
script.js
22
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, '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user