taggart

Simple golang tagging filesystem webapp
Log | Files | Refs

description.js (1646B)


      1 function toggleDescriptionEdit() {
      2     const displayDiv = document.getElementById('description-display');
      3     const editDiv = document.getElementById('description-edit');
      4 
      5     displayDiv.style.display = 'none';
      6     editDiv.style.display = 'block';
      7 
      8     // Focus the textarea and update character count
      9     const textarea = document.getElementById('description-textarea');
     10     textarea.focus();
     11 
     12     // Move cursor to end of text if there's existing content
     13     if (textarea.value) {
     14         textarea.setSelectionRange(textarea.value.length, textarea.value.length);
     15     }
     16 }
     17 
     18 function cancelDescriptionEdit() {
     19     const displayDiv = document.getElementById('description-display');
     20     const editDiv = document.getElementById('description-edit');
     21     const textarea = document.getElementById('description-textarea');
     22 
     23     // Reset textarea to original value
     24     const original = displayDiv.dataset.originalDescription || '';
     25     textarea.value = original;
     26 
     27     displayDiv.style.display = 'block';
     28     editDiv.style.display = 'none';
     29 }
     30 
     31 // Auto-resize textarea as content changes
     32 document.addEventListener('DOMContentLoaded', function() {
     33     const textarea = document.getElementById('description-textarea');
     34     if (textarea) {
     35         textarea.addEventListener('input', function() {
     36             // Reset height to auto to get the correct scrollHeight
     37             this.style.height = 'auto';
     38             // Set the height to match the content, with a minimum of 6 rows
     39             const minHeight = parseInt(getComputedStyle(this).lineHeight) * 6;
     40             this.style.height = Math.max(minHeight, this.scrollHeight) + 'px';
     41         });
     42     }
     43 });