aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2018-05-28 22:29:43 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2018-05-28 22:29:43 -0400
commit7329f6b99596c386ac8dfb5dd2849d3bc80fff44 (patch)
tree77fd730d240573dcfb20bac7dbf5033db49c0711
parent463b5bb820d0b8b9abab317491015d2f08d19cde (diff)
downloadGradeBook-7329f6b99596c386ac8dfb5dd2849d3bc80fff44.tar.gz
GradeBook-7329f6b99596c386ac8dfb5dd2849d3bc80fff44.zip
added javascript to read and set cookies for display style, as well to use these cookies
-rw-r--r--GradeBook.js49
1 files changed, 47 insertions, 2 deletions
diff --git a/GradeBook.js b/GradeBook.js
index 269f008..18652c8 100644
--- a/GradeBook.js
+++ b/GradeBook.js
@@ -1,15 +1,32 @@
function toggleHTMLClassVisibility(className) {
var x = document.getElementsByClassName(className);
var i;
+ var display_style = "block"; // default
for (i = 0; i < x.length; i++) {
if (x[i].style.display === "none") {
- x[i].style.display = "block";
+ display_style = "block";
} else {
- x[i].style.display = "none";
+ 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 = "block"; // 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");
};
@@ -18,3 +35,31 @@ function toggleGradingScheme() {
toggleHTMLClassVisibility("grading_scheme");
};
+// 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");
+ return "";
+}
+