Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions js/editor-libs/mce-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ module.exports = {

return tmpElem.style[property] !== undefined;
},
/**
* Interrupts the default click event on external links inside
* the shadow dom and opens them in a new tab instead
* @param {Array} externalLinks - all external links inside the shadow dom
*/
openLinksInNewTab: function(externalLinks) {
externalLinks.forEach(function(externalLink) {
externalLink.addEventListener('click', function(event) {
event.preventDefault();
window.open(externalLink.href);
});
});
},
/**
* Posts a name to set as a mark to Kuma for
* processing and beaconing to GA
Expand All @@ -45,6 +58,20 @@ module.exports = {
postToKuma: function(perf) {
window.parent.postMessage(perf, 'https://developer.mozilla.org');
},
/**
* Interrupts the default click event on relative links inside
* the shadow dom and scrolls to the targeted anchor
* @param {Object} shadow - the shadow dom root
* @param {Array} relativeLinks - all relative links inside the shadow dom
*/
scrollToAnchors: function(shadow, relativeLinks) {
relativeLinks.forEach(function(relativeLink) {
relativeLink.addEventListener('click', function(event) {
event.preventDefault();
shadow.querySelector(relativeLink.hash).scrollIntoView();
});
});
},
/**
* Hides the default example and shows the custom block
* @param {object} customBlock - The HTML section to show
Expand Down
2 changes: 2 additions & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@

shadow.appendChild(document.importNode(content, true));
setOutputHeight(shadow.querySelector('div'));
mceUtils.openLinksInNewTab(shadow.querySelectorAll('a[href^="http"]'));
mceUtils.scrollToAnchors(shadow, shadow.querySelectorAll('a[href^="#"]'));
}

/**
Expand Down