Skip to content

Commit

Permalink
Fix: _loopStyle bad configuration (fixes #62)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Apr 23, 2024
1 parent 62dab8c commit 212a942
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions js/PageNavModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,16 @@ class PageNavModel extends ComponentModel {

getPages() {
const loopStyle = this.get('_loopStyle');
if (!loopStyle) return [];

let loop = false;
let descendants;
let currentMenu;

switch (loopStyle) {
case 'allPages':
loop = true;
descendants = Adapt.course.getAllDescendantModels(true);
break;
default:
currentMenu = this.getCurrentMenu();
descendants = currentMenu.getAllDescendantModels(true);
}

if (loop) {
// Create a double copy to allow loop searching
const descendants = (loopStyle === 'allPages')
? Adapt.course.getAllDescendantModels(true)
// For siblings and none
: this.getCurrentMenu().getAllDescendantModels(true);
const isLooping = Boolean(loopStyle && loopStyle !== 'none');
if (isLooping) {
// Create a double copy to allow loop searching to fall over the end
descendants = descendants.concat(descendants);
}

return descendants.filter(model => {
return model.get('_type') === 'page';
});
return descendants.filter(model => model.get('_type') === 'page');
}

getClose() {
Expand Down

0 comments on commit 212a942

Please sign in to comment.