pull/66/merge
Oliver Tacke 2021-12-22 00:58:35 +01:00 committed by GitHub
commit 37c0b54b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 4 deletions

View File

@ -19,6 +19,19 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
this.itemName = 'requestQueue'; this.itemName = 'requestQueue';
}; };
/**
* Check whether localStorage is accessible.
* @return {boolean} True, if window.localStorage is accessible, else false.
*/
RequestQueue.prototype.isLocalStorageAccessible = function () {
try {
return (window.localStorage) ? true : false;
}
catch (event) {
return false;
}
};
/** /**
* Add request to queue. Only supports posts currently. * Add request to queue. Only supports posts currently.
* *
@ -27,7 +40,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
* @returns {boolean} * @returns {boolean}
*/ */
RequestQueue.prototype.add = function (url, data) { RequestQueue.prototype.add = function (url, data) {
if (!window.localStorage) { if (!this.isLocalStorageAccessible()) {
return false; return false;
} }
@ -56,7 +69,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
* @returns {boolean|Array} Stored requests * @returns {boolean|Array} Stored requests
*/ */
RequestQueue.prototype.getStoredRequests = function () { RequestQueue.prototype.getStoredRequests = function () {
if (!window.localStorage) { if (!this.isLocalStorageAccessible()) {
return false; return false;
} }
@ -74,7 +87,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
* @returns {boolean} True if the storage was successfully cleared * @returns {boolean} True if the storage was successfully cleared
*/ */
RequestQueue.prototype.clearQueue = function () { RequestQueue.prototype.clearQueue = function () {
if (!window.localStorage) { if (!this.isLocalStorageAccessible()) {
return false; return false;
} }
@ -89,7 +102,7 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
*/ */
RequestQueue.prototype.resumeQueue = function () { RequestQueue.prototype.resumeQueue = function () {
// Not supported // Not supported
if (!H5PIntegration || !window.navigator || !window.localStorage) { if (!H5PIntegration || !window.navigator || !this.isLocalStorageAccessible()) {
return false; return false;
} }
@ -204,6 +217,21 @@ H5P.RequestQueue = (function ($, EventDispatcher) {
*/ */
H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) { H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
let localStorageSupported;
try {
localStorageSupported = (window.localStorage !== undefined);
}
catch (exception) {
localStorageSupported = false;
}
if (!localStorageSupported) {
// Return dummy class with the same interface, but which does nothing:
return function () {
this.add = function () {};
};
}
/** /**
* Constructor * Constructor
* *