fix: courseware-chromeless: cancel click event only when target is found

Cancel the click event on anchor tag only when the target
element is found.

Fixes: TNL-8445
This commit is contained in:
Arjun Singh Yadav
2021-07-08 22:51:51 +05:30
parent b24e65903d
commit 6a52bfa4ce

View File

@@ -141,12 +141,14 @@ ${HTML(fragment.foot_html())}
// required for proper scrolling.
$('a').on("click", function(event){
if ($(this).attr('href')[0] === "#") {
event.preventDefault();
var targetId = $(this).attr('href');
var targetName = $(this).attr('href').slice(1);
// Checks if the target uses an id or name to focus and gets offset.
var targetOffset = $(targetId).offset() || $(document.getElementsByName(targetName)[0]).offset();
window.parent.postMessage({"offset": targetOffset.top}, document.referrer);
if (targetOffset) {
event.preventDefault();
window.parent.postMessage({"offset": targetOffset.top}, document.referrer);
}
}
})
return;