Merge branch 'master' into file-storage-interface

pull/17/head
Frode Petterson 2016-01-13 15:44:31 +01:00
commit 11481c3b4b
5 changed files with 59 additions and 24 deletions

10
composer.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "h5p/h5p-php-library",
"license": "GPL-3.0",
"autoload": {
"files": [
"h5p-development.class.php",
"h5p.classes.php"
]
}
}

View File

@ -2408,6 +2408,10 @@ class H5PCore {
if($platformInfo['uuid'] === '' && isset($json->uuid)) { if($platformInfo['uuid'] === '' && isset($json->uuid)) {
$this->h5pF->setOption('site_uuid', $json->uuid); $this->h5pF->setOption('site_uuid', $json->uuid);
} }
if (isset($json->latest) && !empty($json->latest)) {
$this->h5pF->setOption('update_available', $json->latest->releasedAt);
$this->h5pF->setOption('update_available_path', $json->latest->path);
}
} }
} }

View File

@ -19,7 +19,6 @@
actionHandlers.hello = function (iframe, data, respond) { actionHandlers.hello = function (iframe, data, respond) {
// Make iframe responsive // Make iframe responsive
iframe.style.width = '100%'; iframe.style.width = '100%';
iframe.contentDocument.body.style.height = 'auto';
// Tell iframe that it needs to resize when our window resizes // Tell iframe that it needs to resize when our window resizes
var resize = function (event) { var resize = function (event) {
@ -47,7 +46,14 @@
* @param {Function} respond Send a response to the iframe * @param {Function} respond Send a response to the iframe
*/ */
actionHandlers.prepareResize = function (iframe, data, respond) { actionHandlers.prepareResize = function (iframe, data, respond) {
respond('resizePrepared'); // Do not resize unless page and scrolling differs
if (iframe.clientHeight !== data.scrollHeight ||
data.scrollHeight !== data.clientHeight) {
// Reset iframe height, in case content has shrinked.
iframe.style.height = data.clientHeight + 'px';
respond('resizePrepared');
}
}; };
/** /**
@ -59,16 +65,8 @@
* @param {Function} respond Send a response to the iframe * @param {Function} respond Send a response to the iframe
*/ */
actionHandlers.resize = function (iframe, data, respond) { actionHandlers.resize = function (iframe, data, respond) {
if (iframe.clientHeight === iframe.contentDocument.body.scrollHeight &&
iframe.contentDocument.body.scrollHeight === iframe.contentWindow.document.body.clientHeight) {
return; // Do not resize unless page and scrolling differs
}
// Reset iframe height, in case content has shrinked.
iframe.style.height = iframe.contentWindow.document.body.clientHeight + 'px';
// Resize iframe so all content is visible. Use scrollHeight to make sure we get everything // Resize iframe so all content is visible. Use scrollHeight to make sure we get everything
iframe.style.height = iframe.contentDocument.body.scrollHeight + 'px'; iframe.style.height = data.scrollHeight + 'px';
}; };
/** /**

View File

@ -95,7 +95,9 @@ 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['cid-' + this.contentId] !== undefined) { if (this.contentId !== undefined &&
H5PIntegration.contents !== undefined &&
H5PIntegration.contents['cid-' + this.contentId] !== undefined) {
this.triggerXAPI('attempted'); this.triggerXAPI('attempted');
} }
this.activityStartTime = Date.now(); this.activityStartTime = Date.now();

View File

@ -279,6 +279,9 @@ H5P.init = function (target) {
// Initial setup/handshake is done // Initial setup/handshake is done
parentIsFriendly = true; parentIsFriendly = true;
// Make iframe responsive
document.body.style.height = 'auto';
// Hide scrollbars for correct size // Hide scrollbars for correct size
document.body.style.overflow = 'hidden'; document.body.style.overflow = 'hidden';
@ -289,7 +292,7 @@ H5P.init = function (target) {
// When resize has been prepared tell parent window to resize // When resize has been prepared tell parent window to resize
H5P.communicator.on('resizePrepared', function (data) { H5P.communicator.on('resizePrepared', function (data) {
H5P.communicator.send('resize', { H5P.communicator.send('resize', {
height: document.body.scrollHeight scrollHeight: document.body.scrollHeight
}); });
}); });
@ -307,7 +310,10 @@ H5P.init = function (target) {
resizeDelay = setTimeout(function () { resizeDelay = setTimeout(function () {
// Only resize if the iframe can be resized // Only resize if the iframe can be resized
if (parentIsFriendly) { if (parentIsFriendly) {
H5P.communicator.send('prepareResize'); H5P.communicator.send('prepareResize', {
scrollHeight: document.body.scrollHeight,
clientHeight: document.body.clientHeight
});
} }
else { else {
H5P.communicator.send('hello'); H5P.communicator.send('hello');
@ -1947,20 +1953,35 @@ 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.
H5P.$window.on('beforeunload', 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});
}
} }
} }
} }
};
// 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);
} }
/** /**