mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 20:32:45 -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);
|
apiStatusPanel.classList.add(apiPanelClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentInjectionMode;
|
|
||||||
var keepAliveServiceWorkerHandle;
|
var keepAliveServiceWorkerHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1170,7 +1169,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
|||||||
* and the application
|
* and the application
|
||||||
*/
|
*/
|
||||||
function initOrKeepAliveServiceWorker() {
|
function initOrKeepAliveServiceWorker() {
|
||||||
if (contentInjectionMode === 'serviceworker') {
|
if (params.contentInjectionMode === 'serviceworker') {
|
||||||
// Create a new messageChannel
|
// Create a new messageChannel
|
||||||
var tmpMessageChannel = new MessageChannel();
|
var tmpMessageChannel = new MessageChannel();
|
||||||
tmpMessageChannel.port1.onmessage = handleMessageChannelMessage;
|
tmpMessageChannel.port1.onmessage = handleMessageChannelMessage;
|
||||||
@ -1258,14 +1257,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// We need to set this variable earlier else the ServiceWorker does not get reactivated
|
// We need to set this variable earlier else the ServiceWorker does not get reactivated
|
||||||
contentInjectionMode = value;
|
params.contentInjectionMode = value;
|
||||||
initOrKeepAliveServiceWorker();
|
initOrKeepAliveServiceWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$('input:radio[name=contentInjectionMode]').prop('checked', false);
|
$('input:radio[name=contentInjectionMode]').prop('checked', false);
|
||||||
$('input:radio[name=contentInjectionMode]').filter('[value="' + value + '"]').prop('checked', true);
|
$('input:radio[name=contentInjectionMode]').filter('[value="' + value + '"]').prop('checked', true);
|
||||||
contentInjectionMode = value;
|
params.contentInjectionMode = value;
|
||||||
images.setContentInjectionMode(contentInjectionMode);
|
|
||||||
// Save the value in a cookie, so that to be able to keep it after a reload/restart
|
// Save the value in a cookie, so that to be able to keep it after a reload/restart
|
||||||
cookies.setItem('lastContentInjectionMode', value, Infinity);
|
cookies.setItem('lastContentInjectionMode', value, Infinity);
|
||||||
}
|
}
|
||||||
@ -2102,7 +2100,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
|
|||||||
* @param {DirEntry} dirEntry
|
* @param {DirEntry} dirEntry
|
||||||
*/
|
*/
|
||||||
function readArticle(dirEntry) {
|
function readArticle(dirEntry) {
|
||||||
if (contentInjectionMode === 'serviceworker') {
|
if (params.contentInjectionMode === 'serviceworker') {
|
||||||
// In ServiceWorker mode, we simply set the iframe src.
|
// In ServiceWorker mode, we simply set the iframe src.
|
||||||
// (reading the backend is handled by the ServiceWorker itself)
|
// (reading the backend is handled by the ServiceWorker itself)
|
||||||
var iframeArticleContent = document.getElementById('articleContent');
|
var iframeArticleContent = document.getElementById('articleContent');
|
||||||
|
@ -56,6 +56,7 @@ params['hideActiveContentWarning'] = getCookie('hideActiveContentWarning') != nu
|
|||||||
params['allowHTMLExtraction'] = getCookie('allowHTMLExtraction') == true;
|
params['allowHTMLExtraction'] = getCookie('allowHTMLExtraction') == true;
|
||||||
params['alphaChar'] = getCookie('alphaChar') || 'A'; //Set default start of alphabet string (used by the Archive Index)
|
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['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
|
//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';
|
params['imageDisplayMode'] = params.imageDisplay ? 'progressive' : 'manual';
|
||||||
|
@ -21,13 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
define(['uiUtil'], function (uiUtil) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Declare a module-specific variable defining the contentInjectionMode. Its value may be
|
|
||||||
* changed in setContentInjectionMode()
|
|
||||||
*/
|
|
||||||
var contentInjectionMode = cookies.getItem('lastContentInjectionMode');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A variable to keep track of how many images are being extracted by the extractor
|
* 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; }
|
if (!imageUrl) { checkbatch(); return; }
|
||||||
image.removeAttribute('data-kiwixurl');
|
image.removeAttribute('data-kiwixurl');
|
||||||
var title = decodeURIComponent(imageUrl);
|
var title = decodeURIComponent(imageUrl);
|
||||||
if (contentInjectionMode === 'serviceworker') {
|
if (params.contentInjectionMode === 'serviceworker') {
|
||||||
image.addEventListener('load', function () {
|
image.addEventListener('load', function () {
|
||||||
image.style.opacity = '1';
|
image.style.opacity = '1';
|
||||||
});
|
});
|
||||||
@ -94,7 +88,7 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
|||||||
var originalHeight = image.getAttribute('height') || '';
|
var originalHeight = image.getAttribute('height') || '';
|
||||||
//Ensure 36px clickable image height so user can request images by tapping
|
//Ensure 36px clickable image height so user can request images by tapping
|
||||||
image.height = '36';
|
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.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E";
|
||||||
image.style.background = 'lightblue';
|
image.style.background = 'lightblue';
|
||||||
}
|
}
|
||||||
@ -165,6 +159,10 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
|||||||
remaining.push(images[i]);
|
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 };
|
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
|
* Functions and classes exposed by this module
|
||||||
*/
|
*/
|
||||||
@ -272,7 +260,6 @@ define(['uiUtil', 'cookies'], function (uiUtil, cookies) {
|
|||||||
setupManualImageExtraction: prepareManualExtraction,
|
setupManualImageExtraction: prepareManualExtraction,
|
||||||
prepareImagesServiceWorker: prepareImagesServiceWorker,
|
prepareImagesServiceWorker: prepareImagesServiceWorker,
|
||||||
lazyLoad: lazyLoad,
|
lazyLoad: lazyLoad,
|
||||||
loadMathJax: loadMathJax,
|
loadMathJax: loadMathJax
|
||||||
setContentInjectionMode: setContentInjectionMode
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user