Skip to content

Commit

Permalink
New: Allow visua11y to appear in drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster committed May 16, 2023
1 parent 130c692 commit 020d5e1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
1 change: 1 addition & 0 deletions example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// course.json
"_visua11y": {
"_isEnabled": false,
"_location": "notify",
"_shouldSavePreferences": true,
"title": "Accessibility Controls",
"body": "Use the controls below to customise your learning experience to your individual needs.",
Expand Down
23 changes: 14 additions & 9 deletions js/Visua11yButtonView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Adapt from 'core/js/adapt';
import Visua11ySettingsView from './Visua11ySettingsView';
import notify from 'core/js/notify';
import drawer from 'core/js/drawer';

class AnimationsButtonView extends Backbone.View {

Expand Down Expand Up @@ -42,17 +43,21 @@ class AnimationsButtonView extends Backbone.View {
onClick(event) {
if (event && event.preventDefault) event.preventDefault();
const config = Adapt.course.get('_visua11y');
Adapt.visua11y.settingsPrompt = notify.popup({
title: config.title,
body: config.body,
_view: new Visua11ySettingsView(),
_classes: 'is-visua11ysettings',
_showCloseButton: config._showCloseButton || false
});
if (config._location === 'drawer') {
drawer.triggerCustomView(new Visua11ySettingsView().$el, false, 'auto');
} else {
Adapt.visua11y.settingsPrompt = notify.popup({
title: config.title,
body: config.body,
_view: new Visua11ySettingsView(),
_classes: 'is-visua11ysettings',
_showCloseButton: config._showCloseButton || false
});
Adapt.visua11y.settingsPrompt.$el.on('click', this.onNotifyClicked);
this.listenTo(Adapt, 'notify:closed', this.onNotifyClosed);
}
this.render();
Adapt.visua11y.settingsPrompt.$el.on('click', this.onNotifyClicked);
Adapt.trigger('visua11y:opened');
this.listenTo(Adapt, 'notify:closed', this.onNotifyClosed);
}

onNotifyClicked(event) {
Expand Down
7 changes: 6 additions & 1 deletion js/Visua11ySettingsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { templates } from 'core/js/reactHelpers';
export default class Visua11ySettingsView extends Backbone.View {

className() {
return 'visua11ysettings';
return [
'visua11ysettings',
Adapt.visua11y.config._location === 'drawer'
? 'visua11ysettings-drawer'
: 'visua11ysettings-notify'
].filter(Boolean).join(' ');
}

initialize() {
Expand Down
9 changes: 9 additions & 0 deletions js/adapt-visua11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DEFAULTS from './DEFAULTS';
import { highContrast, invert, lowBrightness, profileFilter } from './ColorTransformations';
import Visua11yButtonView from './Visua11yButtonView';
import notify from 'core/js/notify';
import drawer from 'core/js/drawer';

/**
* Utility function for applying deep defaults
Expand Down Expand Up @@ -362,6 +363,14 @@ class Visua11y extends Backbone.Controller {
$('body').hide().show(0);
}

close() {
if (this.config._location === 'drawer') {
drawer.close();
return;
}
this.settingsPrompt?.closeNotify();
}

reset() {
this._colorProfileId = this.config._colorProfile._default;
this._invert = this.config._invert._default;
Expand Down
18 changes: 16 additions & 2 deletions less/visua11ySettings.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
background-color: transparent;

.notify__popup-inner {
max-width: @device-width-small;
max-width: @device-width-medium;
margin: auto;
background-color: @notify;
padding: @item-padding (@item-padding / 2);
Expand All @@ -16,6 +16,8 @@
// --------------------------------------------------
.visua11ysettings {

color: white;

&__description {
padding-left: @item-padding / 2;
padding-right: @item-padding / 2;
Expand All @@ -25,8 +27,11 @@
&__group {
padding: @item-padding / 2;
margin-bottom: @item-padding;
background-color: darken(@notify, 5%);
border-radius: 3px;

.visua11ysettings-notify & {
background-color: darken(@notify, 5%);
}
}

&__group-title {
Expand Down Expand Up @@ -73,6 +78,10 @@
@media (min-width: @device-width-medium) {
flex-direction: row;
}

.visua11ysettings-drawer & {
flex-direction: column;
}
}

.colorprofileid {
Expand All @@ -98,6 +107,11 @@
align-items: center;
justify-content: space-between;
}

.visua11ysettings-drawer & {
flex-direction: column;
align-items: start;
}
}

.visua11ysettings__item-title {
Expand Down
14 changes: 14 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
"inputType": "Checkbox",
"validators": []
},
"_location": {
"type": "string",
"required": true,
"default": "notify",
"title": "Open in notify or drawer",
"validators": ["required"],
"inputType": {
"type": "Select",
"options": [
"notify",
"drawer"
]
}
},
"_shouldSavePreferences": {
"type": "boolean",
"required": false,
Expand Down
10 changes: 10 additions & 0 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
"title": "Enable Visua11y",
"default": false
},
"_location": {
"type": "string",
"title": "Open in notify or drawer",
"default": "notify",
"enum": [
"notify",
"drawer"
],
"_backboneForms": "Select"
},
"_shouldSavePreferences": {
"type": "boolean",
"title": "Save user preferences?",
Expand Down
2 changes: 1 addition & 1 deletion templates/Visua11ySettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Visua11ySettings(config) {
}

function onClose() {
visua11y.settingsPrompt.closeNotify();
visua11y.close();
}

function onChange(event) {
Expand Down

0 comments on commit 020d5e1

Please sign in to comment.