mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
Merge pull request #346 from kiwix/accept-links-with-anchors
Accept links to articles that have an anchor.
This commit is contained in:
commit
b1118a9747
@ -36,7 +36,7 @@ self.addEventListener('activate', function(event) {
|
||||
console.log("ServiceWorker activated");
|
||||
});
|
||||
|
||||
var regexpRemoveUrlParameters = new RegExp(/([^\?]+)\?.*$/);
|
||||
var regexpRemoveUrlParameters = new RegExp(/([^?#]+)[?#].*$/);
|
||||
|
||||
// This function is duplicated from uiUtil.js
|
||||
// because using requirejs would force to add the 'fetch' event listener
|
||||
@ -44,12 +44,14 @@ var regexpRemoveUrlParameters = new RegExp(/([^\?]+)\?.*$/);
|
||||
// in recent versions of the browsers.
|
||||
// Cf https://bugzilla.mozilla.org/show_bug.cgi?id=1181127
|
||||
// TODO : find a way to avoid this duplication
|
||||
|
||||
/**
|
||||
* Removes parameters and anchors from a URL
|
||||
* @param {type} url
|
||||
* @returns {String} same URL without its parameters and anchors
|
||||
*/
|
||||
function removeUrlParameters(url) {
|
||||
if (regexpRemoveUrlParameters.test(url)) {
|
||||
return regexpRemoveUrlParameters.exec(url)[1];
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
return url.replace(regexpRemoveUrlParameters, "$1");
|
||||
}
|
||||
|
||||
console.log("ServiceWorker startup");
|
||||
|
@ -19,8 +19,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'],
|
||||
function($, zimArchive, zimDirEntry, util, utf8) {
|
||||
define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'uiUtil', 'utf8'],
|
||||
function($, zimArchive, zimDirEntry, util, uiUtil, utf8) {
|
||||
|
||||
var localZimArchive;
|
||||
|
||||
@ -119,6 +119,16 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'],
|
||||
var expectedArray = [{title:"a"}, {title:"b"}, {title:"c"}, {title:"d"}];
|
||||
assert.deepEqual(util.removeDuplicateTitlesInDirEntryArray(array), expectedArray, "Duplicates should be removed from the array");
|
||||
});
|
||||
QUnit.test("check removal of parameters in URL", function(assert) {
|
||||
var testUrl1 = "A/question.html";
|
||||
var testUrl2 = "A/question.html?param1=toto¶m2=titi";
|
||||
var testUrl3 = "A/question.html?param1=toto¶m2=titi#anchor";
|
||||
var testUrl4 = "A/question.html#anchor";
|
||||
assert.equal(uiUtil.removeUrlParameters(testUrl1), testUrl1);
|
||||
assert.equal(uiUtil.removeUrlParameters(testUrl2), testUrl1);
|
||||
assert.equal(uiUtil.removeUrlParameters(testUrl3), testUrl1);
|
||||
assert.equal(uiUtil.removeUrlParameters(testUrl4), testUrl1);
|
||||
});
|
||||
|
||||
QUnit.module("ZIM initialisation");
|
||||
QUnit.test("ZIM archive is ready", function(assert) {
|
||||
|
@ -1000,6 +1000,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
||||
* @param {String} title
|
||||
*/
|
||||
function goToArticle(title) {
|
||||
title = uiUtil.removeUrlParameters(title);
|
||||
selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {
|
||||
if (dirEntry === null || dirEntry === undefined) {
|
||||
$("#readingArticle").hide();
|
||||
|
@ -73,14 +73,15 @@ define([], function() {
|
||||
link.replaceWith(cssElement);
|
||||
}
|
||||
|
||||
var regexpRemoveUrlParameters = new RegExp(/([^\?]+)\?.*$/);
|
||||
var regexpRemoveUrlParameters = new RegExp(/([^?#]+)[?#].*$/);
|
||||
|
||||
/**
|
||||
* Removes parameters and anchors from a URL
|
||||
* @param {type} url
|
||||
* @returns {String} same URL without its parameters and anchors
|
||||
*/
|
||||
function removeUrlParameters(url) {
|
||||
if (regexpRemoveUrlParameters.test(url)) {
|
||||
return regexpRemoveUrlParameters.exec(url)[1];
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
return url.replace(regexpRemoveUrlParameters, "$1");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user