diff --git a/example.json b/example.json index f09fc8b..5162019 100644 --- a/example.json +++ b/example.json @@ -1,8 +1,8 @@ - // Configuration options must be added and amended for all json files + // Configuration options must be added and amended for all json files where required - // config.json + // config.json - to disable globally "_homeButton": { - "_isEnabled": true + "_isEnabled": false } // course.json @@ -11,7 +11,7 @@ "_hideHomeButton": false, "_comment": "Amend co-00 to match the ID of the start / landing page", "_redirectToId": "co-00", - "alt": "Home" + "alt": "Introduction" } // contentObjects.json @@ -19,5 +19,6 @@ "_isEnabled": true, "_hideHomeButton": false, "_hideBackButton": true, - "_redirectToId": "" + "_redirectToId": "", + "alt": "Home" } diff --git a/js/adapt-homeButton.js b/js/adapt-homeButton.js index 7477ad2..1b28b51 100644 --- a/js/adapt-homeButton.js +++ b/js/adapt-homeButton.js @@ -1,102 +1,77 @@ -define([ - 'core/js/adapt' -], function(Adapt) { - - var HomeButton = Backbone.Controller.extend({ - - _$html: null, - - initialize: function() { - this.listenTo(Adapt, 'app:dataReady', this._onDataReady); - }, - - _onDataReady: function() { - var config = Adapt.config.get('_homeButton'); - if (!config || !config._isEnabled) return; - - this._$html = $('html'); - - this.listenTo(Adapt, { - 'remove': this._onRemove, - 'router:menu router:page': this._onRouterEvent, - 'navigation:redirectedHomeButton': this._redirected - }); - }, - - _onRouterEvent: function(model) { - this._config = model.get('_homeButton'); - - var isEnabled = (this._config && this._config._isEnabled); - if (!isEnabled) return this._disabled(); - this._enabled(); - }, - - _onRemove: function() { - this._disabled(); - }, - - _disabled: function() { - this._$html.removeClass('hide-nav-home-btn'); - - if (this._dataEvent) { - $('.js-nav-home-btn').attr('data-event', this._dataEvent); - this._dataEvent = null; - } - }, - - _enabled: function() { - this._$html.toggleClass('hide-nav-home-btn', !!this._config._hideHomeButton); - // extend functionality to toggle back button display - this._$html.toggleClass('hide-nav-back-btn', !!this._config._hideBackButton); - - if (!$('.js-nav-home-btn')[0]) { - // if home button doesn't exist create home button - this._createHomeButton(); - } - - if (this._config._redirectToId) { - this._dataEvent = $('.js-nav-home-btn').attr('data-event'); - $('.js-nav-home-btn').attr('data-event', 'redirectedHomeButton'); - } - }, - - _createHomeButton: function() { - var config = Adapt.course.get('_homeButton'); - var altText = (config && config.alt); - var $backButton = $('button[data-event="backButton"]'); - var $icon = $('
', { 'class': 'icon' }); - var $homeButton = $('