mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-22 12:01:15 -04:00
Random articles.
This commit is contained in:
parent
9430603001
commit
3f7abc7a24
@ -76,6 +76,7 @@
|
|||||||
or <a href="#" id="btnArticlesNearby">Find articles around me (work in progress)</a><br/>
|
or <a href="#" id="btnArticlesNearby">Find articles around me (work in progress)</a><br/>
|
||||||
Longitude/Latitude:
|
Longitude/Latitude:
|
||||||
<input type="text" id="longitude" size="8" /> <input type="text" id="latitude" size="8" /><br/>
|
<input type="text" id="longitude" size="8" /> <input type="text" id="latitude" size="8" /><br/>
|
||||||
|
or <a href="#" id="btnRandomArticle">Go to a random article</a><br/>
|
||||||
<div id="searchingForTitles" style="position: relative; z-index: 10; top: 20px; height: 0px; display: none;">
|
<div id="searchingForTitles" style="position: relative; z-index: 10; top: 20px; height: 0px; display: none;">
|
||||||
<img src="img/spinner.gif" alt="Please wait..." />
|
<img src="img/spinner.gif" alt="Please wait..." />
|
||||||
</div>
|
</div>
|
||||||
|
@ -73,6 +73,14 @@ define(function(require) {
|
|||||||
$('#navbarToggle').click();
|
$('#navbarToggle').click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$("#btnRandomArticle").on("click", function(e) {
|
||||||
|
goToRandomArticle();
|
||||||
|
$("#welcomeText").hide();
|
||||||
|
$("#readingArticle").hide();
|
||||||
|
if ($('#navbarToggle').is(":visible") && $('#liHomeNav').is(':visible')) {
|
||||||
|
$('#navbarToggle').click();
|
||||||
|
}
|
||||||
|
});
|
||||||
// Bottom bar :
|
// Bottom bar :
|
||||||
$('#btnBack').on('click', function(e) {
|
$('#btnBack').on('click', function(e) {
|
||||||
history.back();
|
history.back();
|
||||||
@ -580,4 +588,18 @@ define(function(require) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function goToRandomArticle() {
|
||||||
|
localArchive.getRandomTitle(function(title) {
|
||||||
|
if (title === null || title === undefined) {
|
||||||
|
alert("Error finding random article.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#articleName").html(title.name);
|
||||||
|
$("#readingArticle").show();
|
||||||
|
$("#articleContent").html("");
|
||||||
|
readArticle(title);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -361,7 +361,16 @@ define(function(require) {
|
|||||||
* @param callbackFunction
|
* @param callbackFunction
|
||||||
*/
|
*/
|
||||||
LocalArchive.prototype.getRandomTitle = function(callbackFunction) {
|
LocalArchive.prototype.getRandomTitle = function(callbackFunction) {
|
||||||
// TODO to be implemented
|
var that = this;
|
||||||
|
var offset = Math.floor(Math.random() * this.titleFile.size);
|
||||||
|
jQuery.when().then(function() {
|
||||||
|
var iterator = new titleIterators.SequentialTitleIterator(that, offset);
|
||||||
|
// call advance twice because we are probably not at the beginning
|
||||||
|
// of a title
|
||||||
|
return iterator.advance().then(function() {
|
||||||
|
return iterator.advance();
|
||||||
|
});
|
||||||
|
}).then(callbackFunction, errorHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user