-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: allow to view in CMS #25
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,131 @@ | ||
/* Javascript for H5PPlayerXBlock. */ | ||
function H5PPlayerXBlock(runtime, element, args) { | ||
|
||
function initH5P(H5PStandalone, service) { | ||
if (!window.H5PPlayerXBlockPromises) { | ||
window.H5PPlayerXBlockPromises = []; | ||
window.H5PPlayerXBlockPromises = []; | ||
} | ||
const contentUserDataUrl = runtime.handlerUrl(element, 'user_interaction_data'); | ||
const contentxResultSaveUrl = runtime.handlerUrl(element, 'result_handler'); | ||
const contentUserDataUrl = runtime.handlerUrl( | ||
element, | ||
"user_interaction_data" | ||
); | ||
const contentxResultSaveUrl = runtime.handlerUrl(element, "result_handler"); | ||
|
||
const playerPromise = async function edXH5PPlayer(el) { | ||
if (el && $(el).children(".h5p-iframe-wrapper").length == 0) { | ||
Ian2012 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const userObj = { name: args.user_full_name, mail: args.user_email }; | ||
const options = { | ||
h5pJsonPath: args.h5pJsonPath, | ||
frameJs: | ||
"https://cdn.jsdelivr.net/npm/h5p-standalone@3.6.0/dist/frame.bundle.js", | ||
frameCss: | ||
"https://cdn.jsdelivr.net/npm/h5p-standalone@3.6.0/dist/styles/h5p.css", | ||
frame: args.frame, | ||
copyright: args.copyright, | ||
icon: args.icon, | ||
fullScreen: args.fullScreen, | ||
user: userObj, | ||
saveFreq: args.saveFreq, | ||
customJs: args.customJsPath, | ||
contentUserData: [ | ||
{ | ||
state: args.userData, | ||
}, | ||
], | ||
ajax: { | ||
contentUserDataUrl: contentUserDataUrl, | ||
}, | ||
}; | ||
|
||
const playerPromise = function edXH5PPlayer(el) { | ||
if (el && $(el).children('.h5p-iframe-wrapper').length == 0) { | ||
const userObj = { 'name': args.user_full_name, 'mail': args.user_email }; | ||
const options = { | ||
h5pJsonPath: args.h5pJsonPath, | ||
frameJs: 'https://cdn.jsdelivr.net/npm/h5p-standalone@3.6.0/dist/frame.bundle.js', | ||
frameCss: 'https://cdn.jsdelivr.net/npm/h5p-standalone@3.6.0/dist/styles/h5p.css', | ||
frame: args.frame, | ||
copyright: args.copyright, | ||
icon: args.icon, | ||
fullScreen: args.fullScreen, | ||
user: userObj, | ||
saveFreq: args.saveFreq, | ||
customJs: args.customJsPath, | ||
contentUserData: [{ | ||
state: args.userData | ||
}], | ||
ajax: { | ||
contentUserDataUrl: contentUserDataUrl | ||
} | ||
try { | ||
await new H5PStandalone.H5P(el, options); | ||
$(el).siblings(".spinner-container").find(".spinner-border").hide(); | ||
$(el).show(); | ||
|
||
H5P.externalDispatcher.on("xAPI", (event) => { | ||
let hasStatement = event && event.data && event.data.statement; | ||
if (!hasStatement) { | ||
return; | ||
} | ||
|
||
return new H5PStandalone.H5P(el, options).then(function(){ | ||
$(el).siblings('.spinner-container').find('.spinner-border').hide(); | ||
$(el).show(); | ||
H5P.externalDispatcher.on("xAPI", (event) => { | ||
let statement = event.data.statement; | ||
let validVerb = | ||
statement.verb && | ||
statement.verb.display && | ||
statement.verb.display["en-US"]; | ||
if (!validVerb) { | ||
return; | ||
} | ||
|
||
let isCompleted = | ||
statement.verb.display["en-US"] === "answered" || | ||
statement.verb.display["en-US"] === "completed"; | ||
let isChild = | ||
statement.context && | ||
statement.context.contextActivities && | ||
statement.context.contextActivities.parent && | ||
statement.context.contextActivities.parent[0] && | ||
statement.context.contextActivities.parent[0].id; | ||
|
||
// Store only completed root events. | ||
if (isCompleted && !isChild) { | ||
$.ajax({ | ||
type: "POST", | ||
url: contentxResultSaveUrl, | ||
data: JSON.stringify(event.data.statement), | ||
}) | ||
.done(function () { | ||
// handle fine request here | ||
}) | ||
.fail(function () { | ||
// handle fails request here | ||
Ian2012 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
}); | ||
|
||
let hasStatement = event && event.data && event.data.statement; | ||
if (!hasStatement) { | ||
return; | ||
} | ||
|
||
let statement = event.data.statement; | ||
let validVerb = statement.verb && statement.verb.display && statement.verb.display['en-US']; | ||
if (!validVerb) { | ||
return; | ||
} | ||
|
||
let isCompleted = statement.verb.display['en-US'] === 'answered' || | ||
statement.verb.display['en-US'] === 'completed'; | ||
let isChild = statement.context && statement.context.contextActivities && | ||
statement.context.contextActivities.parent && | ||
statement.context.contextActivities.parent[0] && | ||
statement.context.contextActivities.parent[0].id; | ||
|
||
// Store only completed root events. | ||
if (isCompleted && !isChild) { | ||
$.ajax({ | ||
type: "POST", | ||
url: contentxResultSaveUrl, | ||
data: JSON.stringify(event.data.statement) | ||
}); | ||
} | ||
// uncomment to see all xAPI events triggered by H5P content | ||
//console.log("xAPI event: ", event); | ||
}); | ||
|
||
}); | ||
return Promise.resolve("Result successfully"); | ||
} catch (error) { | ||
return Promise.reject(error.message); | ||
} | ||
} | ||
}; | ||
|
||
const h5pel = document.getElementById('h5p-' + args.player_id); | ||
const h5pel = document.getElementById("h5p-" + args.player_id); | ||
window.H5PPlayerXBlockPromises.push(playerPromise(h5pel)); | ||
window.H5PXBlockPlayersInitlized = false; | ||
|
||
$(function ($) { | ||
if (!H5PXBlockPlayersInitlized) { | ||
window.H5PXBlockPlayersInitlized = true; | ||
window.H5PPlayerXBlockPromises.reduce( | ||
function(prevPromise, curPromise) { | ||
return prevPromise.then(curPromise); | ||
}, Promise.resolve() | ||
); | ||
} | ||
if (!H5PXBlockPlayersInitlized) { | ||
window.H5PXBlockPlayersInitlized = true; | ||
Promise.all(window.H5PPlayerXBlockPromises).then((_) => {}); | ||
} | ||
}); | ||
} | ||
|
||
if (typeof require === "function") { | ||
require(["h5p"], function (H5PStandalone) { | ||
initH5P(H5PStandalone, "cms"); | ||
}); | ||
} else { | ||
loadJS(function () { | ||
initH5P(window.H5PStandalone, "lms"); | ||
}); | ||
} | ||
} | ||
|
||
function loadJS(callback) { | ||
if (window.H5PStandalone) { | ||
callback(); | ||
} else { | ||
// Load jsMind dynamically using $.getScript | ||
$.getScript( | ||
"https://cdn.jsdelivr.net/npm/h5p-standalone@3.6.0/dist/main.bundle.js" | ||
) | ||
.done(function () { | ||
window.H5PStandalone = H5PStandalone; | ||
callback(); | ||
}) | ||
.fail(function () { | ||
console.error("Error loading H5PStandalone."); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
try { | ||
(function (require) { | ||
require.config({ | ||
paths: { | ||
h5p: "https://cdn.jsdelivr.net/npm/h5p-standalone@3.5.1/dist/main.bundle", | ||
}, | ||
}); | ||
}).call(this, require || RequireJS.require); | ||
} catch (e) { | ||
console.log("Unable to load h5p-standalone via requirejs"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are removing
author_view
we should removeauthor_view.html
and also relevant translations in *.po files of all supported languages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done