* feat: add share link modal when hide from toc is enabled Adds a new button in the child subsections of sections with Hide From TOC enabled. This button displays a new modal with two tabs. The first tab displays a button that allows you to copy the link of that subsection to the clipboard. The second tab displays a button that allows you to copy the embedded link of the same subsection to the clipboard. Ref: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/3853975595/Feature+Enhancement+Proposal+Hide+Sections+from+course+outline
32 lines
929 B
JavaScript
32 lines
929 B
JavaScript
define(["jquery"], function ($) {
|
|
"use strict";
|
|
function copyToClipboard(id, textToCopy) {
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard.writeText(textToCopy);
|
|
changeButtonText(id);
|
|
return;
|
|
}
|
|
const textArea = document.createElement("textarea");
|
|
textArea.value = textToCopy;
|
|
document.body.appendChild(textArea);
|
|
textArea.select();
|
|
document.execCommand("copy");
|
|
document.body.removeChild(textArea);
|
|
changeButtonText(id);
|
|
}
|
|
|
|
function changeButtonText(id, delay = 2000) {
|
|
const buttonId = `#${id}`;
|
|
const textClass = ".copy-link-button-text";
|
|
|
|
const previewShareLinkText = $(buttonId).find(textClass).html();
|
|
const shareLinkCopiedText = gettext("Copied");
|
|
$(buttonId).find(textClass).text(shareLinkCopiedText);
|
|
|
|
setTimeout(() => {
|
|
$(buttonId).find(textClass).text(previewShareLinkText);
|
|
}, delay);
|
|
}
|
|
return { copyToClipboard };
|
|
});
|