brendanheywood / moodle-local_cleanurls

Lets drag Moodle's url structure into this century...
37 stars 24 forks source link

Javascript "TypeError: element is undefined" #97

Closed nyanginator closed 7 years ago

nyanginator commented 7 years ago

I've only tested on Chrome and Firefox, and it seems to be just a Firefox issue as far as I can tell. In the browser's debug console, "TypeError: element is undefined" keeps showing up on course pages when I'm logged in, even when I just right-click on the page. Doesn't seem to show on admin settings pages.

Adding "if (element) { ... }" in url_rewriter.php seems to fix it:

document.addEventListener('click', function (event) {
    var element = event.srcElement;
    if (element) { // **Here**
        while (element.tagName != 'A') {
            if (!element.parentElement) {
                return;
            }
            element = element.parentElement;
        }
        if (element.getAttribute('href').charAt(0) == '#') {
            element.href = '{$clean}' + element.getAttribute('href');
        }
    } // **And closing bracket**
}, true);
</script>
brendanheywood commented 7 years ago

thanks @nyanginator - any chance you can make a pull request for that patch?