From 9648eb3a5da9cf53fac1b558c8e4e1adf9c5784c Mon Sep 17 00:00:00 2001
From: Ny11 <Ny11>
Date: Wed, 20 Feb 2019 18:26:17 +0100
Subject: [PATCH] Accordion extension

*Workaround that enables accordion to function for tables
*Since for tables, the nextElementSibling should always fail(resulting in null for panel), the new code is used when that happens. Kind of hacky, so might need to be changed
*The style-sheet was minimally extended, so the +/- are applied to divs as well
---
 src/gui/css/accordianStyleSheet.tw | 11 +++++++++++
 src/js/accordianJS.js              | 17 +++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/gui/css/accordianStyleSheet.tw b/src/gui/css/accordianStyleSheet.tw
index a66921016a7..324a2383518 100644
--- a/src/gui/css/accordianStyleSheet.tw
+++ b/src/gui/css/accordianStyleSheet.tw
@@ -71,3 +71,14 @@ button.accordion.active:before {
 	max-height: 0;
 	overflow: hidden;
 }
+
+div.accordion:before {
+	content: '\002B';
+	color: #777;
+	font-weight: bold;
+	float: left;
+	margin-right: 5px;
+}
+div.accordion.active:before {
+	content: "\2212";
+}
diff --git a/src/js/accordianJS.js b/src/js/accordianJS.js
index 622a41c09b2..0b31fa239c3 100644
--- a/src/js/accordianJS.js
+++ b/src/js/accordianJS.js
@@ -30,10 +30,19 @@ postdisplay["doAccordion"] = function (content) {
 		acc[i].onclick = function () {
 			this.classList.toggle("active");
 			var panel = this.nextElementSibling;
-			if (panel.style.maxHeight) {
-				panel.style.maxHeight = null;
-			} else {
-				panel.style.maxHeight = 2 * panel.scrollHeight + "px";
+			if(panel == null || panel == undefined){
+				panel = document.getElementById(this.id + "accHidden");
+				if( panel.style.display=='none' ){
+					panel.style.display = '';
+				}else{
+					panel.style.display = 'none';
+				}
+			}else{
+				if (panel.style.maxHeight) {
+					panel.style.maxHeight = null;
+				} else {
+					panel.style.maxHeight = 2 * panel.scrollHeight + "px";
+				}
 			}
 		};
 	}
-- 
GitLab