MediaWiki:Skin/Suchttest.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
K (so, + suchtometer, bessere dpl-Unterstützung und im IE sollte es jetzt auch funktionieren (cache entleeren nicht vergessen) *daumenrdück*)
(update: +klippklapp, +kleinerbugfix *daumendrück*)
Zeile 23: Zeile 23:
 
break;
 
break;
 
case "checkbox":
 
case "checkbox":
options[i].getElementsByTagName("span")[j].innerHTML = '<input type="checkbox" name="suchtoption" value="' + optionvalue + '">';
+
options[i].getElementsByTagName("span")[j].innerHTML = '<input type="checkbox" name="suchtoption" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">';
 
break;
 
break;
 
case "testoptionvalueouter":
 
case "testoptionvalueouter":
Zeile 33: Zeile 33:
 
}
 
}
 
}
 
}
 +
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>';
 
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>';
 
};
 
};
Zeile 72: Zeile 78:
 
document.getElementById("suchtomat").style.backgroundColor = 'rgb(' + percent + '%,' + (100 - 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.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("result").innerHTML = '(' + suchtpotential + ' Punkte)'
 
suchtpotential = 0;
 
suchtpotential = 0;
Zeile 87: Zeile 96:
 
document.getElementById("auswertungstext").style.display = "none";
 
document.getElementById("auswertungstext").style.display = "none";
 
document.getElementById("defaulttext").style.display    = "inline";
 
document.getElementById("defaulttext").style.display    = "inline";
 +
};
 +
 +
function checksuboptions(nr) {
 +
if (document.getElementsByName("suchtoption")[nr].checked == true && options[nr].getElementsByTagName("ul")[0])
 +
{
 +
options[nr].getElementsByTagName("ul")[0].style.display = "block";
 +
}
 +
if (document.getElementsByName("suchtoption")[nr].checked == false && options[nr].getElementsByTagName("ul")[0])
 +
{
 +
suboptions = options[nr].getElementsByTagName("ul");
 +
numberofsuboptions = suboptions.length;
 +
for (var i = 0; i < numberofsuboptions; i++)
 +
{
 +
suboptions[i].style.display = "none";
 +
suboptions[i].innerHTML = suboptions[i].innerHTML;
 +
}
 +
}
 
};
 
};

Version vom 10. April 2009, 11:25 Uhr

window.onload = function ()
	{
	suchtpotential = 0
	optionvalue    = 0
	if(document.getElementById("suchttest"))
		{
		makeoptions ();
		prepare (document.getElementById("numberofcategories").innerHTML);
		}
	};

function makeoptions () {
	options = document.getElementById("suchttest").getElementsByTagName("li")
	numberofoptions = options.length;
	for (var i = 0; i < numberofoptions; i++)
		{
		for (var j = 0; j < options[i].getElementsByTagName("span").length; j++)
			{
			switch (options[i].getElementsByTagName("span")[j].className)
				{
				case "testoptionvalueinner":
					optionvalue = options[i].getElementsByTagName("span")[j].innerHTML;
					break;
				case "checkbox":
					options[i].getElementsByTagName("span")[j].innerHTML = '<input type="checkbox" name="suchtoption" value="' + optionvalue + '" onclick="checksuboptions(' + i + ')">';
					break;
				case "testoptionvalueouter":
					options[i].getElementsByTagName("span")[j].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) {
	for (var i = 0; i < numberofoptions; i++)
		{
		if (document.getElementsByName("suchtoption")[i].checked == true)
			{
			suchtpotential = suchtpotential + Number(document.getElementsByName("suchtoption")[i].value);
			for (var j = 0; j < options[i].getElementsByTagName("span").length; j++)
				{
				if (options[i].getElementsByTagName("span")[j].className == "testoptionvalueouter")
					{
					options[i].getElementsByTagName("span")[j].style.display = "block";
					}
				}
			} else {
			for (var j = 0; j < options[i].getElementsByTagName("span").length; j++)
				{
				if (options[i].getElementsByTagName("span")[j].className == "testoptionvalueouter")
					{
					options[i].getElementsByTagName("span")[j].style.display = "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.getElementsByName("suchtoption")[nr].checked == true && options[nr].getElementsByTagName("ul")[0])
		{
		options[nr].getElementsByTagName("ul")[0].style.display = "block";
		}
	if (document.getElementsByName("suchtoption")[nr].checked == false && options[nr].getElementsByTagName("ul")[0])
		{
		suboptions = options[nr].getElementsByTagName("ul");
		numberofsuboptions = suboptions.length;
		for (var i = 0; i < numberofsuboptions; i++)
			{
			suboptions[i].style.display = "none";
			suboptions[i].innerHTML = suboptions[i].innerHTML;
			}
		}
	};