Skip to content

Commit

Permalink
Remove _sibling and _returnToPreviousLocation from JS
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck committed Sep 11, 2023
1 parent 7b61218 commit 7c8d863
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
44 changes: 0 additions & 44 deletions js/PageNavModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@ class PageNavModel extends ComponentModel {
const buttonConfig = buttons[type];
let buttonModel = buttonTypeModels[type];

// Generate sibling entries
if (type === '_sibling') {
// Skip if only one sibling
if (buttonModel.length <= 1) continue;

buttonModel.forEach((model, index) => {
item = model.toJSON();
Object.assign(item, buttonConfig, {
type,
index,
_isCurrent: item._id === location._currentId,
order: order++,
_tooltipId: `pagenav_btn${type}-${index}`,
locked: item._isLocked || (buttonConfig._lockUntilPageComplete && !currentPageComplete)
});
unsortedItems.push(item);
});

continue;
}

// Find buttonModel from config._customRouteId if not found in defined type
if (buttonConfig._customRouteId) {
buttonModel = data.findById(buttonConfig._customRouteId);
Expand Down Expand Up @@ -84,23 +63,15 @@ class PageNavModel extends ComponentModel {

getButtonTypeModels() {
return {
_returnToPreviousLocation: this.getReturnToPreviousLocation(),
_page: this.getCurrentPage(),
_up: this.getCurrentMenu(),
_root: Adapt.course,
_next: this.getNextPage(),
_previous: this.getPrevPage(),
_sibling: this.getSiblingPages(),
_close: this.getClose()
};
}

getReturnToPreviousLocation() {
if (!location._previousId) return;

return data.findById(location._previousId);
};

getCurrentPage() {
return location._currentModel;
};
Expand All @@ -109,18 +80,6 @@ class PageNavModel extends ComponentModel {
return this.findAncestor('menu');
};

getSiblingPages() {
const currentMenu = this.getCurrentMenu();
const siblingModels = currentMenu.getAllDescendantModels(true);

return siblingModels.filter(model => {
const isAvailablePage = model.get('_type') === 'page' && model.get('_isAvailable');
const notOptionalOrNotSkipped = !this.get('_shouldSkipOptionalPages') || !model.get('_isOptional');

return isAvailablePage && notOptionalOrNotSkipped;
});
};

getPrevPage() {
const currentPage = this.getCurrentPage();
const currentPageId = currentPage.get('_id');
Expand Down Expand Up @@ -176,9 +135,6 @@ class PageNavModel extends ComponentModel {
loop = true;
descendants = Adapt.course.getAllDescendantModels(true);
break;
case 'siblings':
loop = true;
// falls through
default:
currentMenu = this.getCurrentMenu();
descendants = currentMenu.getAllDescendantModels(true);
Expand Down
2 changes: 1 addition & 1 deletion js/PageNavView.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PageNavView extends ComponentView {
if (!item._tooltip || item._isHidden) return;

tooltips.register({
_id: item._tooltipId,
_id: `pagenav_btn${item.type}`,
_isEnabled: item._tooltip._isEnabled,
text: Handlebars.compile(item._tooltip.text)(item)
});
Expand Down

0 comments on commit 7c8d863

Please sign in to comment.