From c9aff025aa7e01badaad8467af6165b400cdaac4 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 22 Oct 2025 15:28:02 +0200 Subject: =?UTF-8?q?possibilit=C3=A9=20d'=C3=A9diter=20le=20texte=20dans=20?= =?UTF-8?q?header=20et=20footer,=20class=20JS=20InputText,=20Model::findWh?= =?UTF-8?q?ateverNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/InputText.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 public/js/InputText.js (limited to 'public/js') diff --git a/public/js/InputText.js b/public/js/InputText.js new file mode 100644 index 0000000..ba7e8e4 --- /dev/null +++ b/public/js/InputText.js @@ -0,0 +1,47 @@ +// s'en servir dans menu et chemin +class InputText{ + constructor(name){ + this.name = name; + this.parent = document.getElementById(name); + } + openTextInput(){ + this.parent.querySelector('#' + this.name + '_span').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_input').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_open').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_submit').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_cancel').classList.remove('hidden'); + } + closeTextInput(){ + this.parent.querySelector('#' + this.name + '_span').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_input').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_open').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_submit').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_cancel').classList.add('hidden'); + } + submitTextInput(){ + const new_text = this.parent.querySelector('#' + this.name + '_input').value; + + fetch('index.php?entire_site_edit=' + this.name, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({new_text: new_text}) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + this.parent.querySelector('#' + this.name + '_span').innerHTML = new_text; + this.closeTextInput(this.name); + } + else{ + console.error("Erreur: le serveur n'a pas enregistré le nouveau texte."); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); + } + cancelTextInput(){ + this.parent.querySelector('#' + this.name + '_input').value = this.parent.querySelector('#' + this.name + '_span').innerHTML; + this.closeTextInput(this.name); + } +} \ No newline at end of file -- cgit v1.2.3