From 5edc8de380696a91d11639e7beb1cccd9478ed73 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 15 Mar 2021 13:01:25 +0100 Subject: [PATCH] MOBILE-3645 build: Add script to copy some files to www --- .gitignore | 1 + ionic.config.json | 8 +++- package-lock.json | 27 +++++++------ package.json | 2 + scripts/copy-assets.js | 39 +++++++++++++++++++ .../services/handlers/mathjaxloader.ts | 16 +++++++- src/core/features/h5p/classes/file-storage.ts | 2 +- src/core/services/update-manager.ts | 2 +- src/index.html | 2 + 9 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 scripts/copy-assets.js diff --git a/.gitignore b/.gitignore index 73624db7a..e120915ae 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ npm-debug.log* /platforms /plugins /www +/src/assets/lib /moodle.*.config.json !/moodle.example.config.json diff --git a/ionic.config.json b/ionic.config.json index e2b08c753..f62bd95cc 100644 --- a/ionic.config.json +++ b/ionic.config.json @@ -3,5 +3,9 @@ "integrations": { "cordova": {} }, - "type": "angular" -} \ No newline at end of file + "type": "angular", + "hooks": { + "build:before": "./scripts/copy-assets.js", + "serve:before": "./scripts/copy-assets.js" + } +} diff --git a/package-lock.json b/package-lock.json index 7e9ee4e69..c8224530d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10531,14 +10531,14 @@ "optional": true }, "fs-extra": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz", - "integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", "requires": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", - "universalify": "^1.0.0" + "universalify": "^2.0.0" } }, "fs-minipass": { @@ -14192,12 +14192,12 @@ "dev": true }, "jsonfile": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz", - "integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "requires": { "graceful-fs": "^4.1.6", - "universalify": "^1.0.0" + "universalify": "^2.0.0" } }, "jsonparse": { @@ -15061,6 +15061,11 @@ } } }, + "mathjax": { + "version": "2.7.7", + "resolved": "https://registry.npmjs.org/mathjax/-/mathjax-2.7.7.tgz", + "integrity": "sha512-OOl0B2/0tSJAtAZarXnQuLDBLgTNRqiI9VqHTQzPsxf4okT2iIpDrvaklK9x2QEMD1sDj4yRn11Ygci41DxMAQ==" + }, "md5-file": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz", @@ -21796,9 +21801,9 @@ } }, "universalify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", - "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" }, "unorm": { "version": "1.6.0", diff --git a/package.json b/package.json index a4b3d2811..e58e0e2e3 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,7 @@ "core-js": "^3.9.1", "es6-promise-plugin": "^4.2.2", "jszip": "^3.5.0", + "mathjax": "2.7.7", "moment": "^2.29.0", "nl.kingsquare.cordova.background-audio": "^1.0.1", "phonegap-plugin-multidex": "^1.0.0", @@ -149,6 +150,7 @@ "eslint-plugin-prefer-arrow": "^1.2.2", "eslint-plugin-promise": "^4.2.1", "faker": "^5.1.0", + "fs-extra": "^9.1.0", "gulp": "4.0.2", "gulp-clip-empty-files": "^0.1.2", "gulp-concat": "^2.6.1", diff --git a/scripts/copy-assets.js b/scripts/copy-assets.js new file mode 100644 index 000000000..3b3f03ea4 --- /dev/null +++ b/scripts/copy-assets.js @@ -0,0 +1,39 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * Script to copy some files to the www folder. + */ +const fse = require('fs-extra'); +const path = require('path'); + +// Assets to copy. +const ASSETS = { + '/node_modules/mathjax/MathJax.js': '/lib/mathjax/MathJax.js', + '/node_modules/mathjax/extensions': '/lib/mathjax/extensions', + '/node_modules/mathjax/jax/element': '/lib/mathjax/jax/element', + '/node_modules/mathjax/jax/input': '/lib/mathjax/jax/input', + '/node_modules/mathjax/jax/output/SVG': '/lib/mathjax/jax/output/SVG', + '/node_modules/mathjax/jax/output/PreviewHTML': '/lib/mathjax/jax/output/PreviewHTML', + '/node_modules/mathjax/localization': '/lib/mathjax/localization', + '/src/core/features/h5p/assets': '/lib/h5p', +}; + +module.exports = function(ctx) { + const assetsPath = ctx.project.srcDir + '/assets'; + + for (const src in ASSETS) { + fse.copySync(ctx.project.dir + src, assetsPath + ASSETS[src], { overwrite: true }); + } +}; diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index ca9963c39..a0aab60bf 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -245,7 +245,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan const equations = Array.from(container.querySelectorAll('.filter_mathjaxloader_equation')); equations.forEach((node) => { - that.window.MathJax.Hub.Queue(['Typeset', that.window.MathJax.Hub, node]); + that.window.MathJax.Hub.Queue(['Typeset', that.window.MathJax.Hub, node], [that.fixUseUrls, node]); }); // Set the delay back to normal after processing. @@ -255,6 +255,20 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan }; } + /** + * Fix URLs in elements. + * This is needed because MathJax stores the location.href when it's loaded, and then sets that URL to all the + * elements href. Since the app URL changes when navigating, the SVGs can use a URL that isn't the current page. + * When that happens, the request returns a 404 error and the SVG isn't displayed. + * + * @param node Element that can contain equations. + */ + protected fixUseUrls(node: Element): void { + Array.from(node.querySelectorAll('use')).forEach((useElem) => { + useElem.setAttribute('href', useElem.href.baseVal.substr(useElem.href.baseVal.indexOf('#'))); + }); + } + /** * Perform a mapping of the app language code to the equivalent for MathJax. * diff --git a/src/core/features/h5p/classes/file-storage.ts b/src/core/features/h5p/classes/file-storage.ts index 76105c1c9..1c811674b 100644 --- a/src/core/features/h5p/classes/file-storage.ts +++ b/src/core/features/h5p/classes/file-storage.ts @@ -376,7 +376,7 @@ export class CoreH5PFileStorage { * @return Folder path. */ getCoreH5PPath(): string { - return CoreTextUtils.concatenatePaths(CoreFile.getWWWPath(), '/h5p/'); + return CoreTextUtils.concatenatePaths(CoreFile.getWWWPath(), '/assets/lib/h5p/'); } /** diff --git a/src/core/services/update-manager.ts b/src/core/services/update-manager.ts index cf608e954..ed030e4c4 100644 --- a/src/core/services/update-manager.ts +++ b/src/core/services/update-manager.ts @@ -48,7 +48,7 @@ export class CoreUpdateManagerProvider { const versionApplied = await CoreConfig.get(VERSION_APPLIED, 0); - if (versionCode >= 3900 && versionApplied < 3900 && versionApplied > 0) { + if (versionCode >= 3950 && versionApplied < 3950 && versionApplied > 0) { promises.push(CoreH5P.h5pPlayer.deleteAllContentIndexes()); } diff --git a/src/index.html b/src/index.html index df229b489..83fb2a51f 100644 --- a/src/index.html +++ b/src/index.html @@ -17,6 +17,8 @@ + +