mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 12:53:54 -04:00
Add params for source of CSS
Adds params in init.js for selecting source of CSS ("zimfile", "local" or "mobile"). User selection still to be implemented. Default is "zimfile". Former-commit-id: 311bac831c130592414cbb0df5ddba7eac61f5aa [formerly 903a65084c766f414c13115fd890017ca579814d] Former-commit-id: 96c6d751437772809e39a4a41785bcc71cd02cbb
This commit is contained in:
parent
3bb9bb65e8
commit
547a4d0cad
@ -26,15 +26,14 @@
|
|||||||
// This uses require.js to structure javascript:
|
// This uses require.js to structure javascript:
|
||||||
// http://requirejs.org/docs/api.html#define
|
// http://requirejs.org/docs/api.html#define
|
||||||
|
|
||||||
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFilesystemAccess'],
|
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFilesystemAccess', 'module'],
|
||||||
function($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess) {
|
function($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess, module) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of articles to display in a search
|
* Maximum number of articles to display in a search
|
||||||
* @type Integer
|
* @type Integer
|
||||||
*/
|
*/
|
||||||
//var MAX_SEARCH_RESULT_SIZE = 50;
|
var MAX_SEARCH_RESULT_SIZE = module.config().results; //This is set in init.js
|
||||||
var MAX_SEARCH_RESULT_SIZE = 20; //GK - speed up search
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type ZIMArchive
|
* @type ZIMArchive
|
||||||
@ -795,15 +794,17 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
if (regexpMetadataUrl.test(linkArray[2])) { //It's a CSS file contained in ZIM
|
if (regexpMetadataUrl.test(linkArray[2])) { //It's a CSS file contained in ZIM
|
||||||
var zimLink = decodeURIComponent(uiUtil.removeUrlParameters(linkArray[2]));
|
var zimLink = decodeURIComponent(uiUtil.removeUrlParameters(linkArray[2]));
|
||||||
//If this is a standard Wikipedia css stylesheet cached in the filesystem...
|
//If this is a standard Wikipedia css stylesheet cached in the filesystem...
|
||||||
if (zimLink.match(/-\/s\/style\.css/i) ||
|
if ((module.config().cssSource != "zimfile") &&
|
||||||
|
(zimLink.match(/-\/s\/style\.css/i) ||
|
||||||
zimLink.match(/-\/s\/css_modules\/mediawiki\.toc\.css/i) ||
|
zimLink.match(/-\/s\/css_modules\/mediawiki\.toc\.css/i) ||
|
||||||
zimLink.match(/-\/s\/css_modules\/ext\.cite\.styles\.css/i) ||
|
zimLink.match(/-\/s\/css_modules\/ext\.cite\.styles\.css/i) ||
|
||||||
zimLink.match(/-\/s\/css_modules\/ext\.cite\.a11y\.css/i)) {
|
zimLink.match(/-\/s\/css_modules\/ext\.cite\.a11y\.css/i))) {
|
||||||
blobArray[i] = zimLink; //Store href as is
|
blobArray[i] = zimLink.match(/-\/s\/style\.css/i) && module.config().cssSource == "mobile" ? "../-/s/style-mobile.css" : zimLink;
|
||||||
|
console.log("Matched #" + i + " [" + blobArray[i] + "] from local filesystem");
|
||||||
injectCSS();
|
injectCSS();
|
||||||
} else { //Try to get the stylesheet from the ZIM file
|
} else { //Try to get the stylesheet from the ZIM file
|
||||||
var linkURL = zimLink.match(regexpMetadataUrl)[1];
|
var linkURL = zimLink.match(regexpMetadataUrl)[1];
|
||||||
console.log("Attempting to resolve CSS link #" + i + "...");
|
console.log("Attempting to resolve CSS link #" + i + " [" + linkURL + "] from ZIM file...");
|
||||||
resolveCSS(linkURL, i); //Pass link and index
|
resolveCSS(linkURL, i); //Pass link and index
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -838,9 +839,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
htmlArticle = htmlArticle.replace(regexpSheetHref, ""); //Void existing stylesheets
|
htmlArticle = htmlArticle.replace(regexpSheetHref, ""); //Void existing stylesheets
|
||||||
var cssArray$ = "\r\n" + cssArray.join("\r\n") + "\r\n";
|
var cssArray$ = "\r\n" + cssArray.join("\r\n") + "\r\n";
|
||||||
htmlArticle = htmlArticle.replace(/\s*(<\/head>)/i, cssArray$ + "$1");
|
htmlArticle = htmlArticle.replace(/\s*(<\/head>)/i, cssArray$ + "$1");
|
||||||
|
console.log("All CSS resolved");
|
||||||
injectHTML(htmlArticle); //This passes the revised HTML to the image and JS subroutine...
|
injectHTML(htmlArticle); //This passes the revised HTML to the image and JS subroutine...
|
||||||
} else {
|
} else {
|
||||||
console.log("Waiting for " + (cssArray.length - blobArray.length) + " out of " + cssArray.length + " to resolve...")
|
//console.log("Waiting for " + (cssArray.length - blobArray.length) + " out of " + cssArray.length + " to resolve...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//End of preload stylesheets code
|
//End of preload stylesheets code
|
||||||
|
@ -21,9 +21,13 @@
|
|||||||
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var params = {};
|
||||||
|
var results = params['results'] || 10; //Number of search results to display
|
||||||
|
var cssSource = params['cssSource'] || "zimfile"; //One of "zimfile", "local" or "mobile""
|
||||||
|
|
||||||
require.config({
|
require.config({
|
||||||
baseUrl: 'js/lib',
|
baseUrl: 'js/lib',
|
||||||
|
config: { '../app': { results: results, cssSource: cssSource } },
|
||||||
paths: {
|
paths: {
|
||||||
//'jquery': 'jquery-2.1.4',
|
//'jquery': 'jquery-2.1.4',
|
||||||
//'jquery': 'jquery-3.2.1',
|
//'jquery': 'jquery-3.2.1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user