| 1 |
/** |
| 2 |
* Front-end behaviour for the [accordion_metasync] shortcode. |
| 3 |
* |
| 4 |
* Vanilla JS on purpose: this is the only script the shortcode needs, and |
| 5 |
* depending on jQuery here forced jQuery to load on every front-end request. |
| 6 |
*/ |
| 7 |
(function () { |
| 8 |
'use strict'; |
| 9 |
|
| 10 |
function init() { |
| 11 |
var panels = document.querySelectorAll('.metasync-accordion-block.metasync-panel'); |
| 12 |
for (var i = 0; i < panels.length; i++) { |
| 13 |
panels[i].style.display = 'none'; |
| 14 |
} |
| 15 |
|
| 16 |
var buttons = document.querySelectorAll('button.metasync-accordion'); |
| 17 |
for (var j = 0; j < buttons.length; j++) { |
| 18 |
buttons[j].addEventListener('click', function (event) { |
| 19 |
// Mirrors the jQuery handler's `return false` (preventDefault + stopPropagation). |
| 20 |
event.preventDefault(); |
| 21 |
event.stopPropagation(); |
| 22 |
|
| 23 |
if (this.parentNode && this.parentNode.classList) { |
| 24 |
this.parentNode.classList.toggle('metasync-active'); |
| 25 |
} |
| 26 |
}); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
if (document.readyState === 'loading') { |
| 31 |
document.addEventListener('DOMContentLoaded', init); |
| 32 |
} else { |
| 33 |
init(); |
| 34 |
} |
| 35 |
})(); |
| 36 |
|