pygame-guide-for-sneks / pygame-guide-for-sneks.github.io

https://pygame-guide-for-sneks.github.io
MIT License
12 stars 8 forks source link

Slight tweak to `format.js` #60

Closed oddbookworm closed 1 year ago

oddbookworm commented 2 years ago

In /scripts/format.js,

function toc() {
    let headers = document.getElementsByClassName('js');
    let html = '';

    for (let i = 0; i < headers.length; i++) {
        title = headers[i].parentNode.textContent;
        cls = headers[i].getAttribute("id");
        html += '<li><a href="#' + cls + '">' + title + '</a></li>';
    }

    table_of_contents.innerHTML = html;
}

should be tweaked to

function toc() {
    let headers = document.getElementsByClassName('js');
    let html = '';

    for (let h of headers) {
        title = h.parentNode.textContent;
        cls = h.getAttribute("id");
        html += '<li><a href="#' + cls + '">' + title + '</a></li>';
    }

    table_of_contents.innerHTML = html;
}

Don't make a PR just for this, save it for the next miscellaneous tweaks/bugfix PR. This is just a slight code aesthetics choice

oddbookworm commented 2 years ago

Further suggested edits: Change

linked_button.onclick = function () {
        // HAS to be linked_buttons[i] instead of linked_button; I *think* it's because
        // it just takes the last linked button's url cuz of the loop
        location.href = linked_button.dataset.url;
    }

to

linked_button.onclick = () => {
        location.href = linked_button.dataset.url;
    }