mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 19:57:46 -04:00
Added language selector to list of archives from server
Former-commit-id: 422363fa912df7e4c042cf50f8f9feb064a5b481 [formerly 719c8cc95391a7e24020186430d1537c4c8f739f] Former-commit-id: 87efce41dfcd5155118fc510fd45ba50a84c6962
This commit is contained in:
parent
65c9620db9
commit
2d052acf7e
@ -178,6 +178,7 @@
|
||||
<Content Include="www\js\lib\bootstrap.min.js" />
|
||||
<Content Include="www\js\lib\cookies.js" />
|
||||
<Content Include="www\js\lib\jquery-3.2.1.slim.js" />
|
||||
<Content Include="www\js\lib\kiwixServe.js" />
|
||||
<Content Include="www\js\lib\q.js" />
|
||||
<Content Include="www\js\lib\require.js" />
|
||||
<Content Include="www\js\lib\transformStyles.js" />
|
||||
|
Binary file not shown.
@ -32,7 +32,7 @@
|
||||
<AppXManifest Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\AppxManifest.xml">
|
||||
<PackagePath>AppxManifest.xml</PackagePath>
|
||||
<ReRegisterAppIfChanged>true</ReRegisterAppIfChanged>
|
||||
<Modified>2017-08-31T09:18:37.777</Modified>
|
||||
<Modified>2017-09-01T12:03:24.182</Modified>
|
||||
</AppXManifest>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -475,7 +475,7 @@
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\index.html">
|
||||
<PackagePath>www\index.html</PackagePath>
|
||||
<Modified>2017-08-31T09:18:23.126</Modified>
|
||||
<Modified>2017-08-31T17:39:13.678</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\favicon.ico">
|
||||
<PackagePath>www\favicon.ico</PackagePath>
|
||||
@ -603,7 +603,7 @@
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\app.js">
|
||||
<PackagePath>www\js\app.js</PackagePath>
|
||||
<Modified>2017-08-30T21:02:22.332</Modified>
|
||||
<Modified>2017-09-01T12:02:28.680</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\init.js">
|
||||
<PackagePath>www\js\init.js</PackagePath>
|
||||
@ -625,6 +625,10 @@
|
||||
<PackagePath>www\js\lib\jquery-3.2.1.slim.js</PackagePath>
|
||||
<Modified>2017-07-10T18:00:56.198</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\kiwixServe.js">
|
||||
<PackagePath>www\js\lib\kiwixServe.js</PackagePath>
|
||||
<Modified>2017-09-01T12:03:14.501</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\q.js">
|
||||
<PackagePath>www\js\lib\q.js</PackagePath>
|
||||
<Modified>2017-07-19T09:47:27.642</Modified>
|
||||
@ -635,7 +639,7 @@
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\transformStyles.js">
|
||||
<PackagePath>www\js\lib\transformStyles.js</PackagePath>
|
||||
<Modified>2017-08-29T20:22:39.602</Modified>
|
||||
<Modified>2017-09-01T11:35:16.002</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\uiUtil.js">
|
||||
<PackagePath>www\js\lib\uiUtil.js</PackagePath>
|
||||
@ -647,7 +651,7 @@
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\util.js">
|
||||
<PackagePath>www\js\lib\util.js</PackagePath>
|
||||
<Modified>2017-08-31T09:11:08.245</Modified>
|
||||
<Modified>2017-09-01T11:56:11.733</Modified>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\xzdec.js">
|
||||
<PackagePath>www\js\lib\xzdec.js</PackagePath>
|
||||
@ -1528,7 +1532,7 @@
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\ReverseMap\resources.pri">
|
||||
<PackagePath>resources.pri</PackagePath>
|
||||
<ReRegisterAppIfChanged>true</ReRegisterAppIfChanged>
|
||||
<Modified>2017-08-31T07:00:06.005</Modified>
|
||||
<Modified>2017-09-01T12:02:47.117</Modified>
|
||||
</AppxPackagedFile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -297,10 +297,11 @@
|
||||
<div class="column">
|
||||
<h3>Download links</h3>
|
||||
<p>
|
||||
<br />Files can be very large, <b>do not attempt to download over a mobile connection!</b>
|
||||
Files can be very large, <b>do not attempt to download over a mobile connection!</b>
|
||||
<br /><a id="downloadTrigger" href="#">Open full list of download links</a> : <i>Warning:</i> requires active Internet connection and will use data
|
||||
</p>
|
||||
<div id="downloadLinks" style="display: none;"></div>
|
||||
<pre id="serverResponse" class="panel-footer" style="display:none;"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -26,8 +26,8 @@
|
||||
// This uses require.js to structure javascript:
|
||||
// http://requirejs.org/docs/api.html#define
|
||||
|
||||
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFilesystemAccess', 'q', 'module', 'transformStyles'],
|
||||
function ($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess, q, module, transformStyles) {
|
||||
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFilesystemAccess', 'q', 'module', 'transformStyles', 'kiwixServe'],
|
||||
function ($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess, q, module, transformStyles, kiwixServe) {
|
||||
|
||||
/**
|
||||
* Maximum number of articles to display in a search
|
||||
@ -328,6 +328,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
|
||||
$('#articleContent').hide();
|
||||
$('#searchingForArticles').hide();
|
||||
$('#downloadLinks').hide();
|
||||
$('#serverResponse').hide();
|
||||
refreshAPIStatus();
|
||||
//If user hadn't previously picked a folder or a file, resort to the local storage folder (UWP functionality)
|
||||
if (params.localStorage && !params.pickedFolder && !params.pickedFile) {
|
||||
@ -399,7 +400,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
|
||||
}
|
||||
});
|
||||
document.getElementById('downloadTrigger').addEventListener('click', function () {
|
||||
util.requestDownloadLinks(params.kiwixDownloadLink);
|
||||
kiwixServe.requestDownloadLinks(params.kiwixDownloadLink);
|
||||
});
|
||||
|
||||
$('input:radio[name=contentInjectionMode]').on('change', function (e) {
|
||||
|
373
bin/Release/AppX/www/js/lib/kiwixServe.js
Normal file
373
bin/Release/AppX/www/js/lib/kiwixServe.js
Normal file
@ -0,0 +1,373 @@
|
||||
/**
|
||||
* languageCodes.js: Provides an object literal for looking up the English-language names of language codes
|
||||
* as defined in ISO 639-1, augmented with some ISO 639-3 codes as used by Wikipedia
|
||||
*
|
||||
* This file is part of Kiwix.
|
||||
*
|
||||
* Kiwix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
define([], function () {
|
||||
|
||||
var langCodes = {
|
||||
ab: 'Abkhazian',
|
||||
aa: 'Afar',
|
||||
af: 'Afrikaans',
|
||||
ak: 'Akan',
|
||||
sq: 'Albanian',
|
||||
am: 'Amharic',
|
||||
ar: 'Arabic',
|
||||
an: 'Aragonese',
|
||||
hy: 'Armenian',
|
||||
as: 'Assamese',
|
||||
av: 'Avaric',
|
||||
ae: 'Avestan',
|
||||
ay: 'Aymara',
|
||||
az: 'Azerbaijani',
|
||||
bm: 'Bambara',
|
||||
ba: 'Bashkir',
|
||||
eu: 'Basque',
|
||||
be: 'Belarusian',
|
||||
bn: 'Bengali (Bangla)',
|
||||
bh: 'Bihari',
|
||||
bi: 'Bislama',
|
||||
bs: 'Bosnian',
|
||||
br: 'Breton',
|
||||
bg: 'Bulgarian',
|
||||
my: 'Burmese',
|
||||
ca: 'Catalan',
|
||||
ch: 'Chamorro',
|
||||
ce: 'Chechen',
|
||||
ny: 'Chichewa-Chewa-Nyanja',
|
||||
zh: 'Chinese',
|
||||
zh: 'Chinese',
|
||||
cv: 'Chuvash',
|
||||
kw: 'Cornish',
|
||||
co: 'Corsican',
|
||||
cr: 'Cree',
|
||||
hr: 'Croatian',
|
||||
cs: 'Czech',
|
||||
da: 'Danish',
|
||||
dv: 'Divehi-Dhivehi-Maldivian',
|
||||
nl: 'Dutch',
|
||||
dz: 'Dzongkha',
|
||||
en: 'English',
|
||||
eo: 'Esperanto',
|
||||
et: 'Estonian',
|
||||
ee: 'Ewe',
|
||||
fo: 'Faroese',
|
||||
fj: 'Fijian',
|
||||
fi: 'Finnish',
|
||||
fr: 'French',
|
||||
ff: 'Fula-Fulah-Pulaar-Pular',
|
||||
gl: 'Galician',
|
||||
gd: 'Gaelic (Scottish)',
|
||||
gv: 'Gaelic (Manx)',
|
||||
ka: 'Georgian',
|
||||
de: 'German',
|
||||
el: 'Greek',
|
||||
kl: 'Greenlandic-Kalaallisut',
|
||||
gn: 'Guarani',
|
||||
gu: 'Gujarati',
|
||||
ht: 'Haitian Creole',
|
||||
ha: 'Hausa',
|
||||
he: 'Hebrew',
|
||||
hz: 'Herero',
|
||||
hi: 'Hindi',
|
||||
ho: 'Hiri Motu',
|
||||
hu: 'Hungarian',
|
||||
is: 'Icelandic',
|
||||
io: 'Ido',
|
||||
ig: 'Igbo',
|
||||
id: 'Indonesian',
|
||||
in: 'Indonesian',
|
||||
ia: 'Interlingua',
|
||||
ie: 'Interlingue',
|
||||
iu: 'Inuktitut',
|
||||
ik: 'Inupiak',
|
||||
ga: 'Irish',
|
||||
it: 'Italian',
|
||||
ja: 'Japanese',
|
||||
jv: 'Javanese',
|
||||
kn: 'Kannada',
|
||||
kr: 'Kanuri',
|
||||
ks: 'Kashmiri',
|
||||
kk: 'Kazakh',
|
||||
km: 'Khmer',
|
||||
ki: 'Kikuyu',
|
||||
rw: 'Kinyarwanda (Rwanda)',
|
||||
rn: 'Kirundi',
|
||||
ky: 'Kyrgyz',
|
||||
kv: 'Komi',
|
||||
kg: 'Kongo',
|
||||
ko: 'Korean',
|
||||
ku: 'Kurdish',
|
||||
kj: 'Kwanyama',
|
||||
lo: 'Lao',
|
||||
la: 'Latin',
|
||||
lv: 'Latvian (Lettish)',
|
||||
li: 'Limburgish ( Limburger)',
|
||||
ln: 'Lingala',
|
||||
lt: 'Lithuanian',
|
||||
lu: 'Luga-Katanga',
|
||||
lg: 'Luganda-Ganda',
|
||||
lb: 'Luxembourgish',
|
||||
mk: 'Macedonian',
|
||||
mg: 'Malagasy',
|
||||
ms: 'Malay',
|
||||
ml: 'Malayalam',
|
||||
mt: 'Maltese',
|
||||
mi: 'Maori',
|
||||
mr: 'Marathi',
|
||||
mh: 'Marshallese',
|
||||
mo: 'Moldavian',
|
||||
mn: 'Mongolian',
|
||||
na: 'Nauru',
|
||||
nv: 'Navajo',
|
||||
ng: 'Ndonga',
|
||||
nd: 'Northern Ndebele',
|
||||
ne: 'Nepali',
|
||||
no: 'Norwegian',
|
||||
nb: 'Norwegian bokmål',
|
||||
nn: 'Norwegian nynorsk',
|
||||
ii: 'Nuosu (Sichuan Yi)',
|
||||
oc: 'Occitan',
|
||||
oj: 'Ojibwe',
|
||||
cu: 'Old Church Slavonic-Old Bulgarian',
|
||||
or: 'Oriya',
|
||||
om: 'Oromo (Afaan Oromo)',
|
||||
os: 'Ossetian',
|
||||
pi: 'Pāli',
|
||||
ps: 'Pashto-Pushto',
|
||||
fa: 'Persian (Farsi)',
|
||||
pl: 'Polish',
|
||||
pt: 'Portuguese',
|
||||
pa: 'Punjabi (Eastern)',
|
||||
qu: 'Quechua',
|
||||
rm: 'Romansh',
|
||||
ro: 'Romanian',
|
||||
ru: 'Russian',
|
||||
se: 'Sami',
|
||||
sm: 'Samoan',
|
||||
sg: 'Sango',
|
||||
sa: 'Sanskrit',
|
||||
sr: 'Serbian',
|
||||
sh: 'Serbo-Croatian',
|
||||
st: 'Sesotho',
|
||||
tn: 'Setswana',
|
||||
sn: 'Shona',
|
||||
sd: 'Sindhi',
|
||||
si: 'Sinhalese',
|
||||
ss: 'Siswati',
|
||||
sk: 'Slovak',
|
||||
sl: 'Slovenian',
|
||||
so: 'Somali',
|
||||
nr: 'Southern Ndebele',
|
||||
es: 'Spanish',
|
||||
su: 'Sundanese',
|
||||
sw: 'Swahili (Kiswahili)',
|
||||
sv: 'Swedish',
|
||||
tl: 'Tagalog',
|
||||
ty: 'Tahitian',
|
||||
tg: 'Tajik',
|
||||
ta: 'Tamil',
|
||||
tt: 'Tatar',
|
||||
te: 'Telugu',
|
||||
th: 'Thai',
|
||||
bo: 'Tibetan',
|
||||
ti: 'Tigrinya',
|
||||
to: 'Tonga',
|
||||
ts: 'Tsonga',
|
||||
tr: 'Turkish',
|
||||
tk: 'Turkmen',
|
||||
tum: 'Tumbuka',
|
||||
tw: 'Twi',
|
||||
ug: 'Uyghur',
|
||||
uk: 'Ukrainian',
|
||||
ur: 'Urdu',
|
||||
uz: 'Uzbek',
|
||||
ve: 'Venda',
|
||||
vi: 'Vietnamese',
|
||||
vo: 'Volapük',
|
||||
wa: 'Wallon',
|
||||
cy: 'Welsh',
|
||||
wo: 'Wolof',
|
||||
fy: 'Western Frisian',
|
||||
xh: 'Xhosa',
|
||||
yi: 'Yiddish',
|
||||
ji: 'Yiddish',
|
||||
yo: 'Yoruba',
|
||||
za: 'Zhuang-Chuang',
|
||||
zu: 'Zulu'
|
||||
};
|
||||
|
||||
function requestDownloadLinks(URL, lang) {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
var downloadLinks = document.getElementById('downloadLinks');
|
||||
var serverResponse = document.getElementById('serverResponse');
|
||||
serverResponse.innerHTML = "Server response: Waiting...";
|
||||
serverResponse.style.display = "inline";
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
serverResponse.innerHTML = "Server response: 200 OK (data received)";
|
||||
var doc = this.responseText;
|
||||
if (/\.meta4$/i.test(URL)) {
|
||||
//It's the metalink with download links
|
||||
var linkArray = doc.match(/<url\b[^>]*>[^<]*<\/url>/ig);
|
||||
var size = doc.match(/<size>(\d+)<\/size>/i);
|
||||
//Filter value (add commas if required)
|
||||
size = size.length ? size[1] : "";
|
||||
var megabytes = size ? Math.round(size * 10 / (1024 * 1024)) / 10 : size;
|
||||
//Use the lookbehind reversal trick to add commas....
|
||||
size = size.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
var megabytes$ = megabytes.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
doc = "";
|
||||
//NB we'ere intentionally discarding first link to kiwix.org (not to zim)
|
||||
var mirrorservice = false;
|
||||
for (var i = 1; i < linkArray.length; i++) {
|
||||
if (/mirrorservice\.org/i.test(linkArray[i])) {
|
||||
mirrorservice = true;
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li>*** Server has download bug, see note ***<br />$1</li>\r\n');
|
||||
} else {
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li><a href="$1" target="_blank">$1</a></li>\r\n');
|
||||
}
|
||||
}
|
||||
var headerDoc = 'We found the following links to your file:';
|
||||
var bodyDoc = "<h5";
|
||||
bodyDoc += megabytes > 200 ? ' style="color:red;"> WARNING: ' : '>';
|
||||
bodyDoc += 'File size is <b>' + (megabytes ? megabytes$ + 'MB' : 'unnown') + '</b>' + (size ? ' (' + size + ' bytes)' : '') + '</h5>\r\n';
|
||||
if (megabytes > 4000) bodyDoc += '<p style="color:red;">This file is larger than the maximum file size permitted on an SD card formatted as FAT32 (max size is approx. 4GB). If your card or other storage area is formatted in this way, you will need to download a split version of this file: see <a href="http://wiki.kiwix.org/wiki/FAQ/en">Frequently Asked Questions</a>.</p>\r\n';
|
||||
if (megabytes > 200) bodyDoc += '<p><b>Consider using a torrent download method: see <a href="#" onclick="$(\'#btnAbout\').click();">About</a> section</b></p>\r\n';
|
||||
bodyDoc += '<p><i>Links will open in a new browser window</i></p><ol>\r\n' + doc + '</ol>\r\n';
|
||||
if (mirrorservice) bodyDoc += '*** Note: mirrorservice.org currently has a download bug with ZIM archives: on some browsers it will download the ZIM file as plain text in browser window<br /><br />';
|
||||
bodyDoc += '<a id="returnLink" href="#" data-kiwix-dl="' + URL.replace(/\/[^\/]*\.meta4$/i, "\/") + '"><< Back to list of files</a><br /><br />';
|
||||
var header = document.getElementById('dl-panel-heading');
|
||||
header.outerHTML = header.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + headerDoc + '</div>');
|
||||
var body = document.getElementById('dl-panel-body');
|
||||
body.outerHTML = body.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + bodyDoc + '</div>');
|
||||
downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/Index\s+of/ig, "File in");
|
||||
if (megabytes > 4000) downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/panel-success/i, "panel-danger");
|
||||
if (megabytes > 200) downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/panel-success/i, "panel-warning");
|
||||
var langSel = document.getElementById("langs");
|
||||
//Set chosen value in language selector (really this is for return)
|
||||
if (langSel) {
|
||||
langs.value = lang;
|
||||
}
|
||||
//Add event listener for click on return link, to go back to list of archives
|
||||
document.getElementById('returnLink').addEventListener('click', function (e) {
|
||||
var langSel = document.getElementById("langs");
|
||||
//var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langID = langSel ? langs.value : "";
|
||||
langID = langID == "All" ? "" : langID;
|
||||
requestDownloadLinks(this.dataset.kiwixDl, langID);
|
||||
});
|
||||
return;
|
||||
}
|
||||
//Remove images
|
||||
var doc = doc.replace(/<img\b[^>]*>\s*/ig, "");
|
||||
//Reduce size of header
|
||||
doc = doc.replace(/<h1\b([^>]*>[^<]*<\/)h1>/ig, "<h3$1h3>");
|
||||
//Limit height of pre box and prevent word wrapping
|
||||
doc = doc.replace(/<pre>/i, '<div class="panel panel-success">\r\n' +
|
||||
'<pre id="dl-panel-heading" class="panel-heading" style="overflow-x: hidden; word-wrap: normal;">$#$#</pre>\r\n' +
|
||||
'<pre id="dl-panel-body" class="panel panel-body" style="max-height:360px; word-wrap:normal; margin-bottom:10px; overflow: auto;">');
|
||||
//Remove hr at end of page and add extra </div>
|
||||
doc = doc.replace(/<hr\b[^>]*>(\s*<\/pre>)/i, "$1</div>");
|
||||
//Move header into panel-header (NB regex is deliberately redundant to increase specificity of search)
|
||||
doc = doc.replace(/\$\#\$\#([\s\S]+?)(<a\s+href[^>]+>name<[\s\S]+?last\s+modified<[\s\S]+?)<hr>\s*/i, "$2$1");
|
||||
if (/\dK|\dM|\dG/.test(doc)) {
|
||||
//Swap size and date fields to make file size more prominent on narrow screens
|
||||
doc = doc.replace(/(<a\b[^>]*>last\s+modified<\/a>\s*)(<a\b[^>]*>size<\/a>\s*)/ig, "$2$1");
|
||||
doc = doc.replace(/(\d\d-\w{3}-\d{4}\s\d\d\:\d\d\s+)(\d[\d.\w]+\s+)$/img, "$2$1");
|
||||
}
|
||||
if (/^[^_\n\r]+_([^_]+)_.+\.zim.+$/m.test(doc)) {
|
||||
//Delete all lines without a wiki pattern from language list
|
||||
var langList = doc.replace(/^(?![^_\n\r]+_(\w+)_.+$).*[\r\n]*/mg, "");
|
||||
//Get list of all languages
|
||||
langList = langList.replace(/^[^_]+_([^_]+)_.+$/mg, "$1");
|
||||
//Delete recurrences
|
||||
langList = langList.replace(/\b(\w+)\n(?=.*\b\1\n?)/mg, "");
|
||||
langList = "All\n" + langList;
|
||||
var langArray = langList.match(/^\w+$/mg);
|
||||
if (langArray) {
|
||||
var dropdown = '<select id="langs">\r\n';
|
||||
for (var q = 0; q < langArray.length; q++) {
|
||||
dropdown += '<option value="' + langArray[q] + '">' + langArray[q] + '</option>\r\n';
|
||||
}
|
||||
dropdown += '</select>\r\n';
|
||||
doc = doc.replace(/<\/h3>/i, '</h3><p>Filter list by language code: ' + dropdown + '</p>');
|
||||
}
|
||||
//Add language spans to doc
|
||||
doc = doc.replace(/^([^_\n\r]+_([^_]+)_.+\.zim.+)$[\n\r]*/img, '<span class="wikiLang" lang="$2">$1<br /></span>');
|
||||
}
|
||||
downloadLinks.innerHTML = doc;
|
||||
if (lang) {
|
||||
var langEntries = document.querySelectorAll(".wikiLang");
|
||||
//Hide all entries except specified language
|
||||
for (i = 0; i < langEntries.length; i++) {
|
||||
if (langEntries[i].lang != lang) langEntries[i].style.display = "none";
|
||||
}
|
||||
var langSel = document.getElementById("langs");
|
||||
if (langSel) {
|
||||
//var match = false;
|
||||
//for (var i = 0; i = langSel.options.length; i++) {
|
||||
// if (langSel.options[i].value == lang) { match = true; break; }
|
||||
//}
|
||||
//if (match) langSel.options[i]
|
||||
langs.value = lang;
|
||||
}
|
||||
}
|
||||
if (typeof langArray !== "undefined") {
|
||||
//Set up event listener for language selector
|
||||
document.getElementById("langs").addEventListener("change", function () {
|
||||
var langSel = document.getElementById("langs");
|
||||
var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langEntries = document.querySelectorAll(".wikiLang");
|
||||
//Hide all entries except specified language
|
||||
for (i = 0; i < langEntries.length; i++) {
|
||||
if (langEntries[i].lang == langID || langID == "All") langEntries[i].style.display = "inline";
|
||||
if (langEntries[i].lang != langID && langID != "All") langEntries[i].style.display = "none";
|
||||
}
|
||||
});
|
||||
}
|
||||
var links = downloadLinks.getElementsByTagName("a");
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
//Store the href - seems it's not useful?
|
||||
//links[i].setAttribute("data-kiwix-dl", links[i].href);
|
||||
links[i].href = "#";
|
||||
links[i].addEventListener('click', function () {
|
||||
var langSel = document.getElementById("langs");
|
||||
//var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langID = langSel ? langs.value : "";
|
||||
var replaceURL = URL + this.text;
|
||||
if (/\.zim$/i.test(this.text))
|
||||
replaceURL = replaceURL + ".meta4";
|
||||
if (/parent\s*directory/i.test(this.text))
|
||||
replaceURL = URL.replace(/\/[^\/]*\/$/i, "\/");
|
||||
requestDownloadLinks(replaceURL, langID);
|
||||
});
|
||||
}
|
||||
//Toggle display of download panel -- bug: causes whole div to close if clicking on a link...
|
||||
//downloadLinks.style.display = downloadLinks.style.display == "none" ? "inline" : "none";
|
||||
downloadLinks.style.display = "inline";
|
||||
} else {
|
||||
serverResponse.innerHTML += ".";
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", URL, true);
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
*/
|
||||
return {
|
||||
langCodes: langCodes,
|
||||
requestDownloadLinks: requestDownloadLinks
|
||||
};
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* transformCSS.js: Provides transformations in CSS of Wikipedia articles contained in the ZIM file
|
||||
* transformStyles.js: Provides transformations in CSS of Wikipedia articles contained in the ZIM file
|
||||
* This allows the user to choose the presentation style for the page to be viewed.
|
||||
* Currently available are "mobile" and "desktop" display modes.
|
||||
*
|
||||
@ -122,7 +122,7 @@ define(['util', 'uiUtil'], function (util, uiUtil) {
|
||||
if (paras.length) {
|
||||
for (var g = 0; g < 3; g++) {
|
||||
//Check if the paragraph is a proper sentence, i.e. contains at least 50 non-HTML-delimetered non-full-stop characters, followed by a punctuation character
|
||||
if (/[^.]{50,}[^.]*[.,;:?!-]/.test(paras[g].replace(/<[^>]*>/g, ""))) { matched = true; break; }
|
||||
if (paras[g] && /[^.]{50,}[^.]*[.,;:?!-]/.test(paras[g].replace(/<[^>]*>/g, ""))) { matched = true; break; }
|
||||
}
|
||||
if (matched) {
|
||||
//Swap table and first matched paragraph, but mark lead paragraph first
|
||||
|
@ -694,84 +694,6 @@ define(['q'], function(q) {
|
||||
|
||||
}
|
||||
|
||||
function requestDownloadLinks(URL) {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var doc = this.responseText;
|
||||
var downloadLinks = document.getElementById('downloadLinks');
|
||||
if (/\.meta4$/i.test(URL)) {
|
||||
//It's the metalink with download links
|
||||
var linkArray = doc.match(/<url\b[^>]*>[^<]*<\/url>/ig);
|
||||
var size = doc.match(/<size>(\d+)<\/size>/i);
|
||||
//Filter value (add commas if required)
|
||||
size = size.length ? size[1] : "";
|
||||
var megabytes = size ? Math.round(size * 10 / (1024 * 1024)) / 10 : size;
|
||||
//Use the lookbehind reversal trick to add commas....
|
||||
size = size.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
doc = "";
|
||||
//NB we'ere intentionally discarding first link to kiwix.org (not to zim)
|
||||
var mirrorservice = false;
|
||||
for (var i = 1; i < linkArray.length; i++) {
|
||||
if (/mirrorservice\.org/i.test(linkArray[i])) {
|
||||
mirrorservice = true;
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li>*** Server has download bug, see note ***<br />$1</li>\r\n');
|
||||
} else {
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li><a href="$1" target="_blank">$1</a></li>\r\n');
|
||||
}
|
||||
}
|
||||
var fullDoc = '<div class="panel panel-body" style="overflow-y: auto;">\r\n<h4>We found the following links to your file</h4>\r\n<h5';
|
||||
if (megabytes > 200) fullDoc += ' style="color:red;"';
|
||||
fullDoc += '>WARNING: file size is <b>' + (megabytes ? megabytes + 'Mb' : 'unnown') + '</b>' + (size ? ' (' + size + ' bytes)' : '') + '</h5>\r\n';
|
||||
if (megabytes > 200) fullDoc += '<b>Consider using a torrent download method: see <a href="#" onclick="$(\'#btnAbout\').click();">About</a> section</b>\r\n';
|
||||
fullDoc += '<p><i>Links will open in a new browser window</i></p><ol>\r\n' + doc + '</ol>\r\n';
|
||||
if (mirrorservice) fullDoc += '*** Note: mirrorservice.org currently has a download bug with ZIM archives: on some browsers it will download the ZIM file as plain text in browser window<br /><br />';
|
||||
fullDoc += '<a id="returnLink" href="#" data-kiwix-dl="' + URL.replace(/\/[^\/]*\.meta4$/i, "\/") +'"><< Back to list of files</a></pre>';
|
||||
downloadLinks.innerHTML = fullDoc;
|
||||
document.getElementById('returnLink').addEventListener('click', function (e) {
|
||||
requestDownloadLinks(this.dataset.kiwixDl);
|
||||
});
|
||||
return;
|
||||
}
|
||||
//Remove images
|
||||
var doc = doc.replace(/<img\b[^>]*>\s*/ig, "");
|
||||
//Reduce size of header
|
||||
doc = doc.replace(/<h1\b([^>]*>[^<]*<\/)h1>/ig, "<h3$1h3>");
|
||||
//Limit height of pre box and prevent word wrapping
|
||||
doc = doc.replace(/<pre>/i, '<div class="panel panel-success"><pre class="panel-heading" style="overflow-x: hidden; word-wrap: normal;">$#$#</pre>\r\n<pre class="panel panel-body" style="max-height:360px; word-wrap:normal; margin-bottom:10px;">');
|
||||
//Remove hr at end of page and add extra </div>
|
||||
doc = doc.replace(/<hr\b[^>]*>(\s*<\/pre>)/i, "$1</div>");
|
||||
//Move header into panel-header (NB regex is deliberately redundant to increase specificity of search)
|
||||
doc = doc.replace(/\$\#\$\#([\s\S]+?)(<a\s+href[^>]+>name<[\s\S]+?last\s+modified<[\s\S]+?)<hr>\s*/i, "$2$1");
|
||||
if (/\dK|\dM|\dG/.test(doc)) {
|
||||
//Swap size and date fields to make file size more prominent on narrow screens
|
||||
doc = doc.replace(/(<a\b[^>]*>last\s+modified<\/a>)(\s+)(<a\b[^>]*>size<\/a>)/ig, "$3$2$1");
|
||||
doc = doc.replace(/(\d\d-\w{3}-\d{4}\s\d\d\:\d\d)(\s+)(\d[\d.\w]+)\s+$/img, "$3$2$1");
|
||||
}
|
||||
downloadLinks.innerHTML = doc;
|
||||
var links = downloadLinks.getElementsByTagName("a");
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
//Store the href - seems it's not useful?
|
||||
//links[i].setAttribute("data-kiwix-dl", links[i].href);
|
||||
links[i].href = "#";
|
||||
links[i].addEventListener('click', function (e) {
|
||||
var replaceURL = URL + this.text;
|
||||
if (/\.zim$/i.test(this.text))
|
||||
replaceURL = replaceURL + ".meta4";
|
||||
if (/parent\s*directory/i.test(this.text))
|
||||
replaceURL = URL.replace(/\/[^\/]*\/$/i, "\/");
|
||||
requestDownloadLinks(replaceURL);
|
||||
});
|
||||
}
|
||||
//Toggle display of download panel -- bug: causes whole div to close if clicking on a link...
|
||||
//downloadLinks.style.display = downloadLinks.style.display == "none" ? "inline" : "none";
|
||||
downloadLinks.style.display = "inline";
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", URL, true);
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
@ -795,7 +717,6 @@ define(['q'], function(q) {
|
||||
leftShift: leftShift,
|
||||
matchOuter: matchOuter,
|
||||
matchInner: matchInner,
|
||||
Hilitor: Hilitor,
|
||||
requestDownloadLinks: requestDownloadLinks
|
||||
Hilitor: Hilitor
|
||||
};
|
||||
});
|
||||
|
@ -478,6 +478,9 @@
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\jquery-3.2.1.slim.js">
|
||||
<PackagePath>www\js\lib\jquery-3.2.1.slim.js</PackagePath>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\kiwixServe.js">
|
||||
<PackagePath>www\js\lib\kiwixServe.js</PackagePath>
|
||||
</AppxPackagedFile>
|
||||
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\q.js">
|
||||
<PackagePath>www\js\lib\q.js</PackagePath>
|
||||
</AppxPackagedFile>
|
||||
|
Binary file not shown.
@ -112,6 +112,7 @@ www\js\lib\abstractFilesystemAccess.js
|
||||
www\js\lib\bootstrap.min.js
|
||||
www\js\lib\cookies.js
|
||||
www\js\lib\jquery-3.2.1.slim.js
|
||||
www\js\lib\kiwixServe.js
|
||||
www\js\lib\q.js
|
||||
www\js\lib\require.js
|
||||
www\js\lib\transformStyles.js
|
||||
|
@ -112,6 +112,7 @@ www\js\lib\abstractFilesystemAccess.js
|
||||
www\js\lib\bootstrap.min.js
|
||||
www\js\lib\cookies.js
|
||||
www\js\lib\jquery-3.2.1.slim.js
|
||||
www\js\lib\kiwixServe.js
|
||||
www\js\lib\q.js
|
||||
www\js\lib\require.js
|
||||
www\js\lib\transformStyles.js
|
||||
|
@ -301,6 +301,7 @@
|
||||
<br /><a id="downloadTrigger" href="#">Open full list of download links</a> : <i>Warning:</i> requires active Internet connection and will use data
|
||||
</p>
|
||||
<div id="downloadLinks" style="display: none;"></div>
|
||||
<pre id="serverResponse" class="panel-footer" style="display:none;"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -26,8 +26,8 @@
|
||||
// This uses require.js to structure javascript:
|
||||
// http://requirejs.org/docs/api.html#define
|
||||
|
||||
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFilesystemAccess', 'q', 'module', 'transformStyles'],
|
||||
function ($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess, q, module, transformStyles) {
|
||||
define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFilesystemAccess', 'q', 'module', 'transformStyles', 'kiwixServe'],
|
||||
function ($, zimArchiveLoader, util, uiUtil, cookies, abstractFilesystemAccess, q, module, transformStyles, kiwixServe) {
|
||||
|
||||
/**
|
||||
* Maximum number of articles to display in a search
|
||||
@ -328,6 +328,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
|
||||
$('#articleContent').hide();
|
||||
$('#searchingForArticles').hide();
|
||||
$('#downloadLinks').hide();
|
||||
$('#serverResponse').hide();
|
||||
refreshAPIStatus();
|
||||
//If user hadn't previously picked a folder or a file, resort to the local storage folder (UWP functionality)
|
||||
if (params.localStorage && !params.pickedFolder && !params.pickedFile) {
|
||||
@ -399,7 +400,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
|
||||
}
|
||||
});
|
||||
document.getElementById('downloadTrigger').addEventListener('click', function () {
|
||||
util.requestDownloadLinks(params.kiwixDownloadLink);
|
||||
kiwixServe.requestDownloadLinks(params.kiwixDownloadLink);
|
||||
});
|
||||
|
||||
$('input:radio[name=contentInjectionMode]').on('change', function (e) {
|
||||
|
379
www/js/lib/kiwixServe.js
Normal file
379
www/js/lib/kiwixServe.js
Normal file
@ -0,0 +1,379 @@
|
||||
/**
|
||||
* kiwixServe.js: Provides an AJAX request process for contacting the Kiwix Download Server
|
||||
* and manipulating the returned data for display in-app
|
||||
* Also provides an object literal (langCodes) for looking up the English-language names of
|
||||
* language codesas defined in ISO 639-1, augmented with some ISO 639-3 codes as used by the
|
||||
* Kiwix server
|
||||
*
|
||||
* Copyright 2018 Jaifroid and contributors
|
||||
* License GPL v3:
|
||||
*
|
||||
* This file is part of Kiwix.
|
||||
*
|
||||
* Kiwix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
define([], function () {
|
||||
|
||||
var langCodes = {
|
||||
ab: 'Abkhazian',
|
||||
aa: 'Afar',
|
||||
af: 'Afrikaans',
|
||||
ak: 'Akan',
|
||||
sq: 'Albanian',
|
||||
am: 'Amharic',
|
||||
ar: 'Arabic',
|
||||
an: 'Aragonese',
|
||||
hy: 'Armenian',
|
||||
as: 'Assamese',
|
||||
av: 'Avaric',
|
||||
ae: 'Avestan',
|
||||
ay: 'Aymara',
|
||||
az: 'Azerbaijani',
|
||||
bm: 'Bambara',
|
||||
ba: 'Bashkir',
|
||||
eu: 'Basque',
|
||||
be: 'Belarusian',
|
||||
bn: 'Bengali (Bangla)',
|
||||
bh: 'Bihari',
|
||||
bi: 'Bislama',
|
||||
bs: 'Bosnian',
|
||||
br: 'Breton',
|
||||
bg: 'Bulgarian',
|
||||
my: 'Burmese',
|
||||
ca: 'Catalan',
|
||||
ch: 'Chamorro',
|
||||
ce: 'Chechen',
|
||||
ny: 'Chichewa-Chewa-Nyanja',
|
||||
zh: 'Chinese',
|
||||
zh: 'Chinese',
|
||||
cv: 'Chuvash',
|
||||
kw: 'Cornish',
|
||||
co: 'Corsican',
|
||||
cr: 'Cree',
|
||||
hr: 'Croatian',
|
||||
cs: 'Czech',
|
||||
da: 'Danish',
|
||||
dv: 'Divehi-Dhivehi-Maldivian',
|
||||
nl: 'Dutch',
|
||||
dz: 'Dzongkha',
|
||||
en: 'English',
|
||||
eo: 'Esperanto',
|
||||
et: 'Estonian',
|
||||
ee: 'Ewe',
|
||||
fo: 'Faroese',
|
||||
fj: 'Fijian',
|
||||
fi: 'Finnish',
|
||||
fr: 'French',
|
||||
ff: 'Fula-Fulah-Pulaar-Pular',
|
||||
gl: 'Galician',
|
||||
gd: 'Gaelic (Scottish)',
|
||||
gv: 'Gaelic (Manx)',
|
||||
ka: 'Georgian',
|
||||
de: 'German',
|
||||
el: 'Greek',
|
||||
kl: 'Greenlandic-Kalaallisut',
|
||||
gn: 'Guarani',
|
||||
gu: 'Gujarati',
|
||||
ht: 'Haitian Creole',
|
||||
ha: 'Hausa',
|
||||
he: 'Hebrew',
|
||||
hz: 'Herero',
|
||||
hi: 'Hindi',
|
||||
ho: 'Hiri Motu',
|
||||
hu: 'Hungarian',
|
||||
is: 'Icelandic',
|
||||
io: 'Ido',
|
||||
ig: 'Igbo',
|
||||
id: 'Indonesian',
|
||||
in: 'Indonesian',
|
||||
ia: 'Interlingua',
|
||||
ie: 'Interlingue',
|
||||
iu: 'Inuktitut',
|
||||
ik: 'Inupiak',
|
||||
ga: 'Irish',
|
||||
it: 'Italian',
|
||||
ja: 'Japanese',
|
||||
jv: 'Javanese',
|
||||
kn: 'Kannada',
|
||||
kr: 'Kanuri',
|
||||
ks: 'Kashmiri',
|
||||
kk: 'Kazakh',
|
||||
km: 'Khmer',
|
||||
ki: 'Kikuyu',
|
||||
rw: 'Kinyarwanda (Rwanda)',
|
||||
rn: 'Kirundi',
|
||||
ky: 'Kyrgyz',
|
||||
kv: 'Komi',
|
||||
kg: 'Kongo',
|
||||
ko: 'Korean',
|
||||
ku: 'Kurdish',
|
||||
kj: 'Kwanyama',
|
||||
lo: 'Lao',
|
||||
la: 'Latin',
|
||||
lv: 'Latvian (Lettish)',
|
||||
li: 'Limburgish ( Limburger)',
|
||||
ln: 'Lingala',
|
||||
lt: 'Lithuanian',
|
||||
lu: 'Luga-Katanga',
|
||||
lg: 'Luganda-Ganda',
|
||||
lb: 'Luxembourgish',
|
||||
mk: 'Macedonian',
|
||||
mg: 'Malagasy',
|
||||
ms: 'Malay',
|
||||
ml: 'Malayalam',
|
||||
mt: 'Maltese',
|
||||
mi: 'Maori',
|
||||
mr: 'Marathi',
|
||||
mh: 'Marshallese',
|
||||
mo: 'Moldavian',
|
||||
mn: 'Mongolian',
|
||||
na: 'Nauru',
|
||||
nv: 'Navajo',
|
||||
ng: 'Ndonga',
|
||||
nd: 'Northern Ndebele',
|
||||
ne: 'Nepali',
|
||||
no: 'Norwegian',
|
||||
nb: 'Norwegian bokmål',
|
||||
nn: 'Norwegian nynorsk',
|
||||
ii: 'Nuosu (Sichuan Yi)',
|
||||
oc: 'Occitan',
|
||||
oj: 'Ojibwe',
|
||||
cu: 'Old Church Slavonic-Old Bulgarian',
|
||||
or: 'Oriya',
|
||||
om: 'Oromo (Afaan Oromo)',
|
||||
os: 'Ossetian',
|
||||
pi: 'Pāli',
|
||||
ps: 'Pashto-Pushto',
|
||||
fa: 'Persian (Farsi)',
|
||||
pl: 'Polish',
|
||||
pt: 'Portuguese',
|
||||
pa: 'Punjabi (Eastern)',
|
||||
qu: 'Quechua',
|
||||
rm: 'Romansh',
|
||||
ro: 'Romanian',
|
||||
ru: 'Russian',
|
||||
se: 'Sami',
|
||||
sm: 'Samoan',
|
||||
sg: 'Sango',
|
||||
sa: 'Sanskrit',
|
||||
sr: 'Serbian',
|
||||
sh: 'Serbo-Croatian',
|
||||
st: 'Sesotho',
|
||||
tn: 'Setswana',
|
||||
sn: 'Shona',
|
||||
sd: 'Sindhi',
|
||||
si: 'Sinhalese',
|
||||
ss: 'Siswati',
|
||||
sk: 'Slovak',
|
||||
sl: 'Slovenian',
|
||||
so: 'Somali',
|
||||
nr: 'Southern Ndebele',
|
||||
es: 'Spanish',
|
||||
su: 'Sundanese',
|
||||
sw: 'Swahili (Kiswahili)',
|
||||
sv: 'Swedish',
|
||||
tl: 'Tagalog',
|
||||
ty: 'Tahitian',
|
||||
tg: 'Tajik',
|
||||
ta: 'Tamil',
|
||||
tt: 'Tatar',
|
||||
te: 'Telugu',
|
||||
th: 'Thai',
|
||||
bo: 'Tibetan',
|
||||
ti: 'Tigrinya',
|
||||
to: 'Tonga',
|
||||
ts: 'Tsonga',
|
||||
tr: 'Turkish',
|
||||
tk: 'Turkmen',
|
||||
tum: 'Tumbuka',
|
||||
tw: 'Twi',
|
||||
ug: 'Uyghur',
|
||||
uk: 'Ukrainian',
|
||||
ur: 'Urdu',
|
||||
uz: 'Uzbek',
|
||||
ve: 'Venda',
|
||||
vi: 'Vietnamese',
|
||||
vo: 'Volapük',
|
||||
wa: 'Wallon',
|
||||
cy: 'Welsh',
|
||||
wo: 'Wolof',
|
||||
fy: 'Western Frisian',
|
||||
xh: 'Xhosa',
|
||||
yi: 'Yiddish',
|
||||
ji: 'Yiddish',
|
||||
yo: 'Yoruba',
|
||||
za: 'Zhuang-Chuang',
|
||||
zu: 'Zulu'
|
||||
};
|
||||
|
||||
function requestDownloadLinks(URL, lang) {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
var downloadLinks = document.getElementById('downloadLinks');
|
||||
var serverResponse = document.getElementById('serverResponse');
|
||||
serverResponse.innerHTML = "Server response: Waiting...";
|
||||
serverResponse.style.display = "inline";
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
serverResponse.innerHTML = "Server response: 200 OK (data received)";
|
||||
var doc = this.responseText;
|
||||
if (/\.meta4$/i.test(URL)) {
|
||||
//It's the metalink with download links
|
||||
var linkArray = doc.match(/<url\b[^>]*>[^<]*<\/url>/ig);
|
||||
var size = doc.match(/<size>(\d+)<\/size>/i);
|
||||
//Filter value (add commas if required)
|
||||
size = size.length ? size[1] : "";
|
||||
var megabytes = size ? Math.round(size * 10 / (1024 * 1024)) / 10 : size;
|
||||
//Use the lookbehind reversal trick to add commas....
|
||||
size = size.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
var megabytes$ = megabytes.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
doc = "";
|
||||
//NB we'ere intentionally discarding first link to kiwix.org (not to zim)
|
||||
var mirrorservice = false;
|
||||
for (var i = 1; i < linkArray.length; i++) {
|
||||
if (/mirrorservice\.org/i.test(linkArray[i])) {
|
||||
mirrorservice = true;
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li>*** Server has download bug, see note ***<br />$1</li>\r\n');
|
||||
} else {
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li><a href="$1" target="_blank">$1</a></li>\r\n');
|
||||
}
|
||||
}
|
||||
var headerDoc = 'We found the following links to your file:';
|
||||
var bodyDoc = "<h5";
|
||||
bodyDoc += megabytes > 200 ? ' style="color:red;"> WARNING: ' : '>';
|
||||
bodyDoc += 'File size is <b>' + (megabytes ? megabytes$ + 'MB' : 'unnown') + '</b>' + (size ? ' (' + size + ' bytes)' : '') + '</h5>\r\n';
|
||||
if (megabytes > 4000) bodyDoc += '<p style="color:red;">This file is larger than the maximum file size permitted on an SD card formatted as FAT32 (max size is approx. 4GB). If your card or other storage area is formatted in this way, you will need to download a split version of this file: see <a href="http://wiki.kiwix.org/wiki/FAQ/en">Frequently Asked Questions</a>.</p>\r\n';
|
||||
if (megabytes > 200) bodyDoc += '<p><b>Consider using a torrent download method: see <a href="#" onclick="$(\'#btnAbout\').click();">About</a> section</b></p>\r\n';
|
||||
bodyDoc += '<p><i>Links will open in a new browser window</i></p><ol>\r\n' + doc + '</ol>\r\n';
|
||||
if (mirrorservice) bodyDoc += '*** Note: mirrorservice.org currently has a download bug with ZIM archives: on some browsers it will download the ZIM file as plain text in browser window<br /><br />';
|
||||
bodyDoc += '<a id="returnLink" href="#" data-kiwix-dl="' + URL.replace(/\/[^\/]*\.meta4$/i, "\/") + '"><< Back to list of files</a><br /><br />';
|
||||
var header = document.getElementById('dl-panel-heading');
|
||||
header.outerHTML = header.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + headerDoc + '</div>');
|
||||
var body = document.getElementById('dl-panel-body');
|
||||
body.outerHTML = body.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + bodyDoc + '</div>');
|
||||
downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/Index\s+of/ig, "File in");
|
||||
if (megabytes > 4000) downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/panel-success/i, "panel-danger");
|
||||
if (megabytes > 200) downloadLinks.innerHTML = downloadLinks.innerHTML.replace(/panel-success/i, "panel-warning");
|
||||
var langSel = document.getElementById("langs");
|
||||
//Set chosen value in language selector (really this is for return)
|
||||
if (langSel) {
|
||||
langs.value = lang;
|
||||
}
|
||||
//Add event listener for click on return link, to go back to list of archives
|
||||
document.getElementById('returnLink').addEventListener('click', function (e) {
|
||||
var langSel = document.getElementById("langs");
|
||||
//var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langID = langSel ? langs.value : "";
|
||||
langID = langID == "All" ? "" : langID;
|
||||
requestDownloadLinks(this.dataset.kiwixDl, langID);
|
||||
});
|
||||
return;
|
||||
}
|
||||
//Remove images
|
||||
var doc = doc.replace(/<img\b[^>]*>\s*/ig, "");
|
||||
//Reduce size of header
|
||||
doc = doc.replace(/<h1\b([^>]*>[^<]*<\/)h1>/ig, "<h3$1h3>");
|
||||
//Limit height of pre box and prevent word wrapping
|
||||
doc = doc.replace(/<pre>/i, '<div class="panel panel-success">\r\n' +
|
||||
'<pre id="dl-panel-heading" class="panel-heading" style="overflow-x: hidden; word-wrap: normal;">$#$#</pre>\r\n' +
|
||||
'<pre id="dl-panel-body" class="panel panel-body" style="max-height:360px; word-wrap:normal; margin-bottom:10px; overflow: auto;">');
|
||||
//Remove hr at end of page and add extra </div>
|
||||
doc = doc.replace(/<hr\b[^>]*>(\s*<\/pre>)/i, "$1</div>");
|
||||
//Move header into panel-header (NB regex is deliberately redundant to increase specificity of search)
|
||||
doc = doc.replace(/\$\#\$\#([\s\S]+?)(<a\s+href[^>]+>name<[\s\S]+?last\s+modified<[\s\S]+?)<hr>\s*/i, "$2$1");
|
||||
if (/\dK|\dM|\dG/.test(doc)) {
|
||||
//Swap size and date fields to make file size more prominent on narrow screens
|
||||
doc = doc.replace(/(<a\b[^>]*>last\s+modified<\/a>\s*)(<a\b[^>]*>size<\/a>\s*)/ig, "$2$1");
|
||||
doc = doc.replace(/(\d\d-\w{3}-\d{4}\s\d\d\:\d\d\s+)(\d[\d.\w]+\s+)$/img, "$2$1");
|
||||
}
|
||||
if (/^[^_\n\r]+_([^_]+)_.+\.zim.+$/m.test(doc)) {
|
||||
//Delete all lines without a wiki pattern from language list
|
||||
var langList = doc.replace(/^(?![^_\n\r]+_(\w+)_.+$).*[\r\n]*/mg, "");
|
||||
//Get list of all languages
|
||||
langList = langList.replace(/^[^_]+_([^_]+)_.+$/mg, "$1");
|
||||
//Delete recurrences
|
||||
langList = langList.replace(/\b(\w+)\n(?=.*\b\1\n?)/mg, "");
|
||||
langList = "All\n" + langList;
|
||||
var langArray = langList.match(/^\w+$/mg);
|
||||
if (langArray) {
|
||||
var dropdown = '<select id="langs">\r\n';
|
||||
for (var q = 0; q < langArray.length; q++) {
|
||||
dropdown += '<option value="' + langArray[q] + '">' + langArray[q] + '</option>\r\n';
|
||||
}
|
||||
dropdown += '</select>\r\n';
|
||||
doc = doc.replace(/<\/h3>/i, '</h3><p>Filter list by language code: ' + dropdown + '</p>');
|
||||
}
|
||||
//Add language spans to doc
|
||||
doc = doc.replace(/^([^_\n\r]+_([^_]+)_.+\.zim.+)$[\n\r]*/img, '<span class="wikiLang" lang="$2">$1<br /></span>');
|
||||
}
|
||||
downloadLinks.innerHTML = doc;
|
||||
if (lang) {
|
||||
var langEntries = document.querySelectorAll(".wikiLang");
|
||||
//Hide all entries except specified language
|
||||
for (i = 0; i < langEntries.length; i++) {
|
||||
if (langEntries[i].lang != lang) langEntries[i].style.display = "none";
|
||||
}
|
||||
var langSel = document.getElementById("langs");
|
||||
if (langSel) {
|
||||
//var match = false;
|
||||
//for (var i = 0; i = langSel.options.length; i++) {
|
||||
// if (langSel.options[i].value == lang) { match = true; break; }
|
||||
//}
|
||||
//if (match) langSel.options[i]
|
||||
langs.value = lang;
|
||||
}
|
||||
}
|
||||
if (typeof langArray !== "undefined") {
|
||||
//Set up event listener for language selector
|
||||
document.getElementById("langs").addEventListener("change", function () {
|
||||
var langSel = document.getElementById("langs");
|
||||
var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langEntries = document.querySelectorAll(".wikiLang");
|
||||
//Hide all entries except specified language
|
||||
for (i = 0; i < langEntries.length; i++) {
|
||||
if (langEntries[i].lang == langID || langID == "All") langEntries[i].style.display = "inline";
|
||||
if (langEntries[i].lang != langID && langID != "All") langEntries[i].style.display = "none";
|
||||
}
|
||||
});
|
||||
}
|
||||
var links = downloadLinks.getElementsByTagName("a");
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
//Store the href - seems it's not useful?
|
||||
//links[i].setAttribute("data-kiwix-dl", links[i].href);
|
||||
links[i].href = "#";
|
||||
links[i].addEventListener('click', function () {
|
||||
var langSel = document.getElementById("langs");
|
||||
//var langID = langSel ? langSel.options[langSel.selectedIndex].value : "";
|
||||
var langID = langSel ? langs.value : "";
|
||||
var replaceURL = URL + this.text;
|
||||
if (/\.zim$/i.test(this.text))
|
||||
replaceURL = replaceURL + ".meta4";
|
||||
if (/parent\s*directory/i.test(this.text))
|
||||
replaceURL = URL.replace(/\/[^\/]*\/$/i, "\/");
|
||||
requestDownloadLinks(replaceURL, langID);
|
||||
});
|
||||
}
|
||||
//Toggle display of download panel -- bug: causes whole div to close if clicking on a link...
|
||||
//downloadLinks.style.display = downloadLinks.style.display == "none" ? "inline" : "none";
|
||||
downloadLinks.style.display = "inline";
|
||||
} else {
|
||||
serverResponse.innerHTML += ".";
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", URL, true);
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
*/
|
||||
return {
|
||||
langCodes: langCodes,
|
||||
requestDownloadLinks: requestDownloadLinks
|
||||
};
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* transformCSS.js: Provides transformations in CSS of Wikipedia articles contained in the ZIM file
|
||||
* transformStyles.js: Provides transformations in CSS of Wikipedia articles contained in the ZIM file
|
||||
* This allows the user to choose the presentation style for the page to be viewed.
|
||||
* Currently available are "mobile" and "desktop" display modes.
|
||||
*
|
||||
@ -122,7 +122,7 @@ define(['util', 'uiUtil'], function (util, uiUtil) {
|
||||
if (paras.length) {
|
||||
for (var g = 0; g < 3; g++) {
|
||||
//Check if the paragraph is a proper sentence, i.e. contains at least 50 non-HTML-delimetered non-full-stop characters, followed by a punctuation character
|
||||
if (/[^.]{50,}[^.]*[.,;:?!-]/.test(paras[g].replace(/<[^>]*>/g, ""))) { matched = true; break; }
|
||||
if (paras[g] && /[^.]{50,}[^.]*[.,;:?!-]/.test(paras[g].replace(/<[^>]*>/g, ""))) { matched = true; break; }
|
||||
}
|
||||
if (matched) {
|
||||
//Swap table and first matched paragraph, but mark lead paragraph first
|
||||
|
@ -694,84 +694,6 @@ define(['q'], function(q) {
|
||||
|
||||
}
|
||||
|
||||
function requestDownloadLinks(URL) {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var doc = this.responseText;
|
||||
var downloadLinks = document.getElementById('downloadLinks');
|
||||
if (/\.meta4$/i.test(URL)) {
|
||||
//It's the metalink with download links
|
||||
var linkArray = doc.match(/<url\b[^>]*>[^<]*<\/url>/ig);
|
||||
var size = doc.match(/<size>(\d+)<\/size>/i);
|
||||
//Filter value (add commas if required)
|
||||
size = size.length ? size[1] : "";
|
||||
var megabytes = size ? Math.round(size * 10 / (1024 * 1024)) / 10 : size;
|
||||
//Use the lookbehind reversal trick to add commas....
|
||||
size = size.toString().split('').reverse().join('').replace(/(\d{3}(?!.*\.|$))/g, '$1,').split('').reverse().join('');
|
||||
doc = "";
|
||||
//NB we'ere intentionally discarding first link to kiwix.org (not to zim)
|
||||
var mirrorservice = false;
|
||||
for (var i = 1; i < linkArray.length; i++) {
|
||||
if (/mirrorservice\.org/i.test(linkArray[i])) {
|
||||
mirrorservice = true;
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li>*** Server has download bug, see note ***<br />$1</li>\r\n');
|
||||
} else {
|
||||
doc += linkArray[i].replace(/<url\b[^>]*>([^<]*)<\/url>/i, '<li><a href="$1" target="_blank">$1</a></li>\r\n');
|
||||
}
|
||||
}
|
||||
var fullDoc = '<div class="panel panel-body" style="overflow-y: auto;">\r\n<h4>We found the following links to your file</h4>\r\n<h5';
|
||||
if (megabytes > 200) fullDoc += ' style="color:red;"';
|
||||
fullDoc += '>WARNING: file size is <b>' + (megabytes ? megabytes + 'Mb' : 'unnown') + '</b>' + (size ? ' (' + size + ' bytes)' : '') + '</h5>\r\n';
|
||||
if (megabytes > 200) fullDoc += '<b>Consider using a torrent download method: see <a href="#" onclick="$(\'#btnAbout\').click();">About</a> section</b>\r\n';
|
||||
fullDoc += '<p><i>Links will open in a new browser window</i></p><ol>\r\n' + doc + '</ol>\r\n';
|
||||
if (mirrorservice) fullDoc += '*** Note: mirrorservice.org currently has a download bug with ZIM archives: on some browsers it will download the ZIM file as plain text in browser window<br /><br />';
|
||||
fullDoc += '<a id="returnLink" href="#" data-kiwix-dl="' + URL.replace(/\/[^\/]*\.meta4$/i, "\/") +'"><< Back to list of files</a></pre>';
|
||||
downloadLinks.innerHTML = fullDoc;
|
||||
document.getElementById('returnLink').addEventListener('click', function (e) {
|
||||
requestDownloadLinks(this.dataset.kiwixDl);
|
||||
});
|
||||
return;
|
||||
}
|
||||
//Remove images
|
||||
var doc = doc.replace(/<img\b[^>]*>\s*/ig, "");
|
||||
//Reduce size of header
|
||||
doc = doc.replace(/<h1\b([^>]*>[^<]*<\/)h1>/ig, "<h3$1h3>");
|
||||
//Limit height of pre box and prevent word wrapping
|
||||
doc = doc.replace(/<pre>/i, '<div class="panel panel-success"><pre class="panel-heading" style="overflow-x: hidden; word-wrap: normal;">$#$#</pre>\r\n<pre class="panel panel-body" style="max-height:360px; word-wrap:normal; margin-bottom:10px;">');
|
||||
//Remove hr at end of page and add extra </div>
|
||||
doc = doc.replace(/<hr\b[^>]*>(\s*<\/pre>)/i, "$1</div>");
|
||||
//Move header into panel-header (NB regex is deliberately redundant to increase specificity of search)
|
||||
doc = doc.replace(/\$\#\$\#([\s\S]+?)(<a\s+href[^>]+>name<[\s\S]+?last\s+modified<[\s\S]+?)<hr>\s*/i, "$2$1");
|
||||
if (/\dK|\dM|\dG/.test(doc)) {
|
||||
//Swap size and date fields to make file size more prominent on narrow screens
|
||||
doc = doc.replace(/(<a\b[^>]*>last\s+modified<\/a>)(\s+)(<a\b[^>]*>size<\/a>)/ig, "$3$2$1");
|
||||
doc = doc.replace(/(\d\d-\w{3}-\d{4}\s\d\d\:\d\d)(\s+)(\d[\d.\w]+)\s+$/img, "$3$2$1");
|
||||
}
|
||||
downloadLinks.innerHTML = doc;
|
||||
var links = downloadLinks.getElementsByTagName("a");
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
//Store the href - seems it's not useful?
|
||||
//links[i].setAttribute("data-kiwix-dl", links[i].href);
|
||||
links[i].href = "#";
|
||||
links[i].addEventListener('click', function (e) {
|
||||
var replaceURL = URL + this.text;
|
||||
if (/\.zim$/i.test(this.text))
|
||||
replaceURL = replaceURL + ".meta4";
|
||||
if (/parent\s*directory/i.test(this.text))
|
||||
replaceURL = URL.replace(/\/[^\/]*\/$/i, "\/");
|
||||
requestDownloadLinks(replaceURL);
|
||||
});
|
||||
}
|
||||
//Toggle display of download panel -- bug: causes whole div to close if clicking on a link...
|
||||
//downloadLinks.style.display = downloadLinks.style.display == "none" ? "inline" : "none";
|
||||
downloadLinks.style.display = "inline";
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", URL, true);
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
@ -795,7 +717,6 @@ define(['q'], function(q) {
|
||||
leftShift: leftShift,
|
||||
matchOuter: matchOuter,
|
||||
matchInner: matchInner,
|
||||
Hilitor: Hilitor,
|
||||
requestDownloadLinks: requestDownloadLinks
|
||||
Hilitor: Hilitor
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user