From e794c5b9b075f3b04d5aac262b419e9545d53e41 Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 9 Apr 2024 11:57:33 -0600 Subject: [PATCH 01/17] Add _areEntireItemsClickable option, update documentation --- README.md | 2 ++ example.json | 3 ++- js/BoxMenuItemView.js | 45 +++++++++++++++++++++++++++++++++++++-- less/boxMenuItem.less | 4 ++++ templates/boxMenuItem.hbs | 3 +++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b12baff..174bb88 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ The first value is the horizontal position and the second value is the vertical. >>>**\_small** (number): The minimum height should only be used in instances where the menu header height needs to be greater than the content e.g. to prevent a background image being cropped. +>>>**__areEntireItemsClickable** (boolean): Indicates if the entire menu item can be clicked to go to the target page. If `true`, the View button will be hidden. + **\_globals** (object): The Globals object that contains value for **\_menu**. >**\_menu** (object): The menu object that contains value for **\_boxMenu**. diff --git a/example.json b/example.json index 6ca5a4b..2c385de 100644 --- a/example.json +++ b/example.json @@ -35,7 +35,8 @@ "_medium": 400, "_small": 200 } - } + }, + "_areEntireItemsClickable": true, } // contentObjects.json diff --git a/js/BoxMenuItemView.js b/js/BoxMenuItemView.js index 11817a4..f76d799 100644 --- a/js/BoxMenuItemView.js +++ b/js/BoxMenuItemView.js @@ -1,15 +1,52 @@ import MenuItemView from 'core/js/views/menuItemView'; +import Adapt from 'core/js/adapt'; import router from 'core/js/router'; class BoxMenuItemView extends MenuItemView { className() { - return `${super.className()} boxmenu-item`; + const entireItemClickable = this.areEntireItemsClickable() ? 'is-entire-item-clickable' : ''; + return `${super.className()} boxmenu-item ${entireItemClickable}`; } events() { + if (this.areEntireItemsClickable()) { + return { + click: 'onClickMenuItemButton' + }; + } else { + return { + 'click .js-btn-click': 'onClickMenuItemButton' + }; + } + } + + attributes() { + const globals = Adapt.course.get('_globals'); + const ariaLabel = []; + + if (this.model.get('_isComplete')) { + ariaLabel.push(globals._accessibility._ariaLabels.complete); + } + + if (this.model.get('_isVisited')) { + ariaLabel.push(globals._accessibility._ariaLabels.visited); + } + + if (this.model.get('_isOptional')) { + ariaLabel.push(globals._accessibility._ariaLabels.optional); + } + + const data = this.model.toJSON(); + const itemCount = Handlebars.compile(globals._menu._boxMenu.itemCount)(data); + ariaLabel.push(itemCount); + + const parentAttributes = Object.getPrototypeOf(BoxMenuItemView.prototype).attributes.call(this); + return { - 'click .js-btn-click': 'onClickMenuItemButton' + ...parentAttributes, + role: 'link', + 'aria-label': ariaLabel.join(' ') }; } @@ -18,6 +55,10 @@ class BoxMenuItemView extends MenuItemView { if (this.model.get('_isLocked')) return; router.navigateToElement(this.model.get('_id')); } + + areEntireItemsClickable() { + return Adapt.course.get('_boxMenu')?._areEntireItemsClickable; + } } BoxMenuItemView.template = 'boxMenuItem'; diff --git a/less/boxMenuItem.less b/less/boxMenuItem.less index 577fb05..581edf7 100644 --- a/less/boxMenuItem.less +++ b/less/boxMenuItem.less @@ -8,4 +8,8 @@ @media (min-width: @device-width-medium) { width: 50%; } + + &.is-entire-item-clickable:not(.is-locked) { + cursor: pointer; + } } diff --git a/templates/boxMenuItem.hbs b/templates/boxMenuItem.hbs index 145f44a..cb3e3e9 100644 --- a/templates/boxMenuItem.hbs +++ b/templates/boxMenuItem.hbs @@ -1,4 +1,5 @@ {{import_globals}} +{{import_adapt}}