Skip to content

H5P.getUserData not used asynchronously where required #112

@otacke

Description

@otacke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions