Skip to content

Commit

Permalink
JI-1059 Add resizing of offline request dialog for small content
Browse files Browse the repository at this point in the history
Fix height calculation of confirmation dialog when not provided
  • Loading branch information
thomasmars committed Apr 3, 2019
1 parent 687f886 commit 0b1aadb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion js/h5p-confirmation-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,14 @@ H5P.ConfirmationDialog = (function (EventDispatcher) {
*/
var fitToContainer = function (offsetTop) {
var popupOffsetTop = parseInt(popup.style.top, 10);
if (offsetTop) {
if (offsetTop !== undefined) {
popupOffsetTop = offsetTop;
}

if (!popupOffsetTop) {
popupOffsetTop = 0;
}

// Overflows height
if (popupOffsetTop + popup.offsetHeight > wrapperElement.offsetHeight) {
popupOffsetTop = wrapperElement.offsetHeight - popup.offsetHeight - shadowOffset;
Expand Down
4 changes: 2 additions & 2 deletions js/h5p.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ H5P.init = function (target) {
metadata: contentData.metadata
};

H5P.offlineRequestQueue = new H5P.OfflineRequestQueue();

H5P.getUserData(contentId, 'state', function (err, previousState) {
if (previousState) {
library.userDatas = {
Expand Down Expand Up @@ -138,6 +136,8 @@ H5P.init = function (target) {
// Create new instance.
var instance = H5P.newRunnable(library, contentId, $container, true, {standalone: true});

H5P.offlineRequestQueue = new H5P.OfflineRequestQueue({instance: instance});

// Check if we should add and display a fullscreen button for this H5P.
if (contentData.fullScreen == 1 && H5P.fullscreenSupported) {
H5P.jQuery(
Expand Down
15 changes: 12 additions & 3 deletions js/request-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,14 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
* @type {offlineRequestQueue}
*/
H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
const offlineRequestQueue = function () {

/**
* Constructor
*
* @param {Object} [options] Options for offline request queue
* @param {Object} [options.instance] The H5P instance which UI components are placed within
*/
const offlineRequestQueue = function (options) {
const requestQueue = new RequestQueue();

// We could handle requests from previous pages here, but instead we throw them away
Expand All @@ -245,6 +252,7 @@ H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
let isAttached = false;
let isShowing = false;
let isLoading = false;
const instance = options.instance;

const offlineDialog = new Dialog({
headerText: H5P.t('offlineDialogHeader'),
Expand All @@ -253,6 +261,7 @@ H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
hideCancel: true,
hideExit: true,
classes: ['offline'],
instance: instance,
});

const dialog = offlineDialog.getElement();
Expand Down Expand Up @@ -399,10 +408,10 @@ H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
// Must force delayed show since dialog may be hiding, and confirmation dialog does not
// support this.
setTimeout(function () {
offlineDialog.show();
offlineDialog.show(0);
}, 100);
} else {
offlineDialog.show();
offlineDialog.show(0);
}
}
isShowing = true;
Expand Down

0 comments on commit 0b1aadb

Please sign in to comment.