Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<script>
MemberStack.onReady.then(async function(member) {
// setup
var loadingClass = 'loading'
var completedClass = 'completed';
var notCompletedClass = 'notcompleted';
var lessonItemClass = '.lessonitem';
var lessonsId = 'lessons';
// set default state
var completedState = notCompletedClass;
// fetch remote metadata
let metadata = await member.getMetaData()
var completedLessons = metadata.completed ? metadata.completed : [];
// get all of the lesson links listed (from CMS Collection)
var links = document.getElementById(lessonsId).getElementsByTagName('a');
// loop all of the links
for (let l = 0; l < links.length; l++) {
// setup the current link variables
var link = links[l];
var linkUrl = link.href;
// loop all links found in the JSON stored in MemberStack
for (let c = 0; c < completedLessons.length; c++) {
// set the current url stored in MemberStack
var completedUrl = completedLessons[c];
// if the current link and stored link match
if (linkUrl === completedUrl) {
// set completed state
completedState = completedClass;
// break out of this for loop and
// check the next link
c = completedLessons.length;
} else {
// set completed state
completedState = notCompletedClass;
}
}
// display completed state to screen
let lessonItem = link.closest(lessonItemClass);
(completedState === completedClass) ? displayCompleted(lessonItem): displayNotCompleted(lessonItem);
}
// show the completed state
function displayCompleted(lessonItem) {
lessonItem.getElementsByClassName(loadingClass)[0].style.display = 'none';
lessonItem.getElementsByClassName(completedClass)[0].style.display = 'block';
lessonItem.getElementsByClassName(notCompletedClass)[0].style.display = 'none';
}
// show the not completed state
function displayNotCompleted(lessonItem) {
lessonItem.getElementsByClassName(loadingClass)[0].style.display = 'none';
lessonItem.getElementsByClassName(notCompletedClass)[0].style.display = 'block';
lessonItem.getElementsByClassName(completedClass)[0].style.display = 'none';
}
})
</script>