From 68b6058e2a27fc251c117c4efeb141392a0c9736 Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 6 Apr 2025 12:18:49 +0200 Subject: =?UTF-8?q?nouvel=20article,=20boutons=20dans=20les=20builders,=20?= =?UTF-8?q?makeArticleNode,=20JS=20MAJ=20page,=20tri=20quand=20d=C3=A9plac?= =?UTF-8?q?ement=20ou=20suppression?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/main.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'public/js/main.js') diff --git a/public/js/main.js b/public/js/main.js index 1351fea..c05eb2f 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -30,10 +30,10 @@ function copyInClipBoard(link){ } // complète les fonctions dans tinymce.js -function switchPositions(articleId, direction) +function switchPositions(article_id, direction) { - const current_article = document.getElementById(articleId).parentElement.parentElement; - var other_article = current_article; + const current_article = findParent(document.getElementById(article_id), 'article'); + var other_article; if(direction == 'down'){ other_article = current_article.nextElementSibling; @@ -41,14 +41,23 @@ function switchPositions(articleId, direction) else if(direction == 'up'){ other_article = current_article.previousElementSibling; } - const other_article_id = other_article.querySelector('div[id]').id; + + var other_article_id; + try{ + other_article_id = other_article.querySelector('div[id]').id; + other_article_id = 'i' + other_article_id.slice(1); // peut mieux faire + } + catch(error){ + console.log('Inversion impossible'); + return; + } fetch('index.php?action=switch_positions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id1: articleId, id2: other_article_id }) + body: JSON.stringify({ id1: article_id, id2: other_article_id }) }) .then(response => response.json()) .then(data => { @@ -155,4 +164,15 @@ function submitDate(id_date) .catch(error => { console.error('Erreur:', error); }); +} + +function findParent(element, tag_name) { + while (element !== null) { + if (element.tagName === tag_name.toUpperCase()) // tagName est en majuscules + { + return element; + } + element = element.parentElement; + } + return null; } \ No newline at end of file -- cgit v1.2.3