Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/groups #93

Merged
merged 13 commits into from
Jul 1, 2020
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,49 @@ The following attributes, set within *contentObjects.json*, configure the defaul

**duration** (string): Optional text which follows **durationLabel** (e.g., `"2 mins"`).

**\_boxMenu** (object): The boxMenu object that contains value for **\_renderAsGroup**.

>**\_renderAsGroup** (boolean): Enable this option to render items into a group on the menu. Groups can display a title, body, and instruction text.

>Framework: Change the group content object type to `menu` and update the `_parentId` of the children content objects to match the group content object `_id`. Authoring Tool: Add a submenu and check the 'Enable as menu group?' setting. All users: If accessibility is required update the aria level values in config settings so the title heirarchy of remains intact.
guywillis marked this conversation as resolved.
Show resolved Hide resolved

```
{
guywillis marked this conversation as resolved.
Show resolved Hide resolved
"_id": "co-00",
"_parentId": "course",
"_type": "menu",
"title": "Group 1",
"displayTitle": "Group 1",
"body": "Body",
"instruction": "Instruction",
"_boxMenu": {
"_renderAsGroup": true
}
},
{
"_id": "co-100",
"_parentId": "co-00",
"_type": "page",
"_classes": "",
"_htmlClasses": "",
"title": "Title",
"displayTitle": "Title",
"body": "Body",
"instruction": "Instruction"
},
{
"_id": "co-200",
"_parentId": "co-00",
"_type": "page",
"_classes": "",
"_htmlClasses": "",
"title": "Title",
"displayTitle": "Title",
"body": "Body",
"instruction": "Instruction"
}
```

<div float align=right><a href="#top">Back to Top</a></div>

### Accessibility
Expand Down
37 changes: 37 additions & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,40 @@
"linkText": "View",
"duration": "2 mins"
}

// contentObjects.json
// Render menu with grouped items
{
"_id": "co-00",
"_parentId": "course",
"_type": "menu",
"title": "Group 1",
"displayTitle": "Group 1",
"body": "Body",
"instruction": "Instruction",
"_boxMenu": {
"_renderAsGroup": true
}
},
{
"_id": "co-100",
"_parentId": "co-00",
"_type": "page",
"_classes": "",
"_htmlClasses": "",
"title": "Title",
"displayTitle": "Title",
"body": "Body",
"instruction": "Instruction"
},
{
"_id": "co-200",
"_parentId": "co-00",
"_type": "page",
"_classes": "",
"_htmlClasses": "",
"title": "Title",
"displayTitle": "Title",
"body": "Body",
"instruction": "Instruction"
}
30 changes: 27 additions & 3 deletions js/adapt-contrib-boxMenu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define([
'core/js/adapt',
'core/js/views/menuView',
"./adapt-contrib-boxMenuItemView"
], function(Adapt, MenuView, BoxMenuItemView) {
"./adapt-contrib-boxMenuItemView",
"./adapt-contrib-boxMenuGroupView"
], function(Adapt, MenuView, BoxMenuItemView, BoxMenuGroupView) {

var BoxMenuView = MenuView.extend({

Expand All @@ -19,6 +20,30 @@ define([
this.setStyles();
},

addChildren: function() {
var nthChild = 0;
var models = this.model.getChildren().models;
this.childViews = {};
models.forEach(function(model) {
if (!model.get('_isAvailable')) return;

nthChild++;
model.set('_nthChild', nthChild);

var ChildView = (model.get('_type') === 'menu' && model.get('_boxMenu') && model.get('_boxMenu')._renderAsGroup) ?
BoxMenuGroupView :
BoxMenuItemView;

var $parentContainer = this.$(this.constructor.childContainer);
var childView = new ChildView({ model: model });

this.childViews[model.get('_id')] = childView;

$parentContainer.append(childView.$el);

}.bind(this));
},

setStyles: function() {
this.setBackgroundImage();
this.setBackgroundStyles();
Expand Down Expand Up @@ -152,7 +177,6 @@ define([
}

}, {
childView: BoxMenuItemView,
className: 'boxmenu',
template: 'boxMenu'
});
Expand Down
25 changes: 25 additions & 0 deletions js/adapt-contrib-boxMenuGroupView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define([
"core/js/views/menuItemView",
"./adapt-contrib-boxMenuItemView"
], function(MenuItemView, BoxMenuItemView) {

var BoxMenuGroupView = MenuItemView.extend({

postRender: function() {
_.defer(function() {
this.addChildren();
}.bind(this));
guywillis marked this conversation as resolved.
Show resolved Hide resolved
this.$el.imageready(this.setReadyStatus.bind(this));
this.$('.boxmenu__item-container').addClass('has-groups');
}

}, {
childContainer: '.js-group-children',
childView: BoxMenuItemView,
className: 'boxmenu-group',
template: 'boxMenuGroup'
});

return BoxMenuGroupView;

});
2 changes: 1 addition & 1 deletion less/boxMenu.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.l-container-responsive(@device-width-large);
}

&__item-container-inner {
&__item-container:not(.has-groups) &__item-container-inner {
display: flex;
flex-wrap: wrap;
.l-container-responsive(@device-width-large);
Expand Down
11 changes: 11 additions & 0 deletions less/boxMenuGroup.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.boxmenu-group {
&__header-inner {
.l-container-responsive(@device-width-large);
}

&__item-container-inner {
display: flex;
flex-wrap: wrap;
.l-container-responsive(@device-width-large);
}
}
19 changes: 18 additions & 1 deletion properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,24 @@
}
},
"contentobject": {
"type": "object"
"type": "object",
"properties": {
"_boxMenu": {
"type": "object",
"required": false,
"properties": {
"_renderAsGroup": {
"type": "boolean",
"required": false,
"default": false,
"title": "Enable as menu group?",
"inputType": "Checkbox",
"validators": [],
"help": "Enable this option to render items into a group on the menu. Groups can display a title, body, and instruction text."
}
}
}
}
},
"article": {
"type": "object"
Expand Down
47 changes: 47 additions & 0 deletions templates/boxMenuGroup.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{import_globals}}

<div class="menu-group__inner boxmenu-group__inner">

<div class="menu-group__header boxmenu-group__header">
<div class="menu-group__header-inner boxmenu-group__header-inner">

{{#if displayTitle}}
<div class="menu-group__title boxmenu-group__title">
<div class="js-heading" data-a11y-heading-type="menuGroup"></div>

<div class="menu-group__title-inner boxmenu-group__title-inner accessible-text-block" aria-hidden="true">
{{{compile displayTitle}}}
</div>
</div>
{{/if}}

{{#if body}}
<div class="menu-group__body boxmenu-group__body">
<div class="menu-group__body-inner boxmenu-group__body-inner">
{{{compile body}}}
</div>
</div>
{{/if}}

{{#if instruction}}
<div class="menu-group__instruction boxmenu-group__instruction">
<div class="menu-group__instruction-inner boxmenu-group__instruction-inner">
{{{compile instruction}}}
</div>
</div>
{{/if}}

<div class="menu-group__progress boxmenu-group__progress js-menu-item-progress">
{{!-- Menu item progress bar will render in here --}}
</div>

</div>
</div>

<div class="menu-group__container boxmenu-group__container">
<div class="menu-group__item-container-inner boxmenu-group__item-container-inner js-group-children" role="list">
{{!-- Grouped menu items render here --}}
</div>
</div>

</div>
1 change: 0 additions & 1 deletion templates/boxMenuItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@
</div>
</div>


</div>