From 212a942c4ee9f1a0a431fb5ed754041b523d190a Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Tue, 23 Apr 2024 09:49:25 +0100 Subject: [PATCH] Fix: _loopStyle bad configuration (fixes #62) --- js/PageNavModel.js | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/js/PageNavModel.js b/js/PageNavModel.js index b9444a1..208ef5c 100644 --- a/js/PageNavModel.js +++ b/js/PageNavModel.js @@ -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() {