diff --git a/KiwixWebApp.jsproj b/KiwixWebApp.jsproj
index 6f85c02e..8e76d2c7 100644
--- a/KiwixWebApp.jsproj
+++ b/KiwixWebApp.jsproj
@@ -178,6 +178,7 @@
- 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 Frequently Asked Questions. Consider using a torrent download method: see About section Links will open in a new browser window Filter list by language code: ' + dropdown + ' Links will open in a new browser windowDownload links
Files can be very large, do not attempt to download over a mobile connection!
+ Files can be very large, do not attempt to download over a mobile connection!
Open full list of download links : Warning: requires active Internet connection and will use data
$1 200 ? ' style="color:red;"> WARNING: ' : '>';
+ bodyDoc += 'File size is ' + (megabytes ? megabytes$ + 'MB' : 'unnown') + '' + (size ? ' (' + size + ' bytes)' : '') + '
\r\n';
+ if (megabytes > 4000) bodyDoc += '\r\n' + doc + '
\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
';
+ bodyDoc += '<< Back to list of files
';
+ var header = document.getElementById('dl-panel-heading');
+ header.outerHTML = header.outerHTML.replace(/]*)>[\s\S]*?<\/pre>/i, '
]*)>[\s\S]*?<\/pre>/i, '
]*>\s*/ig, "");
+ //Reduce size of header
+ doc = doc.replace(/
]*>[^<]*<\/)h1>/ig, "
");
+ //Limit height of pre box and prevent word wrapping
+ doc = doc.replace(/
/i, '
$#$#
\r\n' +
+ '');
+ //Remove hr at end of page and add extra
]*>(\s*<\/pre>)/i, "$1");
+ //Move header into panel-header (NB regex is deliberately redundant to increase specificity of search)
+ doc = doc.replace(/\$\#\$\#([\s\S]+?)(]+>name<[\s\S]+?last\s+modified<[\s\S]+?)
\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(/(]*>last\s+modified<\/a>\s*)(]*>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 = '\r\n';
+ doc = doc.replace(/<\/h3>/i, '
');
+ }
+ 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
+ };
+});
\ No newline at end of file
diff --git a/bin/Release/AppX/www/js/lib/transformStyles.js b/bin/Release/AppX/www/js/lib/transformStyles.js
index 2c073186..bd7c65aa 100644
--- a/bin/Release/AppX/www/js/lib/transformStyles.js
+++ b/bin/Release/AppX/www/js/lib/transformStyles.js
@@ -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
diff --git a/bin/Release/AppX/www/js/lib/util.js b/bin/Release/AppX/www/js/lib/util.js
index e1d096d6..a03cf673 100644
--- a/bin/Release/AppX/www/js/lib/util.js
+++ b/bin/Release/AppX/www/js/lib/util.js
@@ -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(/
$1We found the following links to your file
\r\n 200) fullDoc += ' style="color:red;"';
- fullDoc += '>WARNING: file size is ' + (megabytes ? megabytes + 'Mb' : 'unnown') + '' + (size ? ' (' + size + ' bytes)' : '') + '
\r\n';
- if (megabytes > 200) fullDoc += 'Consider using a torrent download method: see About section\r\n';
- fullDoc += '\r\n' + doc + '
\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
';
- fullDoc += '<< Back to list of files';
- downloadLinks.innerHTML = fullDoc;
- document.getElementById('returnLink').addEventListener('click', function (e) {
- requestDownloadLinks(this.dataset.kiwixDl);
- });
- return;
- }
- //Remove images
- var doc = doc.replace(/]*>\s*/ig, "");
- //Reduce size of header
- doc = doc.replace(/
]*>[^<]*<\/)h1>/ig, "
");
- //Limit height of pre box and prevent word wrapping
- doc = doc.replace(/
/i, '
');
- //Remove hr at end of page and add extra
]*>(\s*<\/pre>)/i, "$1
\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(/(]*>last\s+modified<\/a>)(\s+)(]*>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
};
});
diff --git a/bin/Release/KiwixWebApp.build.appxrecipe b/bin/Release/KiwixWebApp.build.appxrecipe
index 957cfd20..5f522cf2 100644
--- a/bin/Release/KiwixWebApp.build.appxrecipe
+++ b/bin/Release/KiwixWebApp.build.appxrecipe
@@ -478,6 +478,9 @@
Open full list of download links : Warning: requires active Internet connection and will use data
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 Frequently Asked Questions.
\r\n'; + if (megabytes > 200) bodyDoc += 'Consider using a torrent download method: see About section
\r\n'; + bodyDoc += 'Links will open in a new browser window
]*)>[\s\S]*?<\/pre>/i, '' + headerDoc + ''); + var body = document.getElementById('dl-panel-body'); + body.outerHTML = body.outerHTML.replace(/]*)>[\s\S]*?<\/pre>/i, '' + bodyDoc + ''); + 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(/]*>\s*/ig, ""); + //Reduce size of header + doc = doc.replace(/
]*>[^<]*<\/)h1>/ig, "
"); + //Limit height of pre box and prevent word wrapping + doc = doc.replace(/
/i, '\r\n' + + '+ doc = doc.replace(/$#$#\r\n' + + ''); + //Remove hr at end of page and add extra
]*>(\s*<\/pre>)/i, "$1"); + //Move header into panel-header (NB regex is deliberately redundant to increase specificity of search) + doc = doc.replace(/\$\#\$\#([\s\S]+?)(]+>name<[\s\S]+?last\s+modified<[\s\S]+?)
\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(/(]*>last\s+modified<\/a>\s*)(]*>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 = '\r\n'; + doc = doc.replace(/<\/h3>/i, 'Filter list by language code: ' + dropdown + '
'); + } + //Add language spans to doc + doc = doc.replace(/^([^_\n\r]+_([^_]+)_.+\.zim.+)$[\n\r]*/img, '$1
'); + } + 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 + }; +}); \ No newline at end of file diff --git a/www/js/lib/transformStyles.js b/www/js/lib/transformStyles.js index 2c073186..bd7c65aa 100644 --- a/www/js/lib/transformStyles.js +++ b/www/js/lib/transformStyles.js @@ -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 diff --git a/www/js/lib/util.js b/www/js/lib/util.js index e1d096d6..a03cf673 100644 --- a/www/js/lib/util.js +++ b/www/js/lib/util.js @@ -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>/ig); - var size = doc.match(/ (\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>/i, ' *** Server has download bug, see note *** \r\n'); - } else { - doc += linkArray[i].replace(/
$1]*>([^<]*)<\/url>/i, ' $1 \r\n'); - } - } - var fullDoc = '\r\n"); - //Move header into panel-header (NB regex is deliberately redundant to increase specificity of search) - doc = doc.replace(/\$\#\$\#([\s\S]+?)(]+>name<[\s\S]+?last\s+modified<[\s\S]+?)We found the following links to your file
\r\n200) fullDoc += ' style="color:red;"'; - fullDoc += '>WARNING: file size is ' + (megabytes ? megabytes + 'Mb' : 'unnown') + '' + (size ? ' (' + size + ' bytes)' : '') + '
\r\n'; - if (megabytes > 200) fullDoc += 'Consider using a torrent download method: see About section\r\n'; - fullDoc += 'Links will open in a new browser window
\r\n' + doc + '
\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
'; - fullDoc += '<< Back to list of files'; - downloadLinks.innerHTML = fullDoc; - document.getElementById('returnLink').addEventListener('click', function (e) { - requestDownloadLinks(this.dataset.kiwixDl); - }); - return; - } - //Remove images - var doc = doc.replace(/]*>\s*/ig, ""); - //Reduce size of header - doc = doc.replace(/
]*>[^<]*<\/)h1>/ig, "
"); - //Limit height of pre box and prevent word wrapping - doc = doc.replace(/
/i, '- doc = doc.replace(/ \r\n'); - //Remove hr at end of page and add extra
]*>(\s*<\/pre>)/i, "$1
\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(/(]*>last\s+modified<\/a>)(\s+)(]*>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 }; });