Script isn't executed in Brightspace LMS

Options
Arman.V.176
Arman.V.176 Posts: 19 🌱

I use a script to automatically add the MIME type of files, which users can download with a download link. However, the scripts works perfectly locally, but in the Brightspace LMS environment the script isn't executed. This might be due to a variety of reasons. For example, conflicting JavaScript or code, restricted environment, customization limitations, insufficient permissions or execution timing, among others. The script is as follows:

// Code adds the MIME type to download links for the 20 most common file types
// Mapping of file extensions to MIME types
const mimeTypeMapping = {
pdf: 'application/pdf',
doc: 'application/msword',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
xls: 'application/vnd.ms-excel',
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
ppt: 'application/vnd.ms-powerpoint',
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
txt: 'text/plain',
csv: 'text/csv',
html: 'text/html',
css: 'text/css',
js: 'application/javascript',
mp3: 'audio/mpeg',
mp4: 'video/mp4',
jpg: 'image/jpeg',
png: 'image/png',
gif: 'image/gif',
zip: 'application/zip',
rar: 'application/x-rar-compressed',
webm: 'video/webm',
ogv: 'video/ogg',
ogg: 'audio/ogg',
};

// Function to add MIME type to download links
function addMimeTypeToLinks() {
const downloadLinks = document.querySelectorAll('a[href$=".pdf"], a[href$=".doc"], a[href$=".docx"], a[href$=".xls"], a[href$=".xlsx"], a[href$=".ppt"], a[href$=".pptx"], a[href$=".txt"], a[href$=".csv"], a[href$=".html"], a[href$=".css"], a[href$=".js"], a[href$=".mp3"], a[href$=".mp4"], a[href$=".jpg"], a[href$=".png"], a[href$=".gif"], a[href$=".zip"], a[href$=".rar"], a[href$=".webm"], a[href$=".ogv"], a[href$=".ogg"]');

downloadLinks.forEach(link => {
const fileExtension = link.href.split('.').pop().toLowerCase();

});
}

// Call the function to add MIME type to links
addMimeTypeToLinks();

// Function to add MIME type to video and audio sources
function addMimeTypeToSources() {
const sources = document.querySelectorAll('source');

sources.forEach(source => {
const fileExtension = source.src.split('.').pop().toLowerCase();

});
}

// Call the function to add MIME type to sources
addMimeTypeToSources();

Any suggestions what might be the cullprit?

Inspecting the page did not result in conflicting code being present. However, using Inspect page for debugging isn't something I'm confident with.

Kind regards,

Arman

Tagged:

Answers

  • Megan.S.88
    Megan.S.88 Posts: 51
    Options

    Hi Arman, We specifically strip scripts out of the Brightspace Editor for safety reasons. This is definitely the culprit.

  • Arman.V.176
    Arman.V.176 Posts: 19 🌱
    Options

    @Megan.S.88 Well, not all scripts are stripped since other scripts, which I added and use work just fine. For what reason are some scripts blocked and others not? Are there some rules? The above mentioned script only adds the type attribute to the download link, but doesn't function in Brightspace. But scripts that add scroll animation using the Intersect Observer API to figures work just fine.

    Kind regards,

    Arman