Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bryantaylor 0:eafc3fd41f75 1 <script>
bryantaylor 0:eafc3fd41f75 2 var elements = document.querySelectorAll(".toggleshow"),
bryantaylor 0:eafc3fd41f75 3 hideClass = 'toggleshow-hide';
bryantaylor 0:eafc3fd41f75 4
bryantaylor 0:eafc3fd41f75 5 for (var i = 0; i < elements.length; i++) {
bryantaylor 0:eafc3fd41f75 6 var arrow = elements[i].querySelector(".toggleshow-arrow");
bryantaylor 0:eafc3fd41f75 7 // Initial hide/show based on class
bryantaylor 0:eafc3fd41f75 8 // Update arrow as well
bryantaylor 0:eafc3fd41f75 9 if (containsClass(elements[i], 'toggleshow-hide')) {
bryantaylor 0:eafc3fd41f75 10 toggleDisplay(elements[i]);
bryantaylor 0:eafc3fd41f75 11 changeArrow(arrow, false);
bryantaylor 0:eafc3fd41f75 12 } else {
bryantaylor 0:eafc3fd41f75 13 changeArrow(arrow, true);
bryantaylor 0:eafc3fd41f75 14 }
bryantaylor 0:eafc3fd41f75 15
bryantaylor 0:eafc3fd41f75 16 // Add click handler
bryantaylor 0:eafc3fd41f75 17 addClick(elements[i], toggleDisplay);
bryantaylor 0:eafc3fd41f75 18 }
bryantaylor 0:eafc3fd41f75 19
bryantaylor 0:eafc3fd41f75 20 function containsClass(element, className) {
bryantaylor 0:eafc3fd41f75 21 var eleClassName = ' ' + elements[i].className + ' ';
bryantaylor 0:eafc3fd41f75 22 return eleClassName.indexOf(' ' + className + ' ') > -1;
bryantaylor 0:eafc3fd41f75 23 }
bryantaylor 0:eafc3fd41f75 24
bryantaylor 0:eafc3fd41f75 25 function toggleDisplay(parentElement) {
bryantaylor 0:eafc3fd41f75 26 var body = parentElement.querySelector(".toggleshow-body"),
bryantaylor 0:eafc3fd41f75 27 arrow = parentElement.querySelector(".toggleshow-arrow");
bryantaylor 0:eafc3fd41f75 28
bryantaylor 0:eafc3fd41f75 29 if (body.style.display == 'block' || body.style.display == '') {
bryantaylor 0:eafc3fd41f75 30 body.style.display = 'none';
bryantaylor 0:eafc3fd41f75 31 changeArrow(arrow, false);
bryantaylor 0:eafc3fd41f75 32 } else {
bryantaylor 0:eafc3fd41f75 33 body.style.display = 'block';
bryantaylor 0:eafc3fd41f75 34 changeArrow(arrow, true);
bryantaylor 0:eafc3fd41f75 35 }
bryantaylor 0:eafc3fd41f75 36 }
bryantaylor 0:eafc3fd41f75 37
bryantaylor 0:eafc3fd41f75 38 function changeArrow(element, visible) {
bryantaylor 0:eafc3fd41f75 39 if (visible) {
bryantaylor 0:eafc3fd41f75 40 element.innerHTML = '&#9650';
bryantaylor 0:eafc3fd41f75 41 } else {
bryantaylor 0:eafc3fd41f75 42 element.innerHTML = '&#9660';
bryantaylor 0:eafc3fd41f75 43 }
bryantaylor 0:eafc3fd41f75 44 }
bryantaylor 0:eafc3fd41f75 45
bryantaylor 0:eafc3fd41f75 46 function addClick(parentElement, func) {
bryantaylor 0:eafc3fd41f75 47 parentElement.querySelector(".toggleshow-title").addEventListener("click", function(e) {
bryantaylor 0:eafc3fd41f75 48 func(parentElement);
bryantaylor 0:eafc3fd41f75 49 e.preventDefault();
bryantaylor 0:eafc3fd41f75 50 return false;
bryantaylor 0:eafc3fd41f75 51 });
bryantaylor 0:eafc3fd41f75 52 }
bryantaylor 0:eafc3fd41f75 53 </script>