diff --git a/config.xml b/config.xml index be368b0a3..ad367a677 100644 --- a/config.xml +++ b/config.xml @@ -47,6 +47,7 @@ + diff --git a/package-lock.json b/package-lock.json index 3748913af..16767d151 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,7 @@ "@ionic/angular": "^5.6.6", "@moodlehq/cordova-plugin-file-transfer": "1.7.1-moodle.2", "@moodlehq/cordova-plugin-inappbrowser": "5.0.0-moodle.2", + "@moodlehq/cordova-plugin-ionic-webview": "5.0.0-moodle.1", "@moodlehq/cordova-plugin-local-notification": "0.9.0-moodle.2", "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.2", "@moodlehq/phonegap-plugin-push": "2.2.3-moodle.1", @@ -72,7 +73,6 @@ "cordova-plugin-geolocation": "^4.1.0", "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-ionic-keyboard": "^2.2.0", - "cordova-plugin-ionic-webview": "^5.0.0", "cordova-plugin-media": "^5.0.3", "cordova-plugin-media-capture": "^3.0.3", "cordova-plugin-network-information": "^2.0.2", @@ -145,7 +145,7 @@ "typescript": "^3.9.9" }, "engines": { - "node": ">=12.x" + "node": ">=14.15.0 <15" }, "optionalDependencies": { "keytar": "^7.2.0" @@ -4970,6 +4970,24 @@ } } }, + "node_modules/@moodlehq/cordova-plugin-ionic-webview": { + "version": "5.0.0-moodle.1", + "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0-moodle.1.tgz", + "integrity": "sha512-+6UrPKsEgXl3pcuTyI1hZIUw9y22Li/nvn7nxiphgZdldlhBvkMK/7nn4IAaXYlnrmIOpCkIrU4BbrAjSJGWSQ==", + "engines": { + "cordovaDependencies": { + "2.0.0": { + "cordova-android": ">=6.4.0", + "cordova-ios": ">=4.0.0-dev" + }, + "3.1.0": { + "cordova": ">=7.1.0", + "cordova-android": ">=6.4.0", + "cordova-ios": ">=4.0.0-dev" + } + } + } + }, "node_modules/@moodlehq/cordova-plugin-local-notification": { "version": "0.9.0-moodle.2", "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-local-notification/-/cordova-plugin-local-notification-0.9.0-moodle.2.tgz", @@ -10899,24 +10917,6 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-keyboard/-/cordova-plugin-ionic-keyboard-2.2.0.tgz", "integrity": "sha512-yDUG+9ieKVRitq5mGlNxjaZh/MgEhFFIgTIPhqSbUaQ8UuZbawy5mhJAVClqY97q8/rcQtL6dCDa7x2sEtCLcA==" }, - "node_modules/cordova-plugin-ionic-webview": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0.tgz", - "integrity": "sha512-Wq0kCanxubK/JroTW4Mp5soayScnRyiY1eCkbwiz1Dyt1xHOiOW/v+1miqtBHtnZhcXw25TulCKAVJzkNBdmyg==", - "engines": { - "cordovaDependencies": { - "2.0.0": { - "cordova-android": ">=6.4.0", - "cordova-ios": ">=4.0.0-dev" - }, - "3.1.0": { - "cordova": ">=7.1.0", - "cordova-android": ">=6.4.0", - "cordova-ios": ">=4.0.0-dev" - } - } - } - }, "node_modules/cordova-plugin-media": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/cordova-plugin-media/-/cordova-plugin-media-5.0.3.tgz", @@ -34720,6 +34720,11 @@ "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-inappbrowser/-/cordova-plugin-inappbrowser-5.0.0-moodle.2.tgz", "integrity": "sha512-0JOLHUFEJC3fv4OQuyr2kwNyrb7oeyjmfFLQ+LcKO41e6UOnNy/du0hU7Yz9Rh8B2zGcebvSwMrN+cRSCqlipQ==" }, + "@moodlehq/cordova-plugin-ionic-webview": { + "version": "5.0.0-moodle.1", + "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0-moodle.1.tgz", + "integrity": "sha512-+6UrPKsEgXl3pcuTyI1hZIUw9y22Li/nvn7nxiphgZdldlhBvkMK/7nn4IAaXYlnrmIOpCkIrU4BbrAjSJGWSQ==" + }, "@moodlehq/cordova-plugin-local-notification": { "version": "0.9.0-moodle.2", "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-local-notification/-/cordova-plugin-local-notification-0.9.0-moodle.2.tgz", @@ -39330,11 +39335,6 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-keyboard/-/cordova-plugin-ionic-keyboard-2.2.0.tgz", "integrity": "sha512-yDUG+9ieKVRitq5mGlNxjaZh/MgEhFFIgTIPhqSbUaQ8UuZbawy5mhJAVClqY97q8/rcQtL6dCDa7x2sEtCLcA==" }, - "cordova-plugin-ionic-webview": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-5.0.0.tgz", - "integrity": "sha512-Wq0kCanxubK/JroTW4Mp5soayScnRyiY1eCkbwiz1Dyt1xHOiOW/v+1miqtBHtnZhcXw25TulCKAVJzkNBdmyg==" - }, "cordova-plugin-media": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/cordova-plugin-media/-/cordova-plugin-media-5.0.3.tgz", diff --git a/package.json b/package.json index 8331ec89d..410bf7793 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@ionic/angular": "^5.6.6", "@moodlehq/cordova-plugin-file-transfer": "1.7.1-moodle.2", "@moodlehq/cordova-plugin-inappbrowser": "5.0.0-moodle.2", + "@moodlehq/cordova-plugin-ionic-webview": "5.0.0-moodle.1", "@moodlehq/cordova-plugin-local-notification": "0.9.0-moodle.2", "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.2", "@moodlehq/phonegap-plugin-push": "2.2.3-moodle.1", @@ -100,7 +101,6 @@ "cordova-plugin-geolocation": "^4.1.0", "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-ionic-keyboard": "^2.2.0", - "cordova-plugin-ionic-webview": "^5.0.0", "cordova-plugin-media": "^5.0.3", "cordova-plugin-media-capture": "^3.0.3", "cordova-plugin-network-information": "^2.0.2", @@ -203,7 +203,7 @@ }, "@moodlehq/cordova-plugin-inappbrowser": {}, "cordova-plugin-ionic-keyboard": {}, - "cordova-plugin-ionic-webview": {}, + "@moodlehq/cordova-plugin-ionic-webview": {}, "@moodlehq/cordova-plugin-local-notification": { "ANDROID_SUPPORT_V4_VERSION": "26.+" }, diff --git a/src/core/features/h5p/assets/js/h5p.js b/src/core/features/h5p/assets/js/h5p.js index ee1888a55..424ac842f 100644 --- a/src/core/features/h5p/assets/js/h5p.js +++ b/src/core/features/h5p/assets/js/h5p.js @@ -32,13 +32,17 @@ if (document.documentElement.requestFullScreen) { H5P.fullScreenBrowserPrefix = ''; } else if (document.documentElement.webkitRequestFullScreen) { - H5P.safariBrowser = navigator.userAgent.match(/version\/([.\d]+)/i); - H5P.safariBrowser = (H5P.safariBrowser === null ? 0 : parseInt(H5P.safariBrowser[1])); + // This code has been changed to allow full screen in Moodle app. + H5P.fullScreenBrowserPrefix = 'webkit'; + H5P.safariBrowser = 0; - // Do not allow fullscreen for safari < 7. - if (H5P.safariBrowser === 0 || H5P.safariBrowser > 6) { - H5P.fullScreenBrowserPrefix = 'webkit'; - } + // H5P.safariBrowser = navigator.userAgent.match(/version\/([.\d]+)/i); + // H5P.safariBrowser = (H5P.safariBrowser === null ? 0 : parseInt(H5P.safariBrowser[1])); + + // // Do not allow fullscreen for safari < 7. + // if (H5P.safariBrowser === 0 || H5P.safariBrowser > 6) { + // H5P.fullScreenBrowserPrefix = 'webkit'; + // } } else if (document.documentElement.mozRequestFullScreen) { H5P.fullScreenBrowserPrefix = 'moz'; diff --git a/src/core/features/h5p/assets/moodle/js/embed.js b/src/core/features/h5p/assets/moodle/js/embed.js index 904eded89..5d86fa63d 100644 --- a/src/core/features/h5p/assets/moodle/js/embed.js +++ b/src/core/features/h5p/assets/moodle/js/embed.js @@ -136,7 +136,7 @@ document.onreadystatechange = function() { // When resize has been prepared tell parent window to resize. H5PEmbedCommunicator.on('resizePrepared', function() { H5PEmbedCommunicator.send('resize', { - scrollHeight: iFrame.contentDocument.body.scrollHeight + scrollHeight: getIframeBodyHeights(iFrame).scrollHeight }); }); @@ -154,10 +154,11 @@ document.onreadystatechange = function() { resizeDelay = setTimeout(function() { // Only resize if the iframe can be resized. if (parentIsFriendly) { + var heights = getIframeBodyHeights(iFrame); H5PEmbedCommunicator.send('prepareResize', { - scrollHeight: iFrame.contentDocument.body.scrollHeight, - clientHeight: iFrame.contentDocument.body.clientHeight + scrollHeight: heights.scrollHeight, + clientHeight: heights.clientHeight } ); } else { @@ -201,3 +202,14 @@ document.onreadystatechange = function() { // Trigger initial resize for instance. H5P.trigger(instance, 'resize'); }; + +// Function created for the Moodle app. +// It also takes the current body margin into account because some user agents put some margin to the body of the outer iframe. +function getIframeBodyHeights(iFrame) { + var margin = parseInt(getComputedStyle(document.body)['margin'], 10) || 0; + + return { + scrollHeight: iFrame.contentDocument.body.scrollHeight + margin * 2, + clientHeight: iFrame.contentDocument.body.clientHeight + margin * 2, + }; +} diff --git a/src/core/features/h5p/assets/readme_moodle.txt b/src/core/features/h5p/assets/readme_moodle.txt new file mode 100644 index 000000000..7a5805bae --- /dev/null +++ b/src/core/features/h5p/assets/readme_moodle.txt @@ -0,0 +1,6 @@ +H5P library +--------------- + +Changes: + +1. The h5p.js file has been modified to make fullscreen work in the Moodle app. In line 34, the code inside the condition document.documentElement.webkitRequestFullScreen has changed, the original code has been commented.