dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
mbd_os/tools/ci_templates/scripts.js@1:55a6170b404f, 2016-09-17 (annotated)
- Committer:
- nexpaq
- Date:
- Sat Sep 17 16:32:05 2016 +0000
- Revision:
- 1:55a6170b404f
checking in for sharing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | <script> |
nexpaq | 1:55a6170b404f | 2 | var elements = document.querySelectorAll(".toggleshow"), |
nexpaq | 1:55a6170b404f | 3 | hideClass = 'toggleshow-hide'; |
nexpaq | 1:55a6170b404f | 4 | |
nexpaq | 1:55a6170b404f | 5 | for (var i = 0; i < elements.length; i++) { |
nexpaq | 1:55a6170b404f | 6 | var arrow = elements[i].querySelector(".toggleshow-arrow"); |
nexpaq | 1:55a6170b404f | 7 | // Initial hide/show based on class |
nexpaq | 1:55a6170b404f | 8 | // Update arrow as well |
nexpaq | 1:55a6170b404f | 9 | if (containsClass(elements[i], 'toggleshow-hide')) { |
nexpaq | 1:55a6170b404f | 10 | toggleDisplay(elements[i]); |
nexpaq | 1:55a6170b404f | 11 | changeArrow(arrow, false); |
nexpaq | 1:55a6170b404f | 12 | } else { |
nexpaq | 1:55a6170b404f | 13 | changeArrow(arrow, true); |
nexpaq | 1:55a6170b404f | 14 | } |
nexpaq | 1:55a6170b404f | 15 | |
nexpaq | 1:55a6170b404f | 16 | // Add click handler |
nexpaq | 1:55a6170b404f | 17 | addClick(elements[i], toggleDisplay); |
nexpaq | 1:55a6170b404f | 18 | } |
nexpaq | 1:55a6170b404f | 19 | |
nexpaq | 1:55a6170b404f | 20 | function containsClass(element, className) { |
nexpaq | 1:55a6170b404f | 21 | var eleClassName = ' ' + elements[i].className + ' '; |
nexpaq | 1:55a6170b404f | 22 | return eleClassName.indexOf(' ' + className + ' ') > -1; |
nexpaq | 1:55a6170b404f | 23 | } |
nexpaq | 1:55a6170b404f | 24 | |
nexpaq | 1:55a6170b404f | 25 | function toggleDisplay(parentElement) { |
nexpaq | 1:55a6170b404f | 26 | var body = parentElement.querySelector(".toggleshow-body"), |
nexpaq | 1:55a6170b404f | 27 | arrow = parentElement.querySelector(".toggleshow-arrow"); |
nexpaq | 1:55a6170b404f | 28 | |
nexpaq | 1:55a6170b404f | 29 | if (body.style.display == 'block' || body.style.display == '') { |
nexpaq | 1:55a6170b404f | 30 | body.style.display = 'none'; |
nexpaq | 1:55a6170b404f | 31 | changeArrow(arrow, false); |
nexpaq | 1:55a6170b404f | 32 | } else { |
nexpaq | 1:55a6170b404f | 33 | body.style.display = 'block'; |
nexpaq | 1:55a6170b404f | 34 | changeArrow(arrow, true); |
nexpaq | 1:55a6170b404f | 35 | } |
nexpaq | 1:55a6170b404f | 36 | } |
nexpaq | 1:55a6170b404f | 37 | |
nexpaq | 1:55a6170b404f | 38 | function changeArrow(element, visible) { |
nexpaq | 1:55a6170b404f | 39 | if (visible) { |
nexpaq | 1:55a6170b404f | 40 | element.innerHTML = '▲'; |
nexpaq | 1:55a6170b404f | 41 | } else { |
nexpaq | 1:55a6170b404f | 42 | element.innerHTML = '▼'; |
nexpaq | 1:55a6170b404f | 43 | } |
nexpaq | 1:55a6170b404f | 44 | } |
nexpaq | 1:55a6170b404f | 45 | |
nexpaq | 1:55a6170b404f | 46 | function addClick(parentElement, func) { |
nexpaq | 1:55a6170b404f | 47 | parentElement.querySelector(".toggleshow-title").addEventListener("click", function(e) { |
nexpaq | 1:55a6170b404f | 48 | func(parentElement); |
nexpaq | 1:55a6170b404f | 49 | e.preventDefault(); |
nexpaq | 1:55a6170b404f | 50 | return false; |
nexpaq | 1:55a6170b404f | 51 | }); |
nexpaq | 1:55a6170b404f | 52 | } |
nexpaq | 1:55a6170b404f | 53 | </script> |