From 8ccdeb8e6b5306a876db39e5d41f7c7906912767 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Sun, 20 Aug 2006 18:30:01 +0000
Subject: [PATCH] optimisation : ne pas repeter x fois le meme code javascript
 (renato)

---
 ecrire/exec/admin_plugin.php | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/ecrire/exec/admin_plugin.php b/ecrire/exec/admin_plugin.php
index c00348c4db..5a9744ca04 100644
--- a/ecrire/exec/admin_plugin.php
+++ b/ecrire/exec/admin_plugin.php
@@ -208,6 +208,16 @@ function affiche_arbre_plugins($liste_plugins,$liste_plugins_actifs){
 	
 	$visible = @isset($deplie[$current_dir]);
 	$maxiter=1000;
+	echo http_script("// http://doc.spip.org/@verifchange\n".
+	"function verifchange(id) {\n".
+	"if(this.checked == true)\n".
+	"{\n".
+	"	document.getElementById(id).className = 'nomplugin_on';\n".
+	"}\n".
+	"else {\n".
+	"	document.getElementById(id).className = 'nomplugin';\n".
+	"}\n".
+	"}\n");
 	while (count($liste_plugins) && $maxiter--){
 		// le rep suivant
 		$dir = dirname(reset($liste_plugins));
@@ -236,21 +246,7 @@ function ligne_plug($plug_file, $actif, $id){
 	$erreur = false;
 	$vals = array();
 	$info = plugin_get_infos($plug_file);
-	$s = "<script type='text/javascript'>";
-$s .= <<<EOF
-// http://doc.spip.org/@verifchange
-function verifchange$id(inputp) {
-	if(inputp.checked == true)
-	{
-		document.getElementById('$plug_file').className = 'nomplugin_on';
-	}
-	else {
-		document.getElementById('$plug_file').className = 'nomplugin';
-	}
-	}
-EOF;
-	$s .= "</script>";
-	$s .= "<div id='$plug_file' class='nomplugin".($actif?'_on':'')."'>";
+	$s = "<div id='$plug_file' class='nomplugin".($actif?'_on':'')."'>";
 	if (isset($info['erreur'])){
 		$s .=  "<div style='background:".$GLOBALS['couleur_claire']."'>";
 		$erreur = true;
@@ -286,7 +282,7 @@ EOF;
 	if (!$erreur){
 		$s .= "<input type='checkbox' name='statusplug_$plug_file' value='O' id='label_$id_input'";
 		$s .= $actif?" checked='checked'":"";
-		$s .= " onclick='verifchange$id(this)' /> <label for='label_$id_input' style='display:none'>"._T('activer_plugin')."</label>";
+		$s .= " onclick='verifchange.apply(this,[\"$plug_file\"])' /> <label for='label_$id_input' style='display:none'>"._T('activer_plugin')."</label>";
 	}
 	$id_input++;
 	
-- 
GitLab