Avoid parsing state multiple times.

semantics-font
Frode Petterson 2015-03-24 11:01:23 +01:00
parent e153acbf3e
commit 24fa34f9c2
1 changed files with 9 additions and 6 deletions

View File

@ -57,6 +57,12 @@ H5P.init = function (target) {
if (contentData === undefined) { if (contentData === undefined) {
return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?'); return H5P.error('No data for content id ' + contentId + '. Perhaps the library is gone?');
} }
if (contentData.contentUserDatas && contentData.contentUserDatas.state) {
try {
contentData.contentUserDatas.state = JSON.parse(contentData.contentUserDatas.state);
}
catch (err) {}
}
var library = { var library = {
library: contentData.library, library: contentData.library,
params: JSON.parse(contentData.jsonContent), params: JSON.parse(contentData.jsonContent),
@ -612,13 +618,10 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
var contentExtrasWrapper; var contentExtrasWrapper;
if (library.userDatas && library.userDatas.state) { if (library.userDatas && library.userDatas.state) {
try {
contentExtrasWrapper = { contentExtrasWrapper = {
previousState: JSON.parse(library.userDatas.state) previousState: library.userDatas.state
}; };
} }
catch (err) {}
}
var instance = new constructor(library.params, contentId, contentExtrasWrapper); var instance = new constructor(library.params, contentId, contentExtrasWrapper);