Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Change back and next button labels when at start / end (fixes #310) #311

Merged
merged 12 commits into from
Aug 19, 2024
40 changes: 18 additions & 22 deletions js/NarrativeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,39 +248,35 @@ class NarrativeView extends ComponentView {
setupBackNextLabels(index = this.model.getActiveItem().get('_index')) {
const totalItems = this.model.getChildren().length;

const isAtStart = index === 0;
const isAtEnd = index === totalItems - 1;
const _isAtStart = index === 0;
const _isAtEnd = index === (totalItems - 1);

const globals = Adapt.course.get('_globals');
const narrativeGlobals = globals._components._narrative;
const _globals = Adapt.course.get('_globals');
const narrativeGlobals = _globals._components._narrative;

let prevTitle = isAtStart ? '' : this.model.getItem(index - 1).get('title');
let nextTitle = isAtEnd ? '' : this.model.getItem(index + 1).get('title');
const prevItem = !_isAtStart && this.model.getItem(index - 1);
const nextItem = !_isAtEnd && this.model.getItem(index + 1);

let backItem = isAtStart ? null : index;
let nextItem = isAtEnd ? null : index + 2;
const prevTitle = prevItem ? prevItem.get('title') : '';
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved
const nextTitle = nextItem ? nextItem.get('title') : '';

if (isAtStart) {
prevTitle = this.model.getItem(totalItems - 1).get('title');
backItem = totalItems;
}
if (isAtEnd) {
nextTitle = this.model.getItem(0).get('title');
nextItem = 1;
}
const prevItemNumber = _isAtStart ? null : index;
const nextItemNumber = _isAtEnd ? null : index + 2;

const backLabel = compile(narrativeGlobals.previous, {
_globals: globals,
_globals,
title: prevTitle,
itemNumber: backItem,
totalItems
itemNumber: prevItemNumber,
totalItems,
_isAtStart
});

const nextLabel = compile(narrativeGlobals.next, {
_globals: globals,
_globals,
title: nextTitle,
itemNumber: nextItem,
totalItems
itemNumber: nextItemNumber,
totalItems,
_isAtEnd
});

this.model.set('backLabel', backLabel);
Expand Down
4 changes: 2 additions & 2 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"previous": {
"type": "string",
"required": true,
"default": "{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}})",
"default": "{{#if _isAtStart}}{{_globals._accessibility._ariaLabels.previous}}{{else}}{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{/if}}",
"inputType": "Text",
"validators": [],
"translatable": true
},
"next": {
"type": "string",
"required": true,
"default": "{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}})",
"default": "{{#if _isAtEnd}}{{_globals._accessibility._ariaLabels.next}}{{else}}{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{/if}}",
"inputType": "Text",
"validators": [],
"translatable": true
Expand Down
4 changes: 2 additions & 2 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"previous": {
"type": "string",
"title": "Previous",
"default": "{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}})",
"default": "{{#if _isAtStart}}{{_globals._accessibility._ariaLabels.previous}}{{else}}{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{/if}}",
"_adapt": {
"translatable": true
}
},
"next": {
"type": "string",
"title": "Next",
"default": "{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}})",
"default": "{{#if _isAtEnd}}{{_globals._accessibility._ariaLabels.next}}{{else}}{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{/if}}",
"_adapt": {
"translatable": true
}
Expand Down