mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-23 04:28:30 -04:00
Slightly optimize the way results are displayed
Temporary workaround for duplicated titles nearby Merge the 2 "articles nearby" functions in app.js
This commit is contained in:
parent
0b460d55d4
commit
92f71aee6a
84
js/app.js
84
js/app.js
@ -305,18 +305,14 @@ define(function(require) {
|
||||
*/
|
||||
function populateListOfTitles(titleArray) {
|
||||
var titleListDiv = $('#titleList');
|
||||
// Remove previous results
|
||||
titleListDiv.empty();
|
||||
var titleListDivHtml = "";
|
||||
for (var i = 0; i < titleArray.length; i++) {
|
||||
var title = titleArray[i];
|
||||
var titleA = document.createElement('a');
|
||||
titleA.setAttribute("class","list-group-item");
|
||||
titleA.setAttribute("titleId", title.toStringId());
|
||||
titleA.setAttribute("href", "#");
|
||||
$(titleA).append(title.getReadableName());
|
||||
$(titleA).on("click",handleTitleClick);
|
||||
titleListDiv.append(titleA);
|
||||
titleListDivHtml += "<a href='#' titleid='" + title.toStringId()
|
||||
+ "' class='list-group-item'>" + title.getReadableName() + "</a>";
|
||||
}
|
||||
titleListDiv.html(titleListDivHtml);
|
||||
$("#titleList a").on("click",handleTitleClick);
|
||||
$('#searchingForTitles').hide();
|
||||
}
|
||||
|
||||
@ -514,43 +510,6 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to geolocate the device of the user
|
||||
* The accuracy of geolocation is not very important, so we disable HighAccuracy,
|
||||
* so that geolocation might be as fast as possible (including geolocation by IP)
|
||||
*
|
||||
* If a geolocation has been made less than 30 minutes ago, it can be re-used in cache
|
||||
*/
|
||||
function geolocateAndLaunchTitlesNearbySearch() {
|
||||
if (navigator.geolocation) {
|
||||
var geo_options = {
|
||||
enableHighAccuracy: false,
|
||||
maximumAge: 1800000 // 30 minutes
|
||||
};
|
||||
|
||||
function geo_success(pos) {
|
||||
var crd = pos.coords;
|
||||
|
||||
var rectangle = new geometry.rect(
|
||||
crd.longitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
||||
crd.latitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
||||
MAX_DISTANCE_ARTICLES_NEARBY * 2,
|
||||
MAX_DISTANCE_ARTICLES_NEARBY * 2);
|
||||
|
||||
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||
};
|
||||
|
||||
function geo_error(err) {
|
||||
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
|
||||
};
|
||||
|
||||
navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
|
||||
}
|
||||
else {
|
||||
alert("Geolocation is not supported (or disabled) on your device, or by your browser");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for titles located around where the device is geolocated
|
||||
*/
|
||||
@ -559,9 +518,36 @@ define(function(require) {
|
||||
$('#configuration').hide();
|
||||
$('#articleContent').empty();
|
||||
if (localArchive !== null && localArchive.titleFile !== null) {
|
||||
//geolocateAndLaunchTitlesNearbySearch();
|
||||
var rectangle = new geometry.rect(0,40,10,10);
|
||||
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||
//var rectangle = new geometry.rect(0,40,10,10);
|
||||
//localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||
if (navigator.geolocation) {
|
||||
var geo_options = {
|
||||
enableHighAccuracy: false,
|
||||
maximumAge: 1800000, // 30 minutes
|
||||
timeout : 10000 // 10 seconds
|
||||
};
|
||||
|
||||
function geo_success(pos) {
|
||||
var crd = pos.coords;
|
||||
|
||||
var rectangle = new geometry.rect(
|
||||
crd.longitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
||||
crd.latitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
||||
MAX_DISTANCE_ARTICLES_NEARBY * 2,
|
||||
MAX_DISTANCE_ARTICLES_NEARBY * 2);
|
||||
|
||||
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||
};
|
||||
|
||||
function geo_error(err) {
|
||||
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
|
||||
};
|
||||
|
||||
navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
|
||||
}
|
||||
else {
|
||||
alert("Geolocation is not supported (or disabled) on your device, or by your browser");
|
||||
}
|
||||
} else {
|
||||
$('#searchingForTitles').hide();
|
||||
// We have to remove the focus from the search field,
|
||||
|
@ -752,7 +752,14 @@ define(function(require) {
|
||||
else {
|
||||
// Search is over : now let's convert the title positions into Title instances
|
||||
if (titlePositionsFound && titlePositionsFound.length > 0) {
|
||||
LocalArchive.readTitlesFromTitleCoordsInTitleFile(localArchive, titlePositionsFound, 0, new Array(), callbackFunction);
|
||||
// TODO find out why there are duplicates, and why the maxTitles is not respected
|
||||
// The statement below removes duplicates and limits its size
|
||||
// (not correctly because based on indexes of the original array, instead of target array)
|
||||
// This should be removed when the cause is found
|
||||
var filteredTitlePositions = titlePositionsFound.filter(function (e, i, arr) {
|
||||
return arr.lastIndexOf(e) === i && i<=maxTitles;
|
||||
});
|
||||
LocalArchive.readTitlesFromTitleCoordsInTitleFile(localArchive, filteredTitlePositions, 0, new Array(), callbackFunction);
|
||||
}
|
||||
else {
|
||||
return titlePositionsFound;
|
||||
|
Loading…
x
Reference in New Issue
Block a user