code.gitea.io/gitea@v1.22.3/web_src/js/features/file-fold.js (about)

     1  import {svg} from '../svg.js';
     2  
     3  // Hides the file if newFold is true, and shows it otherwise. The actual hiding is performed using CSS.
     4  //
     5  // The fold arrow is the icon displayed on the upper left of the file box, especially intended for components having the 'fold-file' class.
     6  // The file content box is the box that should be hidden or shown, especially intended for components having the 'file-content' class.
     7  //
     8  export function setFileFolding(fileContentBox, foldArrow, newFold) {
     9    foldArrow.innerHTML = svg(`octicon-chevron-${newFold ? 'right' : 'down'}`, 18);
    10    fileContentBox.setAttribute('data-folded', newFold);
    11    if (newFold && fileContentBox.getBoundingClientRect().top < 0) {
    12      fileContentBox.scrollIntoView();
    13    }
    14  }
    15  
    16  // Like `setFileFolding`, except that it automatically inverts the current file folding state.
    17  export function invertFileFolding(fileContentBox, foldArrow) {
    18    setFileFolding(fileContentBox, foldArrow, fileContentBox.getAttribute('data-folded') !== 'true');
    19  }