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
27 changes: 13 additions & 14 deletions js/NarrativeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,32 +254,31 @@ class NarrativeView extends ComponentView {
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 prevBody = prevItem ? prevItem.get('body') : '';

if (isAtStart) {
prevTitle = this.model.getItem(totalItems - 1).get('title');
backItem = totalItems;
}
if (isAtEnd) {
nextTitle = this.model.getItem(0).get('title');
nextItem = 1;
}
const nextTitle = nextItem ? nextItem.get('title') : '';
const nextBody = nextItem ? nextItem.get('body') : '';

const prevItemNumber = isAtStart ? null : index;
const nextItemNumber = isAtEnd ? null : index + 2;

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

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

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": "{{#any title body}}{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/any}}",
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved
"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": "{{#any title body}}{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/any}}",
"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": "{{#any title body}}{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/any}}",
"_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": "{{#any title body}}{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/any}}",
"_adapt": {
"translatable": true
}
Expand Down