MediaWiki:Skin/Suchttest.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
WiMu (Diskussion | Beiträge) (update: +klippklapp, +kleinerbugfix *daumendrück*) |
WiMu (Diskussion | Beiträge) K |
||
(5 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
+ | /******************************************************************************** | ||
+ | * * | ||
+ | * Hinweis: irgendwie funktioniert's (sollte es zumindest) * | ||
+ | * aber fragt mich bloß nicht, wie ... * | ||
+ | * Vermutlich ist das hier alles total umständlich und alles * | ||
+ | * andere als übliches javascript. Aber ich bin ja noch am * | ||
+ | * lernen. * | ||
+ | * * | ||
+ | * --[[Kamel:WiMu|WiMu 12:13, 16. Apr. 2009 (CEST) * | ||
+ | * * | ||
+ | ********************************************************************************/ | ||
+ | |||
window.onload = function () | window.onload = function () | ||
{ | { | ||
suchtpotential = 0 | suchtpotential = 0 | ||
optionvalue = 0 | optionvalue = 0 | ||
+ | notes = 0 | ||
if(document.getElementById("suchttest")) | if(document.getElementById("suchttest")) | ||
{ | { | ||
Zeile 11: | Zeile 24: | ||
function makeoptions () { | function makeoptions () { | ||
− | + | optionsouter = document.getElementById("suchttest").getElementsByTagName("li"); | |
− | numberofoptions = | + | optionsinner = document.getElementById("suchttest").getElementsByTagName("div"); |
+ | numberofoptions = 0; | ||
+ | for (var i = 0; i < optionsinner.length; i++) | ||
+ | { | ||
+ | if (optionsinner[i].className == "testoption") | ||
+ | { | ||
+ | numberofoptions++ | ||
+ | } | ||
+ | } | ||
for (var i = 0; i < numberofoptions; i++) | for (var i = 0; i < numberofoptions; i++) | ||
{ | { | ||
− | for (var j = 0; j < | + | for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++) |
{ | { | ||
− | switch ( | + | switch (optionsinner[i].getElementsByTagName("span")[j].className.split("/")[0]) |
{ | { | ||
case "testoptionvalueinner": | case "testoptionvalueinner": | ||
− | optionvalue = | + | optionvalue = optionsinner[i].getElementsByTagName("span")[j].innerHTML; |
break; | break; | ||
case "checkbox": | case "checkbox": | ||
− | + | optionsinner[i].getElementsByTagName("span")[j].innerHTML = '<input type="checkbox" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">'; | |
+ | break; | ||
+ | case "radio": | ||
+ | optionsinner[i].getElementsByTagName("span")[j].innerHTML = '<input type="radio" name="' + optionsinner[i].getElementsByTagName("span")[j].className.split("/")[1] + '" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">'; | ||
break; | break; | ||
case "testoptionvalueouter": | case "testoptionvalueouter": | ||
− | + | optionsinner[i].getElementsByTagName("span")[j].style.display = "none"; | |
+ | break; | ||
+ | case "ref": | ||
+ | notes++; | ||
+ | document.getElementById("note" + notes).style.display = "none"; | ||
break; | break; | ||
default: | default: | ||
Zeile 43: | Zeile 71: | ||
function auswertung (numberofcategories) { | function auswertung (numberofcategories) { | ||
+ | notes = 0 | ||
+ | clicked = 0 | ||
+ | restorenotes = document.getElementById("suchttest").getElementsByTagName("span"); | ||
+ | for (var i = 0; i < restorenotes.length; i++) | ||
+ | { | ||
+ | if (restorenotes[i].className == "refnumber") | ||
+ | { | ||
+ | notes++; | ||
+ | restorenotes[i].innerHTML = notes; | ||
+ | } | ||
+ | } | ||
+ | notes = 0 | ||
for (var i = 0; i < numberofoptions; i++) | for (var i = 0; i < numberofoptions; i++) | ||
{ | { | ||
− | if (document. | + | if (document.getElementsByTagName("input")[i].checked == true) |
{ | { | ||
− | suchtpotential = suchtpotential + Number(document. | + | clicked++ |
− | for (var j = 0; j < | + | suchtpotential = suchtpotential + Number(document.getElementsByTagName("input")[i].value); |
+ | for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++) | ||
{ | { | ||
− | if ( | + | if (optionsinner[i].getElementsByTagName("span")[j].className == "testoptionvalueouter") |
+ | { | ||
+ | optionsinner[i].getElementsByTagName("span")[j].style.display = "block"; | ||
+ | } | ||
+ | if (optionsinner[i].getElementsByTagName("span")[j].className == "refnumber") | ||
{ | { | ||
− | + | notenumber = document.getElementById("note" + optionsinner[i].getElementsByTagName("span")[j].innerHTML); | |
+ | notenumber.style.display = "block"; | ||
+ | notes++ | ||
+ | optionsinner[i].getElementsByTagName("span")[j].innerHTML = notes; | ||
+ | for (var k = 0; k < notenumber.getElementsByTagName("span").length; k++) | ||
+ | { | ||
+ | if (notenumber.getElementsByTagName("span")[k].className == "notenumber") | ||
+ | { | ||
+ | notenumber.getElementsByTagName("span")[k].innerHTML = notes; | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
} else { | } else { | ||
− | for (var j = 0; j < | + | for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++) |
{ | { | ||
− | if ( | + | if (optionsinner[i].getElementsByTagName("span")[j].className == "testoptionvalueouter") |
+ | { | ||
+ | optionsinner[i].getElementsByTagName("span")[j].style.display = "none"; | ||
+ | } | ||
+ | if (optionsinner[i].getElementsByTagName("span")[j].className == "refnumber") | ||
{ | { | ||
− | + | document.getElementById("note" + optionsinner[i].getElementsByTagName("span")[j].innerHTML).style.display = "none"; | |
} | } | ||
} | } | ||
} | } | ||
} | } | ||
− | + | if(clicked == numberofoptions) | |
− | |||
− | |||
{ | { | ||
− | + | document.getElementById("defaulttext").innerHTML = document.getElementById("allesanklicktext").innerHTML; | |
+ | document.getElementById("suchtomat").style.backgroundImage = 'url(../images/f/f2/WiMu%27s_Tapete.jpg)' | ||
+ | document.getElementById("suchtomat").style.height = '100%' | ||
+ | document.getElementById("result").innerHTML = "(verrat' ich nicht!)" | ||
+ | } else { | ||
+ | document.getElementById("suchtomat").style.backgroundImage = 'none'; | ||
+ | var maxpoints = document.getElementById("maxpoints").innerHTML; | ||
+ | var percent = Math.round((suchtpotential / maxpoints) * 100); | ||
+ | for (var i = 0; i <= numberofcategories; i++) | ||
{ | { | ||
− | document.getElementById("defaulttext").innerHTML = "<ul><li><b>Du hast " + suchtpotential + " von " + maxpoints + " möglichen Punkten erreicht</b><br>" + categories['text' + i] + "</ul></li>"; | + | if(suchtpotential >= categories['min' + i] && suchtpotential <= categories['max' + i]) |
+ | { | ||
+ | document.getElementById("defaulttext").innerHTML = "<ul><li><b>Du hast " + suchtpotential + " von " + maxpoints + " möglichen Punkten erreicht</b><br>" + categories['text' + i] + "</ul></li>"; | ||
+ | } | ||
+ | } | ||
+ | if(percent >= 0) | ||
+ | { | ||
+ | document.getElementById("suchtomat").style.backgroundColor = 'rgb(' + percent + '%,' + (100 - percent) + '%,0%)'; | ||
+ | document.getElementById("suchtomat").style.height = 75 + (percent * 1.55) + 'px'; | ||
+ | document.getElementById("suchtomat").style.display = "block"; | ||
+ | } else { | ||
+ | document.getElementById("suchtomat").style.display = "none"; | ||
} | } | ||
− | + | document.getElementById("result").innerHTML = '(' + suchtpotential + ' Punkte)' | |
− | |||
− | |||
− | document.getElementById(" | ||
− | |||
− | |||
− | |||
− | |||
}; | }; | ||
− | |||
suchtpotential = 0; | suchtpotential = 0; | ||
}; | }; | ||
Zeile 99: | Zeile 167: | ||
function checksuboptions(nr) { | function checksuboptions(nr) { | ||
− | if (document. | + | if (document.getElementsByTagName("input")[nr].checked == true && optionsouter[nr].getElementsByTagName("ul")[0]) |
{ | { | ||
− | + | optionsouter[nr].getElementsByTagName("ul")[0].style.display = "block"; | |
} | } | ||
− | if (document. | + | if (document.getElementsByTagName("input")[nr].checked == false && optionsouter[nr].getElementsByTagName("ul")[0]) |
{ | { | ||
− | suboptions = | + | suboptions = optionsouter[nr].getElementsByTagName("ul"); |
numberofsuboptions = suboptions.length; | numberofsuboptions = suboptions.length; | ||
for (var i = 0; i < numberofsuboptions; i++) | for (var i = 0; i < numberofsuboptions; i++) | ||
Zeile 111: | Zeile 179: | ||
suboptions[i].style.display = "none"; | suboptions[i].style.display = "none"; | ||
suboptions[i].innerHTML = suboptions[i].innerHTML; | suboptions[i].innerHTML = suboptions[i].innerHTML; | ||
+ | } | ||
+ | } | ||
+ | if (document.getElementsByTagName("input")[nr].name != "") | ||
+ | { | ||
+ | radioname = document.getElementsByTagName("input")[nr].name; | ||
+ | for (var i = 0; i < numberofoptions; i++) | ||
+ | { | ||
+ | if(document.getElementsByTagName("input")[i].name == radioname && document.getElementsByTagName("input")[i].checked == false && optionsouter[i].getElementsByTagName("ul")[0]) | ||
+ | { | ||
+ | suboptions = optionsouter[i].getElementsByTagName("ul"); | ||
+ | numberofsuboptions = suboptions.length; | ||
+ | for (var j = 0; j < numberofsuboptions; j++) | ||
+ | { | ||
+ | suboptions[j].style.display = "none"; | ||
+ | suboptions[j].innerHTML = suboptions[j].innerHTML; | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
}; | }; |
Aktuelle Version vom 30. Juni 2015, 15:34 Uhr
/********************************************************************************
* *
* Hinweis: irgendwie funktioniert's (sollte es zumindest) *
* aber fragt mich bloß nicht, wie ... *
* Vermutlich ist das hier alles total umständlich und alles *
* andere als übliches javascript. Aber ich bin ja noch am *
* lernen. *
* *
* --[[Kamel:WiMu|WiMu 12:13, 16. Apr. 2009 (CEST) *
* *
********************************************************************************/
window.onload = function ()
{
suchtpotential = 0
optionvalue = 0
notes = 0
if(document.getElementById("suchttest"))
{
makeoptions ();
prepare (document.getElementById("numberofcategories").innerHTML);
}
};
function makeoptions () {
optionsouter = document.getElementById("suchttest").getElementsByTagName("li");
optionsinner = document.getElementById("suchttest").getElementsByTagName("div");
numberofoptions = 0;
for (var i = 0; i < optionsinner.length; i++)
{
if (optionsinner[i].className == "testoption")
{
numberofoptions++
}
}
for (var i = 0; i < numberofoptions; i++)
{
for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++)
{
switch (optionsinner[i].getElementsByTagName("span")[j].className.split("/")[0])
{
case "testoptionvalueinner":
optionvalue = optionsinner[i].getElementsByTagName("span")[j].innerHTML;
break;
case "checkbox":
optionsinner[i].getElementsByTagName("span")[j].innerHTML = '<input type="checkbox" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">';
break;
case "radio":
optionsinner[i].getElementsByTagName("span")[j].innerHTML = '<input type="radio" name="' + optionsinner[i].getElementsByTagName("span")[j].className.split("/")[1] + '" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">';
break;
case "testoptionvalueouter":
optionsinner[i].getElementsByTagName("span")[j].style.display = "none";
break;
case "ref":
notes++;
document.getElementById("note" + notes).style.display = "none";
break;
default:
break;
}
}
}
suboptions = document.getElementById("suchttest").getElementsByTagName("ul");
numberofsuboptions = suboptions.length;
for (var i = 0; i < numberofsuboptions; i++)
{
suboptions[i].style.display = "none"
};
document.getElementById("auswertungsknopp").innerHTML = '<input type="button" name="Auswertung" value="auswerten" onclick="auswertung(' + "'" + document.getElementById("numberofcategories").innerHTML + "'" + ')"><span id="result" style="position:absolute; right:0px; top:0px;"></span>';
};
function auswertung (numberofcategories) {
notes = 0
clicked = 0
restorenotes = document.getElementById("suchttest").getElementsByTagName("span");
for (var i = 0; i < restorenotes.length; i++)
{
if (restorenotes[i].className == "refnumber")
{
notes++;
restorenotes[i].innerHTML = notes;
}
}
notes = 0
for (var i = 0; i < numberofoptions; i++)
{
if (document.getElementsByTagName("input")[i].checked == true)
{
clicked++
suchtpotential = suchtpotential + Number(document.getElementsByTagName("input")[i].value);
for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++)
{
if (optionsinner[i].getElementsByTagName("span")[j].className == "testoptionvalueouter")
{
optionsinner[i].getElementsByTagName("span")[j].style.display = "block";
}
if (optionsinner[i].getElementsByTagName("span")[j].className == "refnumber")
{
notenumber = document.getElementById("note" + optionsinner[i].getElementsByTagName("span")[j].innerHTML);
notenumber.style.display = "block";
notes++
optionsinner[i].getElementsByTagName("span")[j].innerHTML = notes;
for (var k = 0; k < notenumber.getElementsByTagName("span").length; k++)
{
if (notenumber.getElementsByTagName("span")[k].className == "notenumber")
{
notenumber.getElementsByTagName("span")[k].innerHTML = notes;
}
}
}
}
} else {
for (var j = 0; j < optionsinner[i].getElementsByTagName("span").length; j++)
{
if (optionsinner[i].getElementsByTagName("span")[j].className == "testoptionvalueouter")
{
optionsinner[i].getElementsByTagName("span")[j].style.display = "none";
}
if (optionsinner[i].getElementsByTagName("span")[j].className == "refnumber")
{
document.getElementById("note" + optionsinner[i].getElementsByTagName("span")[j].innerHTML).style.display = "none";
}
}
}
}
if(clicked == numberofoptions)
{
document.getElementById("defaulttext").innerHTML = document.getElementById("allesanklicktext").innerHTML;
document.getElementById("suchtomat").style.backgroundImage = 'url(../images/f/f2/WiMu%27s_Tapete.jpg)'
document.getElementById("suchtomat").style.height = '100%'
document.getElementById("result").innerHTML = "(verrat' ich nicht!)"
} else {
document.getElementById("suchtomat").style.backgroundImage = 'none';
var maxpoints = document.getElementById("maxpoints").innerHTML;
var percent = Math.round((suchtpotential / maxpoints) * 100);
for (var i = 0; i <= numberofcategories; i++)
{
if(suchtpotential >= categories['min' + i] && suchtpotential <= categories['max' + i])
{
document.getElementById("defaulttext").innerHTML = "<ul><li><b>Du hast " + suchtpotential + " von " + maxpoints + " möglichen Punkten erreicht</b><br>" + categories['text' + i] + "</ul></li>";
}
}
if(percent >= 0)
{
document.getElementById("suchtomat").style.backgroundColor = 'rgb(' + percent + '%,' + (100 - percent) + '%,0%)';
document.getElementById("suchtomat").style.height = 75 + (percent * 1.55) + 'px';
document.getElementById("suchtomat").style.display = "block";
} else {
document.getElementById("suchtomat").style.display = "none";
}
document.getElementById("result").innerHTML = '(' + suchtpotential + ' Punkte)'
};
suchtpotential = 0;
};
function prepare (numberofcategories) {
categories = new Array();
for (var i = 0; i <= numberofcategories; i++)
{
categories['min' + i] = document.getElementById('min' + i).innerHTML;
categories['max' + i] = document.getElementById('max' + i).innerHTML;
categories['text' + i] = document.getElementById('text' + i).innerHTML;
}
document.getElementById("auswertungstext").style.display = "none";
document.getElementById("defaulttext").style.display = "inline";
};
function checksuboptions(nr) {
if (document.getElementsByTagName("input")[nr].checked == true && optionsouter[nr].getElementsByTagName("ul")[0])
{
optionsouter[nr].getElementsByTagName("ul")[0].style.display = "block";
}
if (document.getElementsByTagName("input")[nr].checked == false && optionsouter[nr].getElementsByTagName("ul")[0])
{
suboptions = optionsouter[nr].getElementsByTagName("ul");
numberofsuboptions = suboptions.length;
for (var i = 0; i < numberofsuboptions; i++)
{
suboptions[i].style.display = "none";
suboptions[i].innerHTML = suboptions[i].innerHTML;
}
}
if (document.getElementsByTagName("input")[nr].name != "")
{
radioname = document.getElementsByTagName("input")[nr].name;
for (var i = 0; i < numberofoptions; i++)
{
if(document.getElementsByTagName("input")[i].name == radioname && document.getElementsByTagName("input")[i].checked == false && optionsouter[i].getElementsByTagName("ul")[0])
{
suboptions = optionsouter[i].getElementsByTagName("ul");
numberofsuboptions = suboptions.length;
for (var j = 0; j < numberofsuboptions; j++)
{
suboptions[j].style.display = "none";
suboptions[j].innerHTML = suboptions[j].innerHTML;
}
}
}
}
};