* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * fix: failing js test
41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
import { ViewedEventTracker } from './ViewedEvent';
|
|
|
|
const completedBlocksKeys = new Set();
|
|
|
|
export function markBlocksCompletedOnViewIfNeeded(runtime, containerElement) {
|
|
const blockElements = $(containerElement).find(
|
|
'.xblock-student_view[data-mark-completed-on-view-after-delay]',
|
|
).get();
|
|
|
|
if (blockElements.length > 0) {
|
|
const tracker = new ViewedEventTracker();
|
|
|
|
blockElements.forEach((blockElement) => {
|
|
const markCompletedOnViewAfterDelay = parseInt(blockElement.dataset.markCompletedOnViewAfterDelay, 10);
|
|
if (markCompletedOnViewAfterDelay >= 0) {
|
|
tracker.addElement(blockElement, markCompletedOnViewAfterDelay);
|
|
}
|
|
});
|
|
|
|
tracker.addHandler((blockElement, event) => {
|
|
const blockKey = blockElement.dataset.usageId;
|
|
if (blockKey && !completedBlocksKeys.has(blockKey)) {
|
|
if (event.elementHasBeenViewed) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: runtime.handlerUrl(blockElement, 'publish_completion'),
|
|
data: JSON.stringify({
|
|
completion: 1.0,
|
|
}),
|
|
}).then(
|
|
() => {
|
|
completedBlocksKeys.add(blockKey);
|
|
blockElement.dataset.markCompletedOnViewAfterDelay = 0;
|
|
},
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|