gitea源码

file-fold.ts 1.0KB

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