Skip to content

Commit 718285d

Browse files
committed
feat: add full screen modal option to base_modal
1 parent 24468b6 commit 718285d

5 files changed

Lines changed: 102 additions & 6 deletions

File tree

cms/static/js/views/modals/base_modal.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* primaryActionButtonType: A string to be used as type for primary action button.
2222
* primaryActionButtonTitle: A string to be used as title for primary action button.
2323
* showEditorModeButtons: Whether to show editor mode button in the modal header.
24+
* showFullscreenButton: Whether to show fullscreen button in the modal header.
2425
*/
2526
define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
2627
function($, _, gettext, BaseView) {
@@ -43,7 +44,8 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
4344
addPrimaryActionButton: false,
4445
primaryActionButtonType: 'save',
4546
primaryActionButtonTitle: gettext('Save'),
46-
showEditorModeButtons: true
47+
showEditorModeButtons: true,
48+
showFullscreenButton: false,
4749
}),
4850

4951
initialize: function() {
@@ -71,7 +73,8 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
7173
title: this.getTitle(),
7274
modalSRTitle: this.options.modalSRTitle,
7375
showEditorModeButtons: this.options.showEditorModeButtons,
74-
viewSpecificClasses: this.options.viewSpecificClasses
76+
viewSpecificClasses: this.options.viewSpecificClasses,
77+
showFullscreenButton: this.options.showFullscreenButton,
7578
}));
7679
this.addActionButtons();
7780
this.renderContents();
@@ -83,9 +86,14 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
8386
},
8487

8588
renderContents: function() {
86-
var contentHtml = this.getContentHtml();
89+
const contentHtml = this.getContentHtml();
8790
// xss-lint: disable=javascript-jquery-html
8891
this.$('.modal-content').html(contentHtml);
92+
93+
const fullscreenButton = this.$('.fullscreen-button');
94+
if (fullscreenButton.length) {
95+
fullscreenButton.bind('click', this.toggleFullscreen.bind(this));
96+
}
8997
},
9098

9199
/**
@@ -106,6 +114,7 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
106114
// after showing and resizing, send focus
107115
this.$el.find(this.options.modalWindowClass).focus();
108116
}
117+
109118
},
110119

111120
hide: function() {
@@ -195,11 +204,25 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview'],
195204
this.getActionBar().find('.action-' + type).prop('disabled', true).addClass('is-disabled');
196205
},
197206

207+
toggleFullscreen: function() {
208+
this.$('.fullscreen-button .icon').toggleClass('fa-expand fa-compress');
209+
this.$('.modal-editor').toggleClass(`modal-${this.options.modalSize} modal-fullscreen`);
210+
this.resize();
211+
},
212+
198213
resize: function() {
199214
var top, left, modalWindow, modalWidth, modalHeight,
200215
availableWidth, availableHeight, maxWidth, maxHeight;
201216

202217
modalWindow = this.$el.find(this.options.modalWindowClass);
218+
if (modalWindow.hasClass('modal-fullscreen')) {
219+
// Remove previously set width and height from the modal window
220+
modalWindow.css({
221+
top: '',
222+
left: '',
223+
});
224+
return;
225+
}
203226
availableWidth = $(window).width();
204227
availableHeight = $(window).height();
205228
maxWidth = availableWidth * 0.98;

cms/static/js/views/modals/edit_xblock.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function($, _, Backbone, gettext, BaseModal, ViewUtils, XBlockViewUtils, XBlockE
2121
viewSpecificClasses: 'modal-editor confirm',
2222
// Translators: "title" is the name of the current component being edited.
2323
titleFormat: gettext('Editing: {title}'),
24-
addPrimaryActionButton: true
24+
addPrimaryActionButton: true,
25+
showFullscreenButton: true,
2526
}),
2627

2728
initialize: function() {
@@ -127,6 +128,7 @@ function($, _, Backbone, gettext, BaseModal, ViewUtils, XBlockViewUtils, XBlockE
127128
} else {
128129
this.$('.modal-window-title').text(title);
129130
}
131+
130132
this.getXBlockUpstreamLink();
131133

132134
// If the xblock is not using custom buttons then choose which buttons to show
@@ -292,8 +294,7 @@ function($, _, Backbone, gettext, BaseModal, ViewUtils, XBlockViewUtils, XBlockE
292294
$input.focus().select();
293295
$(event.target).remove();
294296
return true;
295-
}
296-
297+
},
297298
});
298299

299300
return EditXBlockModal;

cms/static/sass/course-unit-mfe-iframe-bundle.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,31 @@ body,
443443
line-height: 28px;
444444
}
445445

446+
.fullscreen-button {
447+
color: $primary-base;
448+
height: 44px;
449+
width: 44px;
450+
border-radius: 22px;
451+
452+
&:hover {
453+
border-color: $primary-base;
454+
}
455+
456+
&:focus {
457+
border-color: $primary-base;
458+
}
459+
}
460+
446461
.xblock-actions {
447462
border-top: 1px solid $border-color;
448463
background-color: $white;
449464
display: flex;
450465
justify-content: flex-end;
451466

467+
ul {
468+
margin-left: auto;
469+
}
470+
452471
.action-button {
453472
background-color: $transparent;
454473
border: 1px solid $transparent;

cms/static/sass/elements/_modal-window.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@
308308
bottom: 30px;
309309
}
310310
}
311+
312+
.fullscreen-button {
313+
height: 44px;
314+
width: 44px;
315+
position: absolute;
316+
right: 30px;
317+
z-index: 10;
318+
}
311319
}
312320

313321

@@ -391,6 +399,48 @@
391399
}
392400
}
393401

402+
// fullscren modals - component editors
403+
.modal-fullscreen {
404+
width: 100vw;
405+
height: 100vh;
406+
display: flex;
407+
flex-direction: column;
408+
409+
410+
// Set the components to flex so that they can grow
411+
div,
412+
form {
413+
display: flex;
414+
flex-direction: column;
415+
flex-grow: 1;
416+
417+
// Set the header to not grow
418+
header,
419+
&.modal-header {
420+
flex-grow: 0;
421+
}
422+
423+
}
424+
425+
ul {
426+
flex-grow: 1;
427+
428+
// Reset the divs inside the ul to preserve previous styling
429+
div,
430+
form {
431+
display: unset;
432+
flex-direction: unset;
433+
flex-grow: unset;
434+
}
435+
}
436+
437+
&.modal-editor {
438+
.modal-content {
439+
padding: 0px;
440+
}
441+
}
442+
}
443+
394444

395445

396446
// specific modal overrides

cms/templates/js/basic-modal.underscore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
role="dialog">
44
<div class="modal-window-overlay"></div>
55
<div class="modal-window <%- viewSpecificClasses %> modal-<%- size %> modal-type-<%- type %>" tabindex="-1" aria-labelledby="modal-window-title">
6+
<% if (showFullscreenButton) { %>
7+
<button class="btn-default fullscreen-button"><span class="icon fa fa-expand"></span></button>
8+
<% } %>
69
<div class="<%- name %>-modal">
710
<% if (title || modalSRTitle || showEditorModeButtons) { %>
811
<div class="modal-header">

0 commit comments

Comments
 (0)