Skip to content

Commit

Permalink
#8 React/ES6 conversion, #6 Nav order, #1 Hide for mobile option
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck committed Jan 2, 2023
1 parent da06959 commit ac8ee06
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 68 deletions.
27 changes: 18 additions & 9 deletions example.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// course.json
"_navigationTitle": {
"_isEnabled": true,
"title": "Title"
}
// course.json
"_navigationTitle": {
"_isEnabled": true,
"title": "Title",
"_hideTitleForMobile": true
}

// course.json - if you want to use the course displayTitle
"_navigationTitle": {
"_isEnabled": true,
"title": "{{{Adapt.[course].displayTitle}}}"
"_globals": {
"_extensions": {
"_navigationTitle": {
"_navOrder": 2
}
}
}

// course.json - if you want to use the course displayTitle
"_navigationTitle": {
"_isEnabled": true,
"title": "{{{Adapt.[course].displayTitle}}}"
}
50 changes: 50 additions & 0 deletions js/NavigationTitleView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Adapt from 'core/js/adapt';
import device from 'core/js/device';
import React from 'react';
import ReactDOM from 'react-dom';
import { templates } from 'core/js/reactHelpers';

class NavigationTitleView extends Backbone.View {
className() {
return 'navigation-title';
}

attributes() {
return {
'data-order': (Adapt.course.get('_globals')?._extensions?._navigationTitle?._navOrder || 0)
};
}

initialize() {
this.listenTo(Adapt, 'device:changed', this.changed);
this.render();
}

render() {
this.changed();
}

changed() {
this.setIsDeviceSmall();
this.hideForMobile();

ReactDOM.render(<templates.navigationTitle {...this.model.toJSON()} />, this.el);
}

setIsDeviceSmall() {
this.model.set('_isDeviceSmall', device.screenSize === 'small');
}

hideForMobile() {
const _isDeviceSmall = this.model.get('_isDeviceSmall');
const _hideForMobile = this.model.get('_hideForMobile');

if (_isDeviceSmall && _hideForMobile) {
this.$el.addClass('u-display-none');
} else {
this.$el.removeClass('u-display-none');
}
}
}

export default NavigationTitleView;
24 changes: 0 additions & 24 deletions js/TitleView.js

This file was deleted.

51 changes: 21 additions & 30 deletions js/adapt-navigationTitle.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
define([
'core/js/adapt',
'./TitleView'
],function(Adapt, TitleView) {
import Adapt from 'core/js/adapt';
import NavigationTitleView from './NavigationTitleView';

var NavigationTitle = Backbone.Controller.extend({
class NavigationTitle extends Backbone.Controller {

initialize: function() {
this.listenTo(Adapt, "adapt:initialize", this.onDataReady);
},
initialize() {
this.listenTo(Adapt, 'adapt:initialize', this.onDataReady);
}

onDataReady: function() {
if (this.titleView) this.titleView.remove();
onDataReady() {
const config = Adapt.course.get('_navigationTitle');
if (!config || !config._isEnabled) return;

var config = Adapt.course.get("_navigationTitle");
if (!config || !config._isEnabled) return;
this.titleView = new NavigationTitleView({
model: new Backbone.Model(config)
});

this.titleView = new TitleView({
model: new Backbone.Model(config)
});
// If 'navigation logo' is present in the navigation, insert title after it.
// Otherwise, insert after 'back' button.
const $navLogo = $('.navigation-logo');
const $backBtn = $('.js-nav-back-btn');
const $insertAfter = $navLogo.length > 0 ? $navLogo : $backBtn;

// if 'navigation logo' is present in the navigation, insert after
var $navLogo = $('.navigation-logo');
if ($navLogo.length > 0) {
this.titleView.$el.insertAfter($navLogo);
return;
}
// otherwise just insert after back button
var $backBtn = ".js-nav-back-btn";
this.titleView.$el.insertAfter($backBtn);
}
this.titleView.$el.insertAfter($insertAfter);
}
};

});

return new NavigationTitle();

});
export default new NavigationTitle();
2 changes: 1 addition & 1 deletion less/navigationTitle.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
min-height: @navMinHeight;
padding-right: @icon-padding;
padding-left: @icon-padding;
}
}
4 changes: 0 additions & 4 deletions templates/navigationTitle.hbs

This file was deleted.

15 changes: 15 additions & 0 deletions templates/navigationTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

export default function NavigationTitle(props) {
const {
title
} = props;

return (

<div className='navigation-title__inner'>
{title}
</div>

);
}

0 comments on commit ac8ee06

Please sign in to comment.