var select = document.getElementById('toc-selector');
// transform the TOC into options in a select
function makeTocSelect(entries) {
entries.forEach(function(entry) {
var option = document.createElement('option');
option.innerText = entry.title;
option.value = entry.url;
select.appendChild(option);
// include entries for this entry's children
makeTocSelect(entry.children);
// selection changed, load the HTML
function selectionChanged(e) {
var xhr = new XMLHttpRequest(),
container = document.getElementById('section-content'),
url = e.target.value + '.html',
// get your API token from https://edit.laws.africa/accounts/profile/api/
apiToken = 'YOUR API TOKEN';
xhr.setRequestHeader('Authorization', 'Token ' + apiToken);
xhr.onload = function() {
if (xhr.status === 200) {
container.innerHTML = xhr.responseText;
container.innerText = 'Request failed. Returned status of ' + xhr.status;
// fetch content when the selection changes
select.addEventListener('change', selectionChanged);
// build the select options