A+ JavaScript interface version 1 (DRAFT)
This interface documents how a custom JavaScript code (provided as a plugin, by the content service, or by the assessment service) may hook into the exercise embedding process. The interface can be used to implemented custom exercise types or to replace the exercise embedding process.
N.B. This protocol is still a draft and is based on the current implementation in the A+ portal.
The Event Interface
The interface is based on the CustomEvent API. Here is a list of all the events part of the interface:
-
aplus:chapter-loadedis send from the chapter element after it has been loaded. -
aplus:chapter-readyis send from the chapter element after all exercises have been loaded. -
aplus:exercise-loadedwith data{type: exercise_type}is send from the exercise element after the exercise has been downloaded.to be designed:
- Define that
event.preventDefault()can be used to disable the default exercise process (i.e. so that the LMS does not add exercise frame and so on). This will disable theaplus:exercise-readyevent for this exercise.
- Define that
-
aplus:exercise-readywith data{type: exercise_type}is send from the exercise element after the exercise binding has completed, i.e., all event listeners for theaplus:exercise-loadedand the default action has completed. -
aplus:submission-abortedwith data{type: exercise_type}is send from the exercise element when the submission is aborted before ajax request.to be designed:
- Add the submission data to the event data.
-
aplus:exercise-submission-failurewith data{type: exercise_type}is send from the exercise element when the submission has failed during the ajax request.to be designed:
- Rename this to
aplus:submission-failedto match names of other events. - Add the submission data to the event data.
- Add the ajax failure reason (e.g. network problem, invalid data, and so on) to the event data.
- Rename this to
-
aplus:submission-finishedwith data{type: exercise_type}is send from the exercise element when the submission was successfully send. If the submission trigger reload, then the process repeats andaplus:exercise-loadedetc. are send again.
The list of exercise types, which may be part of the exericse_type field:
text/x.aplus-exercise- normal A+ exercisetext/x.aplus-exercise.quiz.v1- core A+ questionnaire typetext/x.aplus-exercise.iframe.v1- core A+ iframe typetext/x.aplus-exercise.active-element.v1- core A+ active-element type
The postMessage API
The older interface is based on window.postMessage API.
However, this interfaces is not as flexible as the Event API, hence all new code should use the Event API instead.
-
{type: 'a-plus-refresh-stats'}(pending deprecation). An event listener is added for every exercise, thus when this message is received, all exercises will be reloaded. The message is accepted from any iframe (i.e.origin='*').N.B: This will be deprecated, once there is a replacement in the Event API.
-
{type: 'a-plus-bind-exercise', id: exercise_element.id}(DEPRECATED, use Event API). This is send just afteraplus:exercise-readyevent. The element can be retrieved withdocument.getElementById(event.data.id).