diff options
author | polo <ordipolo@gmx.fr> | 2025-04-21 20:36:10 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-04-21 20:36:10 +0200 |
commit | eb3e1eb8c8365d3b3d1d39f24314ba420255afc2 (patch) | |
tree | 5e3d747b0e4d5e747052e9afed76f3a0f0986379 /public/js/main.js | |
parent | ca3949aca0c7c1af476c8eec93b4920d5aff21ec (diff) | |
download | cms-eb3e1eb8c8365d3b3d1d39f24314ba420255afc2.zip |
page menu et chemin, partie1
Diffstat (limited to 'public/js/main.js')
-rw-r--r-- | public/js/main.js | 105 |
1 files changed, 104 insertions, 1 deletions
diff --git a/public/js/main.js b/public/js/main.js index cb76ea8..fadcfa9 100644 --- a/public/js/main.js +++ b/public/js/main.js | |||
@@ -29,10 +29,17 @@ function copyInClipBoard(link){ | |||
29 | alert('Cette adresse a été copiée dans le presse-papier:\n\n' + link); | 29 | alert('Cette adresse a été copiée dans le presse-papier:\n\n' + link); |
30 | } | 30 | } |
31 | 31 | ||
32 | function toastNotify(message) { | ||
33 | var toast = document.getElementById('toast'); | ||
34 | toast.textContent = message; | ||
35 | toast.className = 'toast show'; | ||
36 | setTimeout(function(){ toast.className = toast.className.replace('show', ''); }, 3000); | ||
37 | } | ||
38 | |||
32 | // complète les fonctions dans tinymce.js | 39 | // complète les fonctions dans tinymce.js |
33 | function switchPositions(article_id, direction) | 40 | function switchPositions(article_id, direction) |
34 | { | 41 | { |
35 | const current_article = findParent(document.getElementById(article_id), 'article'); | 42 | const current_article = findParent(document.getElementById(article_id), 'article'); // l'id n'est pas sur la bonne balise |
36 | var other_article; | 43 | var other_article; |
37 | 44 | ||
38 | if(direction == 'down'){ | 45 | if(direction == 'down'){ |
@@ -195,4 +202,100 @@ function findParent(element, tag_name){ | |||
195 | element = element.parentElement; | 202 | element = element.parentElement; |
196 | } | 203 | } |
197 | return null; | 204 | return null; |
205 | } | ||
206 | |||
207 | /* page Menu et chemins */ | ||
208 | function moveOneLevelUp(){} | ||
209 | function moveOneLevelDown(){} | ||
210 | |||
211 | function switchMenuPositions(page_id, direction) | ||
212 | { | ||
213 | const nav_zone = document.getElementById("nav_zone"); // parent de <nav> | ||
214 | const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton | ||
215 | var other_entry = null; | ||
216 | |||
217 | // pas bon | ||
218 | if(direction == 'down'){ | ||
219 | other_entry = clicked_menu_entry.nextElementSibling; | ||
220 | } | ||
221 | else if(direction == 'up'){ | ||
222 | other_entry = clicked_menu_entry.previousElementSibling; | ||
223 | } | ||
224 | |||
225 | if(other_entry == null){ | ||
226 | console.log('Inversion impossible'); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | fetch('index.php?menu_edit=switch_positions', { | ||
231 | method: 'POST', | ||
232 | headers: { | ||
233 | 'Content-Type': 'application/json' | ||
234 | }, | ||
235 | body: JSON.stringify({ id1: clicked_menu_entry.id, id2: other_entry.id }) | ||
236 | }) | ||
237 | .then(response => response.json()) | ||
238 | .then(data => { | ||
239 | if(data.success) | ||
240 | { | ||
241 | if(direction == 'down'){ | ||
242 | clicked_menu_entry.parentElement.insertBefore(other_entry, clicked_menu_entry); | ||
243 | console.log('Inversion réussie'); | ||
244 | } | ||
245 | else if(direction == 'up'){ | ||
246 | other_entry.parentElement.insertBefore(clicked_menu_entry, other_entry); | ||
247 | console.log('Inversion réussie'); | ||
248 | } | ||
249 | else{ | ||
250 | console.error('Échec de l\'inversion'); | ||
251 | } | ||
252 | |||
253 | // remplacement du menu | ||
254 | nav_zone.innerHTML = ''; | ||
255 | nav_zone.insertAdjacentHTML('afterbegin', data.nav); | ||
256 | } | ||
257 | else { | ||
258 | |||
259 | console.error('Échec de l\'inversion'); | ||
260 | } | ||
261 | }) | ||
262 | .catch(error => { | ||
263 | console.error('Erreur:', error); | ||
264 | }); | ||
265 | } | ||
266 | |||
267 | function checkMenuEntry(page_id){ | ||
268 | const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton | ||
269 | const checkbox = clicked_menu_entry.querySelector("input"); | ||
270 | |||
271 | let color; | ||
272 | if(checkbox.checked){ | ||
273 | color = "#ff1d04"; | ||
274 | checked = true; | ||
275 | } | ||
276 | else{ | ||
277 | color = "grey"; | ||
278 | checked = false; | ||
279 | } | ||
280 | |||
281 | // contrôle check impossible si le parent le plus ancien est unchecked | ||
282 | // | ||
283 | |||
284 | // sur l'élément concerné | ||
285 | clicked_menu_entry.querySelector("button").style.color = color; | ||
286 | |||
287 | // même chose sur les enfants | ||
288 | /*try{ | ||
289 | const level_markup = clicked_menu_entry.querySelector('.level'); | ||
290 | //const other_buttons = .querySelectorAll("button"); | ||
291 | level_markup.querySelectorAll("input").forEach(input => { | ||
292 | input.checked = checked; | ||
293 | }); | ||
294 | level_markup.querySelectorAll("button").forEach(button => { | ||
295 | button.style.color = color; | ||
296 | }); | ||
297 | } | ||
298 | catch(error){ | ||
299 | console.log("pas d'enfant"); | ||
300 | }*/ | ||
198 | } \ No newline at end of file | 301 | } \ No newline at end of file |