From 7807b8af68a1dfabe8e7c71d238ac139e3c96a39 Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Mon, 6 Jun 2016 16:09:35 +0200 Subject: [PATCH 1/2] Making sure reset dialog is only shown once [HFJ-1989] --- js/h5p.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/h5p.js b/js/h5p.js index 5a1c9e1..1511ee8 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -103,6 +103,7 @@ H5P.init = function (target) { var $container = H5P.jQuery('
').appendTo($element); var contentId = $element.data('content-id'); var contentData = H5PIntegration.contents['cid-' + contentId]; + var resetUserState = false; if (contentData === undefined) { return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?'); } @@ -118,6 +119,7 @@ H5P.init = function (target) { }; } else if (previousState === null && H5PIntegration.saveFreq) { + resetUserState = true; // Content has been reset. Display dialog. delete contentData.contentUserData; var dialog = new H5P.Dialog('content-user-data-reset', 'Data Reset', '

' + H5P.t('contentChanged') + '

' + H5P.t('startingOver') + '

OK
', $container); @@ -137,6 +139,10 @@ H5P.init = function (target) { // Create new instance. var instance = H5P.newRunnable(library, contentId, $container, true, {standalone: true}); + if (resetUserState) { + H5P.deleteUserData(contentId, 'state', instance.subContentId); + } + // Check if we should add and display a fullscreen button for this H5P. if (contentData.fullScreen == 1 && H5P.canHasFullScreen) { H5P.jQuery('
').prependTo($container).children().click(function () { From f4cee6e2847a8c48ff1c3063825a62f588d38cd8 Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Tue, 7 Jun 2016 11:09:42 +0200 Subject: [PATCH 2/2] Moved deletion of content user data to after dialog is closed [HFJ-1989] --- js/h5p.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 1511ee8..5de66e2 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -103,7 +103,6 @@ H5P.init = function (target) { var $container = H5P.jQuery('
').appendTo($element); var contentId = $element.data('content-id'); var contentData = H5PIntegration.contents['cid-' + contentId]; - var resetUserState = false; if (contentData === undefined) { return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?'); } @@ -119,18 +118,19 @@ H5P.init = function (target) { }; } else if (previousState === null && H5PIntegration.saveFreq) { - resetUserState = true; // Content has been reset. Display dialog. delete contentData.contentUserData; var dialog = new H5P.Dialog('content-user-data-reset', 'Data Reset', '

' + H5P.t('contentChanged') + '

' + H5P.t('startingOver') + '

OK
', $container); H5P.jQuery(dialog).on('dialog-opened', function (event, $dialog) { - $dialog.find('.h5p-dialog-ok-button').click(function () { - dialog.close(); - }).keypress(function (event) { - if (event.which === 32) { + + var closeDialog = function (event) { + if (event.type === 'click' || event.which === 32) { dialog.close(); + H5P.deleteUserData(contentId, 'state', 0); } - }); + }; + + $dialog.find('.h5p-dialog-ok-button').click(closeDialog).keypress(closeDialog); }); dialog.open(); } @@ -139,10 +139,6 @@ H5P.init = function (target) { // Create new instance. var instance = H5P.newRunnable(library, contentId, $container, true, {standalone: true}); - if (resetUserState) { - H5P.deleteUserData(contentId, 'state', instance.subContentId); - } - // Check if we should add and display a fullscreen button for this H5P. if (contentData.fullScreen == 1 && H5P.canHasFullScreen) { H5P.jQuery('
').prependTo($container).children().click(function () {