mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 04:06:27 -04:00
Make contentInjectionMode global
Former-commit-id: 5626d45e2cfa63e65e8cbb3b4000b2c23a08e788 [formerly d93d3ddd46ffcb8a552d4707847a8a628e0143de] Former-commit-id: 52637a9879f42ae8e509368cf5693c95429e0803
This commit is contained in:
parent
7d327f91e8
commit
6bd47a98c3
@ -1160,7 +1160,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
||||
apiStatusPanel.classList.add(apiPanelClass);
|
||||
}
|
||||
|
||||
var contentInjectionMode;
|
||||
var keepAliveServiceWorkerHandle;
|
||||
|
||||
/**
|
||||
@ -1170,7 +1169,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
||||
* and the application
|
||||
*/
|
||||
function initOrKeepAliveServiceWorker() {
|
||||
if (contentInjectionMode === 'serviceworker') {
|
||||
if (params.contentInjectionMode === 'serviceworker') {
|
||||
// Create a new messageChannel
|
||||
var tmpMessageChannel = new MessageChannel();
|
||||
tmpMessageChannel.port1.onmessage = handleMessageChannelMessage;
|
||||
@ -1258,14 +1257,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
||||
});
|
||||
} else {
|
||||
// We need to set this variable earlier else the ServiceWorker does not get reactivated
|
||||
contentInjectionMode = value;
|
||||
params.contentInjectionMode = value;
|
||||
initOrKeepAliveServiceWorker();
|
||||
}
|
||||
}
|
||||
$('input:radio[name=contentInjectionMode]').prop('checked', false);
|
||||
$('input:radio[name=contentInjectionMode]').filter('[value="' + value + '"]').prop('checked', true);
|
||||
contentInjectionMode = value;
|
||||
images.setContentInjectionMode(contentInjectionMode);
|
||||
params.contentInjectionMode = value;
|
||||
// Save the value in a cookie, so that to be able to keep it after a reload/restart
|
||||
cookies.setItem('lastContentInjectionMode', value, Infinity);
|
||||
}
|
||||
@ -2102,7 +2100,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
||||
* @param {DirEntry} dirEntry
|
||||
*/
|
||||
function readArticle(dirEntry) {
|
||||
if (contentInjectionMode === 'serviceworker') {
|
||||
if (params.contentInjectionMode === 'serviceworker') {
|
||||
// In ServiceWorker mode, we simply set the iframe src.
|
||||
// (reading the backend is handled by the ServiceWorker itself)
|
||||
var iframeArticleContent = document.getElementById('articleContent');
|
||||
|
@ -56,6 +56,7 @@ params['hideActiveContentWarning'] = getCookie('hideActiveContentWarning') != nu
|
||||
params['allowHTMLExtraction'] = getCookie('allowHTMLExtraction') == true;
|
||||
params['alphaChar'] = getCookie('alphaChar') || 'A'; //Set default start of alphabet string (used by the Archive Index)
|
||||
params['omegaChar'] = getCookie('omegaChar') || 'Z'; //Set default end of alphabet string
|
||||
params['contentInjectionMode'] = getCookie('contentInjectionMode') || 'jquery'; //Defaults to jquery mode (widest compatibility)
|
||||
|
||||
//Do not touch these values unless you know what they do! Some are global variables, some are set programmatically
|
||||
params['imageDisplayMode'] = params.imageDisplay ? 'progressive' : 'manual';
|
||||
|
@ -21,13 +21,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
|
||||
/**
|
||||
* Declare a module-specific variable defining the contentInjectionMode. Its value may be
|
||||
* changed in setContentInjectionMode()
|
||||
*/
|
||||
var contentInjectionMode = cookies.getItem('lastContentInjectionMode');
|
||||
define(['uiUtil'], function (uiUtil) {
|
||||
|
||||
/**
|
||||
* A variable to keep track of how many images are being extracted by the extractor
|
||||
@ -50,7 +44,7 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
if (!imageUrl) { checkbatch(); return; }
|
||||
image.removeAttribute('data-kiwixurl');
|
||||
var title = decodeURIComponent(imageUrl);
|
||||
if (contentInjectionMode === 'serviceworker') {
|
||||
if (params.contentInjectionMode === 'serviceworker') {
|
||||
image.addEventListener('load', function () {
|
||||
image.style.opacity = '1';
|
||||
});
|
||||
@ -94,7 +88,7 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
var originalHeight = image.getAttribute('height') || '';
|
||||
//Ensure 36px clickable image height so user can request images by tapping
|
||||
image.height = '36';
|
||||
if (contentInjectionMode === 'jquery') {
|
||||
if (params.contentInjectionMode === 'jquery') {
|
||||
image.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E";
|
||||
image.style.background = 'lightblue';
|
||||
}
|
||||
@ -165,6 +159,10 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
remaining.push(images[i]);
|
||||
}
|
||||
}
|
||||
// Callback has to be run inside a timeout because receiving function will expect the visible and remaining arrays to
|
||||
// have been returned before running callback code; NB if images have been scheduled for extraction, callback will be
|
||||
// called above instead of here, but we still need this in case there are no immediately visible images
|
||||
if (callback && !batchCount) setTimeout(callback);
|
||||
return { 'visible': visible, 'remaining': remaining };
|
||||
}
|
||||
|
||||
@ -254,16 +252,6 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility to set the contentInjectionmode in this module
|
||||
* It should be called when the user changes the contentInjectionMode
|
||||
*
|
||||
* @param {String} injectionMode The contentInjectionMode selected by the user
|
||||
*/
|
||||
function setContentInjectionMode(injectionMode) {
|
||||
contentInjectionMode = injectionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
*/
|
||||
@ -272,7 +260,6 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
||||
setupManualImageExtraction: prepareManualExtraction,
|
||||
prepareImagesServiceWorker: prepareImagesServiceWorker,
|
||||
lazyLoad: lazyLoad,
|
||||
loadMathJax: loadMathJax,
|
||||
setContentInjectionMode: setContentInjectionMode
|
||||
loadMathJax: loadMathJax
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user