mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 11:48:26 -04:00
Allow user to strip the mobile stylesheets
Former-commit-id: 304fb75c0d055ac1b43e614e67598d5ca3633aad [formerly 46c1a05f68c964b9a71f017fcdf24192dd476757] Former-commit-id: 6c5bc8226d12ca52a55f64741bee166785979187
This commit is contained in:
parent
467936de1f
commit
3529ccdf4a
File diff suppressed because one or more lines are too long
@ -13,8 +13,8 @@
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
.mw-body h3, .mw-body h2 {
|
||||
clear: both;
|
||||
width: 100%;
|
||||
/*clear: both;*/
|
||||
/*width: 100%;*/
|
||||
margin-bottom: 0.5em;
|
||||
border-bottom: solid 1px #eaecf0;
|
||||
font-family: 'Linux Libertine','Georgia','Times',serif;
|
||||
|
@ -208,6 +208,8 @@
|
||||
<br />
|
||||
<input type="radio" name="cssInjectionMode" value="mobile" id="cssModeMobileRadio"><label for="cssModeMobileRadio"> Use Wikipedia mobile display style</label> (only works with standard Wikipedia ZIM files)
|
||||
<br />
|
||||
<input type="radio" name="cssInjectionMode" value="desktop" id="cssModeMobileRadio"><label for="cssModeMobileRadio"> Use Wikipedia desktop display style</label> (strips mobile formatting if your ZIM file is pre-formatted for mobile)
|
||||
<br />
|
||||
<input type="radio" name="cssInjectionMode" value="zimfile" id="cssModeZIMfileRadio"><label for="cssModeZIMfileRadio"> Use styles embedded in the ZIM file</label> (slower retrieval, uses more memory if accessing large Wikipedia ZIMs)
|
||||
</div>
|
||||
<h2>Expert settings</h2>
|
||||
|
@ -791,6 +791,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
||||
|
||||
//Extract CSS URLs from given array of links
|
||||
function getBLOB(arr) {
|
||||
if (cssSource == "desktop" && (!arr.join().match(/-\/s\/style\.css/i))) {
|
||||
arr.push('<link href="../-/s/style.css" rel="stylesheet">'); //Insert the standard desktop style
|
||||
}
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var linkArray = regexpSheetHref.exec(arr[i]);
|
||||
regexpSheetHref.lastIndex = 0; //Reset start position for next loop
|
||||
@ -810,6 +813,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
||||
zimLink.match(/-\/s\/css_modules\/mobile\.css/i) ||
|
||||
zimLink.match(/-\/s\/css_modules\/skins\.minerva\.base\.reset\|skins\.minerva\.content\.styles\|ext\.cite\.style\|mediawiki\.page\.gallery\.styles\|mobile\.app\.pagestyles\.android\|mediawiki\.skinning\.content\.parsoid\.css/i)
|
||||
)) {
|
||||
if (cssSource == "desktop" && zimLink.match(/minerva|mobile|parsoid/)) { //If user selected desktop style and the ZIM is formatted for mobile...
|
||||
zimLink = "#"; //Void the style
|
||||
}
|
||||
if ((cssSource == "mobile") || (zimLink.match(/minerva/))) { //If user has selected mobile display mode or mobile is built into ZIM, substitute main stylesheet
|
||||
zimLink = zimLink.match(/(-\/s\/style\.css)|(minerva)/i) ? "../-/s/style-mobile.css" : zimLink;
|
||||
}
|
||||
@ -862,6 +868,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
||||
htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*thumbcaption\s*["']\s*/ig, 'style="margin: 0.5em 0 0; font-size: 0.8em; line-height: 1.5; padding: 0 !important; color: #54595d; width: auto !important;"');
|
||||
htmlArticle = htmlArticle.replace(/(table\s+(?=[^>]*class\s*=\s*["'][^"']*infobox)[^>]*style\s*=\s*["'][^"']+[^;'"]);?\s*["']/ig, '$1; position: relative; border: 1px solid #eaecf0; text-align: left; background-color: #f8f9fa;"');
|
||||
}
|
||||
if (cssSource == "desktop") { //If user has selected desktop display mode...
|
||||
htmlArticle = htmlArticle.replace(/class\s*=\s*["']\s*mw-body\s*["']\s*/ig, 'style="background-color: white; padding: 1em; border-width: 0px; max-width: 55.8em; margin: 0 auto 0 auto;"');
|
||||
htmlArticle = htmlArticle.replace(/<h1\s*[^>]+titleHeading[^>]+>\s*<\/h1>\s*/ig, ""); //Void empty header title
|
||||
}
|
||||
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...
|
||||
|
@ -23,7 +23,7 @@
|
||||
'use strict';
|
||||
var params = {};
|
||||
var results = params['results'] || 10; //Number of search results to display
|
||||
var cssSource = params['cssSource'] || "local"; //One of "zimfile", "local" or "mobile""
|
||||
var cssSource = params['cssSource'] || "local"; //One of "zimfile", "local", "desktop" or "mobile""
|
||||
|
||||
require.config({
|
||||
baseUrl: 'js/lib',
|
||||
|
Loading…
x
Reference in New Issue
Block a user