Skip to content

Commit

Permalink
issue/3281 Added data-order to buttons for sorting navigation (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Feb 7, 2022
1 parent faae481 commit c29eace
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
18 changes: 16 additions & 2 deletions js/views/navigationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class NavigationView extends Backbone.View {

attributes() {
return {
'role': 'navigation'
role: 'navigation'
};
}

initialize() {
this.sortNavigationButtons = _.debounce(this.sortNavigationButtons.bind(this), 1);
this.listenToOnce(Adapt, {
'courseModel:dataLoading': this.remove
});
this.listenTo(Adapt, 'router:menu router:page', this.hideNavigationButton);
this.listenTo(Adapt, 'router:menu router:page', this.onNavigate);
this.preRender();
}

Expand Down Expand Up @@ -72,11 +73,24 @@ class NavigationView extends Backbone.View {
Adapt.a11y.focusFirst('.' + Adapt.location._contentType);
}

onNavigate(model) {
this.hideNavigationButton(model);
this.sortNavigationButtons();
}

hideNavigationButton(model) {
const shouldHide = (model.get('_type') === 'course');
this.$('.nav__back-btn, .nav__home-btn').toggleClass('u-display-none', shouldHide);
}

sortNavigationButtons() {
const container = this.$('.nav__inner')[0];
const items = [...container.children];
items
.sort((a, b) => parseFloat($(a).attr('data-order') || 0) - parseFloat($(b).attr('data-order') || 0))
.forEach(item => container.appendChild(item));
}

showNavigationButton() {
this.$('.nav__back-btn, .nav__home-btn').removeClass('u-display-none');
}
Expand Down
19 changes: 19 additions & 0 deletions schema/course.model.schema
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,25 @@
}
}
}
},
"_extensions": {
"type": "object",
"title": "Extensions",
"default": {},
"properties": {
"_drawer": {
"type": "object",
"title": "Drawer",
"default": {},
"properties": {
"_navOrder": {
"type": "number",
"title": "Navigation bar order",
"default": 0
}
}
}
}
}
}
},
Expand Down
19 changes: 19 additions & 0 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@
}
}
}
},
"_extensions": {
"type": "object",
"title": "Extensions",
"default": {},
"properties": {
"_drawer": {
"type": "object",
"title": "Drawer",
"default": {},
"properties": {
"visited": {
"type": "number",
"title": "Navigation bar order",
"default": 0
}
}
}
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion templates/nav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="icon"></div>
</button>

<button class="btn-icon nav__btn nav__drawer-btn js-nav-drawer-btn" data-event="toggleDrawer" aria-label="{{_globals._accessibility._ariaLabels.navigationDrawer}}">
<button class="btn-icon nav__btn nav__drawer-btn js-nav-drawer-btn" data-event="toggleDrawer" aria-label="{{_globals._accessibility._ariaLabels.navigationDrawer}}" data-order="{{_globals._extensions._drawer._navOrder}}">
<div class="icon"></div>
</button>

Expand Down

0 comments on commit c29eace

Please sign in to comment.