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

H5P.getUserData not used asynchronously where required #112

Open
otacke opened this issue Nov 15, 2021 · 1 comment · May be fixed by #167
Open

H5P.getUserData not used asynchronously where required #112

otacke opened this issue Nov 15, 2021 · 1 comment · May be fixed by #167

Comments

@otacke
Copy link
Contributor

otacke commented Nov 15, 2021

h5p-php-library/js/h5p.js

Lines 107 to 137 in 22115c0

H5P.getUserData(contentId, 'state', function (err, previousState) {
if (previousState) {
library.userDatas = {
state: previousState
};
}
else if (previousState === null && H5PIntegration.saveFreq) {
// Content has been reset. Display dialog.
delete contentData.contentUserData;
var dialog = new H5P.Dialog('content-user-data-reset', 'Data Reset', '<p>' + H5P.t('contentChanged') + '</p><p>' + H5P.t('startingOver') + '</p><div class="h5p-dialog-ok-button" tabIndex="0" role="button">OK</div>', $container);
H5P.jQuery(dialog).on('dialog-opened', function (event, $dialog) {
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);
H5P.trigger(instance, 'resize');
}).on('dialog-closed', function () {
H5P.trigger(instance, 'resize');
});
dialog.open();
}
// If previousState is false we don't have a previous state
});
// Create new instance.
var instance = H5P.newRunnable(library, contentId, $container, true, {standalone: true});

The call to H5P.getUserData is supposed to populate library.userDatas with the previous state, so it can be used in in the call to H5P.newRunnable in

var instance = H5P.newRunnable(library, contentId, $container, true, {standalone: true});

This works fine if the previous state is set in the H5PIntegration object and fetched in

var preloadedData = content.contentUserData;

Otherwise. however H5P.getUserData will not resolve before the asynchronous call to contentUserDataAjax in

function contentUserDataAjax(contentId, dataType, subContentId, done, data, preload, invalidate, async) {

is resolved and thus library.userDatas may be set after H5P.newRunnable wants to use the parameter.

This is currently not an issue, because all the H5P plugins set the contentUserData property in the H5PIntegration object, but it will not work otherwise although the code suggests it would.

@Melchizedek6809
Copy link

Is there a chance that a PR which fixes this gets merged? I'm working on a custom H5P integration where user data is only available asynchronously, so fixing this issue would be quite convenient :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants