From 52e3674140ae71d8fa87e44aed3e615886831d84 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 12 Dec 2024 16:25:43 +0100 Subject: [PATCH] use document fragment --- static/js/cours.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/static/js/cours.js b/static/js/cours.js index 0ecc1d8..f959d60 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -5,7 +5,10 @@ * @param {string} location Current location, used for links creation */ const buildFileTree = (parent, data, location) => { + const fragment = document.createDocumentFragment(); const ul = document.createElement("ul"); + fragment.appendChild(ul); + data.forEach((item) => { const li = document.createElement("li"); li.classList.add(item.is_dir ? "directory" : "file"); @@ -32,16 +35,16 @@ const buildFileTree = (parent, data, location) => { ul.appendChild(li); - if (item.children && item.children.length > 0) { + if (item.children?.length) { buildFileTree( li, item.children, - item.is_dir ? location + `${item.name}/` : location + item.is_dir ? `${location}${item.name}/` : location ); } }); - parent.appendChild(ul); + parent.appendChild(fragment); }; /**