diff --git a/js/NarrativeView.js b/js/NarrativeView.js index 9a0383b..948b3f6 100644 --- a/js/NarrativeView.js +++ b/js/NarrativeView.js @@ -247,40 +247,31 @@ 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 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'); - - let backItem = isAtStart ? null : index; - let nextItem = isAtEnd ? null : index + 2; - - if (isAtStart) { - prevTitle = this.model.getItem(totalItems - 1).get('title'); - backItem = totalItems; - } - if (isAtEnd) { - nextTitle = this.model.getItem(0).get('title'); - nextItem = 1; - } + const isAtEnd = (index === totalItems - 1); + const _globals = Adapt.course.get('_globals'); + const narrativeGlobals = _globals._components._narrative; + const prevItem = isAtStart ? null : this.model.getItem(index - 1); + const nextItem = isAtEnd ? null : this.model.getItem(index + 1); + const prevTitle = prevItem?.get('title') ?? ''; + const nextTitle = nextItem?.get('title') ?? ''; + 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); diff --git a/properties.schema b/properties.schema index 798683e..846f9fd 100644 --- a/properties.schema +++ b/properties.schema @@ -15,7 +15,7 @@ "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 @@ -23,7 +23,7 @@ "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 diff --git a/schema/course.schema.json b/schema/course.schema.json index 1ecd837..9205cd0 100644 --- a/schema/course.schema.json +++ b/schema/course.schema.json @@ -32,7 +32,7 @@ "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 } @@ -40,7 +40,7 @@ "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 }