aboutsummaryrefslogtreecommitdiff
path: root/GradeBook.js
blob: 4878060d4929ecbe65b36ba4143a594b458a80cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function toggleHTMLClassVisibility(className, defaultVisibleStyle) {
	var x = document.getElementsByClassName(className);
	var i;
	var display_style = defaultVisibleStyle; // default
	for (i = 0; i < x.length; i++) {
		if (x[i].style.display === "none") {
			display_style = defaultVisibleStyle;
		} else {
			display_style = "none";
		}
		x[i].style.display = display_style;
	}
	document.cookie=""+className+"_display_style"+"="+display_style;
};

function setHTMLClassVisibility(className, display_style) {
	// use "block" or "none" for display_style
	if (display_style === "") {
		display_style = ""; // default
	}
	var x = document.getElementsByClassName(className);
	var i;
	for (i = 0; i < x.length; i++) {
		x[i].style.display = display_style;
	}
	document.cookie=""+className+"_display_style"+"="+display_style;
};


function toggleHistogramMarker() {
	toggleHTMLClassVisibility("histogram_marker", "block");
};

function toggleGradingScheme() {
	toggleHTMLClassVisibility("grading_scheme", "block");
};

function toggleControls() {
	toggleHTMLClassVisibility("controls", "");
};

// getCookie is copied from https://www.w3schools.com/js/js_cookies.asp
function getCookie(cname) {
	var name = cname + "=";
	var decodedCookie = decodeURIComponent(document.cookie);
	var ca = decodedCookie.split(';');
	for(var i = 0; i <ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1);
		}
		if (c.indexOf(name) == 0) {
			return c.substring(name.length, c.length);
		}
	}
	return "";
}

function readAndSetVisibility(className) {
	setHTMLClassVisibility( className, getCookie(""+className+"_display_style") );
	return "";
}

function onPageLoad() {
	readAndSetVisibility("histogram_marker");
	readAndSetVisibility("grading_scheme");
	readAndSetVisibility("controls");
	return "";
}