Merge branch 'release' of github.com:h5p/h5p-php-library into release

pull/17/head Drupal-7.x-1.12
Frode Petterson 2016-01-05 13:58:20 +01:00
commit 510016b1cc
2 changed files with 24 additions and 10 deletions

View File

@ -95,7 +95,8 @@ H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, ver
H5P.EventDispatcher.prototype.setActivityStarted = function() { H5P.EventDispatcher.prototype.setActivityStarted = function() {
if (this.activityStartTime === undefined) { if (this.activityStartTime === undefined) {
// Don't trigger xAPI events in the editor // Don't trigger xAPI events in the editor
if (H5PIntegration.contents !== undefined && if (this.contentId !== undefined &&
H5PIntegration.contents !== undefined &&
H5PIntegration.contents['cid-' + this.contentId] !== undefined) { H5PIntegration.contents['cid-' + this.contentId] !== undefined) {
this.triggerXAPI('attempted'); this.triggerXAPI('attempted');
} }

View File

@ -1953,21 +1953,34 @@ H5P.createTitle = function (rawTitle, maxLength) {
} }
if (H5PIntegration.saveFreq !== false) { if (H5PIntegration.saveFreq !== false) {
// When was the last state stored
var lastStoredOn = 0;
// Store the current state of the H5P when leaving the page. // Store the current state of the H5P when leaving the page.
var storeCurrentState = function () { var storeCurrentState = function () {
for (var i = 0; i < H5P.instances.length; i++) { // Make sure at least 250 ms has passed since last save
var instance = H5P.instances[i]; var currentTime = new Date().getTime();
if (instance.getCurrentState instanceof Function || if (currentTime - lastStoredOn > 250) {
typeof instance.getCurrentState === 'function') { lastStoredOn = currentTime;
var state = instance.getCurrentState(); for (var i = 0; i < H5P.instances.length; i++) {
if (state !== undefined) { var instance = H5P.instances[i];
// Async is not used to prevent the request from being cancelled. if (instance.getCurrentState instanceof Function ||
H5P.setUserData(instance.contentId, 'state', state, {deleteOnChange: true, async: false}); typeof instance.getCurrentState === 'function') {
var state = instance.getCurrentState();
if (state !== undefined) {
// Async is not used to prevent the request from being cancelled.
H5P.setUserData(instance.contentId, 'state', state, {deleteOnChange: true, async: false});
}
} }
} }
} }
}; };
H5P.$window.one('beforeunload unload', storeCurrentState); // iPad does not support beforeunload, therefore using unload
H5P.$window.one('beforeunload unload', function () {
// Only want to do this once
H5P.$window.off('pagehide beforeunload unload');
storeCurrentState();
});
// pagehide is used on iPad when tabs are switched
H5P.$window.on('pagehide', storeCurrentState); H5P.$window.on('pagehide', storeCurrentState);
} }