[FIX] JavaScript Code von knapp 4.000 Zeilen auf unter 300 gedrückt indem ein fettes JSON Objekt von PHP zu JS übergeben wird & favicon hinzugefügt

This commit is contained in:
Caspar Armster 2016-07-03 17:02:07 +02:00
parent 84cae46ba5
commit 6c3f003169
2 changed files with 148 additions and 168 deletions

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

316
index.php
View File

@ -25,6 +25,9 @@
<link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
EOT; EOT;
try { try {
@ -33,9 +36,23 @@ EOT;
echo("Fehler: ".$e->getMessage()); echo("Fehler: ".$e->getMessage());
die(); die();
} }
$router_json = json_encode($router);
echo("\n<script>\n");
echo("var router_text = '".$router_json."';\n");
echo("var router_json = JSON.parse(router_text);\n");
echo("var anzahl_hersteller = ".$anzahl_hersteller.";\n");
echo("var herstellername = [");
for( $i=0; $i<$anzahl_hersteller; $i++) {
echo("\"".$hersteller[$i]['name']."\"");
if( $i != $anzahl_hersteller-1) {
echo(", ");
}
}
echo("];\n");
echo <<<EOT echo <<<EOT
<script>
function populateA(){ function populateA(){
var s1 = document.getElementById("fw-dl-1"); var s1 = document.getElementById("fw-dl-1");
var s2 = document.getElementById("fw-dl-2"); var s2 = document.getElementById("fw-dl-2");
@ -45,31 +62,29 @@ function populateA(){
var s6 = document.getElementById("fw-dl-6"); var s6 = document.getElementById("fw-dl-6");
var img_router_front = document.getElementById("img_router_front"); var img_router_front = document.getElementById("img_router_front");
var img_router_back = document.getElementById("img_router_back"); var img_router_back = document.getElementById("img_router_back");
var optionArray = new Array();
s2.innerHTML = ""; s2.innerHTML = "";
EOT; for(i=0; i<anzahl_hersteller; i++) {
for( $i=0; $i<$anzahl_hersteller; $i++) { if(s1.value == herstellername[i]) {
echo("\n if(s1.value == \"".$hersteller[$i]['name']."\"){\n"); optionArray[0] = "|Modell auswählen";
echo(" var optionArray = [\"|Modell auswählen\""); var j = 0;
$j=0; while(j < router_json.length) {
while( $j<count($router) ) { if(router_json[j].hersteller == herstellername[i]) {
if($router[$j]->hersteller == $hersteller[$i]['name']) { optionArray[j+1] = router_json[j].modell+"|"+router_json[j].modell;
echo(",\"".$router[$j]->modell."|".$router[$j]->modell."\""); if(j<router_json.length-1) {
if( $j<count($router)-1 ) { while(router_json[j].modell == router_json[j+1].modell) {
while($router[$j]->modell == $router[$j+1]->modell) { if(j<router_json.length-1) {
if( $j<count($router)-1 ) { j++;
$j++; } else {
} else { break;
break; }
} }
} }
} }
} j++;
$j++; }
} }
echo("];\n"); }
echo(" }\n");
}
echo <<<EOT
for(var option in optionArray){ for(var option in optionArray){
var pair = optionArray[option].split("|"); var pair = optionArray[option].split("|");
var newOption = document.createElement("option"); var newOption = document.createElement("option");
@ -105,31 +120,25 @@ function populateB(){
var s6 = document.getElementById("fw-dl-6"); var s6 = document.getElementById("fw-dl-6");
var img_router_front = document.getElementById("img_router_front"); var img_router_front = document.getElementById("img_router_front");
var img_router_back = document.getElementById("img_router_back"); var img_router_back = document.getElementById("img_router_back");
var optionArray = new Array();
optionArray[0] = "|Modell auswählen";
s2.innerHTML = ""; s2.innerHTML = "";
switch(s1.value){\n var i = 0;
EOT; while(i < router_json.length) {
$i=0; if(router_json[i].modell == s1.value) {
while( $i<count($router) ) { optionArray[i+1] = i+"|"+router_json[i].version;
echo(" case \"".$router[$i]->modell."\":\n"); if(i<router_json.length-1) {
echo(" var optionArray = [\"|Version auswählen\""); while(router_json[i].modell == router_json[i+1].modell) {
echo(",\"".$i."|".$router[$i]->version."\""); if(i<router_json.length-1) {
if( $i<count($router)-1 ) { i++;
while($router[$i]->modell == $router[$i+1]->modell) { optionArray[i+1] = i+"|"+router_json[i].version;
if( $i<count($router)-1 ) { } else {
$i++; break;
echo(",\"".$i."|".$router[$i]->version."\""); }
} else { }
break; }
} }
} i++;
}
echo("];\n");
echo(" break;\n");
$i++;
}
echo <<<EOT
default:
break;
} }
for(var option in optionArray){ for(var option in optionArray){
var pair = optionArray[option].split("|"); var pair = optionArray[option].split("|");
@ -162,28 +171,18 @@ function populateC(){
var s6 = document.getElementById("fw-dl-6"); var s6 = document.getElementById("fw-dl-6");
var img_router_front = document.getElementById("img_router_front"); var img_router_front = document.getElementById("img_router_front");
var img_router_back = document.getElementById("img_router_back"); var img_router_back = document.getElementById("img_router_back");
var optionArray = new Array();
optionArray[0] = "|Erstinstallation?";
s2.innerHTML = ""; s2.innerHTML = "";
switch(s1.value){\n var newImageFront = router_json[s1.value].imagefront;
EOT; var newImageBack = router_json[s1.value].imageback;
$i=0; var i = 1;
while( $i<count($router) ) { if((router_json[s1.value].betafactory == 1) || (router_json[s1.value].brokenfactory == 1) || (router_json[s1.value].experimentalfactory == 1) || (router_json[s1.value].stablefactory == 1)) {
echo(" case \"".$i."\":\n"); optionArray[i] = s1.value+"J|Ja";
echo(" var newImageFront = \"".$router[$i]->imagefront."\";\n"); i++;
echo(" var newImageBack = \"".$router[$i]->imageback."\";\n"); }
echo(" var optionArray = [\"|Erstinstallation?\""); if((router_json[s1.value].betasysupgrade == 1) || (router_json[s1.value].brokensysupgrade == 1) || (router_json[s1.value].experimentalsysupgrade == 1) || (router_json[s1.value].stablesysupgrade == 1)) {
if( ($router[$i]->betafactory == 1) || ($router[$i]->brokenfactory == 1) || ($router[$i]->experimentalfactory == 1) || ($router[$i]->stablefactory == 1) ) { optionArray[i] = s1.value+"N|Nein";
echo(",\"".$i."J|Ja\"");
}
if( ($router[$i]->betasysupgrade == 1) || ($router[$i]->brokensysupgrade == 1) || ($router[$i]->experimentalsysupgrade == 1) || ($router[$i]->stablesysupgrade == 1) ) {
echo(",\"".$i."N|Nein\"");
}
echo("];\n");
echo(" break;\n");
$i++;
}
echo <<<EOT
default:
break;
} }
for(var option in optionArray){ for(var option in optionArray){
var pair = optionArray[option].split("|"); var pair = optionArray[option].split("|");
@ -210,48 +209,47 @@ function populateD(){
var s1 = document.getElementById("fw-dl-4"); var s1 = document.getElementById("fw-dl-4");
var s2 = document.getElementById("fw-dl-5"); var s2 = document.getElementById("fw-dl-5");
var s6 = document.getElementById("fw-dl-6"); var s6 = document.getElementById("fw-dl-6");
var optionArray = new Array();
optionArray[0] = "|Entwicklungsstadium?";
s2.innerHTML = ""; s2.innerHTML = "";
switch(s1.value){\n var id = parseInt(s1.value.slice(0,s1.value.length));
EOT; var jein = s1.value.slice(-1);
$i=0; var i = 1;
while( $i<count($router) ) { if(jein == "J") {
echo(" case \"".$i."J\":\n"); if(router_json[id].betafactory == 1) {
echo(" var optionArray = [\"|Entwicklungsstadium?\""); optionArray[i] = id+"Jbeta|Beta";
if( ($router[$i]->betafactory == 1) ) { i++;
echo(",\"".$i."Jbeta|Beta\""); }
} if(router_json[id].brokenfactory == 1) {
if( ($router[$i]->brokenfactory == 1) ) { optionArray[i] = id+"Jbroken|Broken";
echo(",\"".$i."Jbroken|Broken\""); i++;
} }
if( ($router[$i]->experimentalfactory == 1) ) { if(router_json[id].experimentalfactory == 1) {
echo(",\"".$i."Jexp|Experimental\""); optionArray[i] = id+"Jexp|Experimental";
} i++;
if( ($router[$i]->stablefactory == 1) ) { }
echo(",\"".$i."Jstable|Stable\""); if(router_json[id].stablefactory == 1) {
} optionArray[i] = id+"Jstable|Stable";
echo("];\n"); i++;
echo(" break\n"); }
echo(" case \"".$i."N\":\n"); }
echo(" var optionArray = [\"|Entwicklungsstadium?\""); if(jein == "N") {
if( ($router[$i]->betasysupgrade == 1) ) { if(router_json[id].betasysupgrade == 1) {
echo(",\"".$i."Nbeta|Beta\""); optionArray[i] = id+"Nbeta|Beta";
} i++;
if( ($router[$i]->brokensysupgrade == 1) ) { }
echo(",\"".$i."Nbroken|Broken\""); if(router_json[id].brokensysupgrade == 1) {
} optionArray[i] = id+"Nbroken|Broken";
if( ($router[$i]->experimentalsysupgrade == 1) ) { i++;
echo(",\"".$i."Nexp|Experimental\""); }
} if(router_json[id].experimentalsysupgrade == 1) {
if( ($router[$i]->stablesysupgrade == 1) ) { optionArray[i] = id+"Nexp|Experimental";
echo(",\"".$i."Nstable|Stable\""); i++;
} }
echo("];\n"); if(router_json[id].stablesysupgrade == 1) {
echo(" break\n"); optionArray[i] = id+"Nstable|Stable";
$i++; i++;
} }
echo <<<EOT
default:
break;
} }
for(var option in optionArray){ for(var option in optionArray){
var pair = optionArray[option].split("|"); var pair = optionArray[option].split("|");
@ -273,63 +271,45 @@ function populateE(){
var s1 = document.getElementById("fw-dl-5"); var s1 = document.getElementById("fw-dl-5");
var s2 = document.getElementById("fw-dl-6"); var s2 = document.getElementById("fw-dl-6");
s2.innerHTML = ""; s2.innerHTML = "";
switch(s1.value){\n if(s1.value.lastIndexOf("Jbeta") != -1) {
EOT; var id = parseInt(s1.value.slice(0,s1.value.length-4));
$i=0; var link = router_json[id].betafactorylink;
while( $i<count($router) ) { var linkclass = " btn-warning";
if( ($router[$i]->betafactory == 1) ) { }
echo(" case \"".$i."Jbeta\":\n"); if(s1.value.lastIndexOf("Jbroken") != -1) {
echo(" var link = \"".$router[$i]->betafactorylink."\";\n"); var id = parseInt(s1.value.slice(0,s1.value.length-6));
echo(" var linkclass = \" btn-warning\";\n"); var link = router_json[id].brokenfactorylink;
echo(" break;\n"); var linkclass = " btn-danger";
} }
if( ($router[$i]->brokenfactory == 1) ) { if(s1.value.lastIndexOf("Jexp") != -1) {
echo(" case \"".$i."Jbroken\":\n"); var id = parseInt(s1.value.slice(0,s1.value.length-3));
echo(" var link = \"".$router[$i]->brokenfactorylink."\";\n"); var link = router_json[id].experimentalfactorylink;
echo(" var linkclass = \" btn-danger\";\n"); var linkclass = " btn-warning";
echo(" break;\n"); }
} if(s1.value.lastIndexOf("Jstable") != -1) {
if( ($router[$i]->experimentalfactory == 1) ) { var id = parseInt(s1.value.slice(0,s1.value.length-6));
echo(" case \"".$i."Jexp\":\n"); var link = router_json[id].stablefactorylink;
echo(" var link = \"".$router[$i]->experimentalfactorylink."\";\n"); var linkclass = " btn-success";
echo(" var linkclass = \" btn-warning\";\n"); }
echo(" break;\n"); if(s1.value.lastIndexOf("Nbeta") != -1) {
} var id = parseInt(s1.value.slice(0,s1.value.length-4));
if( ($router[$i]->stablefactory == 1) ) { var link = router_json[id].betasysupgradelink;
echo(" case \"".$i."Jstable\":\n"); var linkclass = " btn-warning";
echo(" var link = \"".$router[$i]->stablefactorylink."\";\n"); }
echo(" var linkclass = \" btn-success\";\n"); if(s1.value.lastIndexOf("Nbroken") != -1) {
echo(" break;\n"); var id = parseInt(s1.value.slice(0,s1.value.length-6));
} var link = router_json[id].brokensysupgradelink;
if( ($router[$i]->betasysupgrade == 1) ) { var linkclass = " btn-danger";
echo(" case \"".$i."Nbeta\":\n"); }
echo(" var link = \"".$router[$i]->betasysupgradelink."\";\n"); if(s1.value.lastIndexOf("Nexp") != -1) {
echo(" var linkclass = \" btn-warning\";\n"); var id = parseInt(s1.value.slice(0,s1.value.length-3));
echo(" break;\n"); var link = router_json[id].experimentalsysupgradelink;
} var linkclass = " btn-warning";
if( ($router[$i]->brokensysupgrade == 1) ) { }
echo(" case \"".$i."Nbroken\":\n"); if(s1.value.lastIndexOf("Nstable") != -1) {
echo(" var link = \"".$router[$i]->brokensysupgradelink."\";\n"); var id = parseInt(s1.value.slice(0,s1.value.length-6));
echo(" var linkclass = \" btn-danger\";\n"); var link = router_json[id].stablesysupgradelink;
echo(" break;\n"); var linkclass = " btn-success";
}
if( ($router[$i]->experimentalsysupgrade == 1) ) {
echo(" case \"".$i."Nexp\":\n");
echo(" var link = \"".$router[$i]->experimentalsysupgradelink."\";\n");
echo(" var linkclass = \" btn-warning\";\n");
echo(" break;\n");
}
if( ($router[$i]->stablesysupgrade == 1) ) {
echo(" case \"".$i."Nstable\":\n");
echo(" var link = \"".$router[$i]->stablesysupgradelink."\";\n");
echo(" var linkclass = \" btn-success\";\n");
echo(" break;\n");
}
$i++;
}
echo <<<EOT
default:
break;
} }
s2.href = link; s2.href = link;
s2.className = s2.className.replace( /(?:^|\s)disabled(?!\S)/g , '' ); s2.className = s2.className.replace( /(?:^|\s)disabled(?!\S)/g , '' );