mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
Display the main page of the archive in the Home section.
Instead of a blank page. Fixes #126 It does not apply to Evopedia archives
This commit is contained in:
parent
81bf91c8c4
commit
d60a85a703
@ -501,7 +501,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
||||
expect(2);
|
||||
var callbackRandomTitleFound = function(title) {
|
||||
ok(title !== null, "One title should be found");
|
||||
ok(title._name !== null, "The random title should have a name" );
|
||||
ok(title.name() !== null, "The random title should have a name" );
|
||||
|
||||
start();
|
||||
};
|
||||
@ -702,5 +702,27 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
|
||||
}
|
||||
}).fail(errorHandlerAsyncTest);
|
||||
});
|
||||
|
||||
module("zim_random_and_main_title");
|
||||
asyncTest("check that a random title is found", function() {
|
||||
expect(2);
|
||||
var callbackRandomTitleFound = function(title) {
|
||||
ok(title !== null, "One title should be found");
|
||||
ok(title.name() !== null, "The random title should have a name" );
|
||||
|
||||
start();
|
||||
};
|
||||
localZimArchive.getRandomTitle(callbackRandomTitleFound);
|
||||
});
|
||||
asyncTest("check that the main title is found", function() {
|
||||
expect(2);
|
||||
var callbackMainPageTitleFound = function(title) {
|
||||
ok(title !== null, "Main title should be found");
|
||||
equal(title.name(), "Summary", "The main title should be called Summary" );
|
||||
|
||||
start();
|
||||
};
|
||||
localZimArchive.getMainPageTitle(callbackMainPageTitleFound);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
@ -203,6 +203,10 @@ define(['jquery', 'abstractBackend', 'util', 'uiUtil', 'cookies','geometry','osa
|
||||
$('#geolocationProgress').hide();
|
||||
$("#articleContent").contents().empty();
|
||||
$('#searchingForTitles').hide();
|
||||
if (selectedArchive !== null && selectedArchive.isReady()) {
|
||||
$("#welcomeText").hide();
|
||||
goToMainArticle();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('#btnConfigure').on('click', function(e) {
|
||||
@ -646,12 +650,14 @@ define(['jquery', 'abstractBackend', 'util', 'uiUtil', 'cookies','geometry','osa
|
||||
+ " storages found with getDeviceStorages instead of 1");
|
||||
}
|
||||
}
|
||||
selectedArchive = backend.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory);
|
||||
cookies.setItem("lastSelectedArchive", archiveDirectory, Infinity);
|
||||
if (checkSelectedArchiveCompatibilityWithInjectionMode()) {
|
||||
// The archive is set : go back to home page to start searching
|
||||
$("#btnHome").click();
|
||||
}
|
||||
selectedArchive = backend.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function (archive) {
|
||||
cookies.setItem("lastSelectedArchive", archiveDirectory, Infinity);
|
||||
if (checkSelectedArchiveCompatibilityWithInjectionMode()) {
|
||||
// The archive is set : go back to home page to start searching
|
||||
$("#btnHome").click();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -664,11 +670,13 @@ define(['jquery', 'abstractBackend', 'util', 'uiUtil', 'cookies','geometry','osa
|
||||
}
|
||||
|
||||
function setLocalArchiveFromFileList(files) {
|
||||
selectedArchive = backend.loadArchiveFromFiles(files);
|
||||
if (checkSelectedArchiveCompatibilityWithInjectionMode()) {
|
||||
// The archive is set : go back to home page to start searching
|
||||
$("#btnHome").click();
|
||||
}
|
||||
selectedArchive = backend.loadArchiveFromFiles(files, function(archive){
|
||||
if (checkSelectedArchiveCompatibilityWithInjectionMode()) {
|
||||
// The archive is set : go back to home page to start searching
|
||||
$("#btnHome").click();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
/**
|
||||
* Sets the localArchive from the File selects populated by user
|
||||
@ -1288,5 +1296,25 @@ define(['jquery', 'abstractBackend', 'util', 'uiUtil', 'cookies','geometry','osa
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function goToMainArticle() {
|
||||
selectedArchive.getMainPageTitle(function(title) {
|
||||
if (title === null || title === undefined) {
|
||||
console.error("Error finding main article.");
|
||||
}
|
||||
else {
|
||||
if (title.namespace === 'A') {
|
||||
$("#articleName").html(title.name());
|
||||
pushBrowserHistoryState(title.name());
|
||||
$("#readingArticle").show();
|
||||
$('#articleContent').contents().find('body').html("");
|
||||
readArticle(title);
|
||||
}
|
||||
else {
|
||||
console.error("The main page of this archive does not seem to be an article");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -29,30 +29,32 @@ define(['archive', 'zimArchive', 'util', 'jquery'],
|
||||
* Create an archive (ZIM or Evopedia) from DeviceStorage location
|
||||
* @param {DeviceStorage} storage
|
||||
* @param {String} path
|
||||
* @param {callbackZIMArchive} callback
|
||||
* @returns {ZIMArchive|LocalArchive}
|
||||
*/
|
||||
function loadArchiveFromDeviceStorage(storage, path) {
|
||||
function loadArchiveFromDeviceStorage(storage, path, callback) {
|
||||
if (regexpZIMFileName.test(path)) {
|
||||
return new zimArchive.ZIMArchive(storage, path);
|
||||
return new zimArchive.ZIMArchive(storage, path, callback);
|
||||
}
|
||||
else {
|
||||
var archive = new evopediaArchive.LocalArchive();
|
||||
archive.initializeFromDeviceStorage(storage, path);
|
||||
archive.initializeFromDeviceStorage(storage, path, callback);
|
||||
return archive;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Create an archive (ZIM or Evopedia) from Files
|
||||
* @param {Array.<File>} files
|
||||
* @param {callbackZIMArchive} callback
|
||||
* @returns {ZIMArchive|LocalArchive}
|
||||
*/
|
||||
function loadArchiveFromFiles(files) {
|
||||
function loadArchiveFromFiles(files, callback) {
|
||||
if (files.length >= 1 && regexpZIMFileName.test(files[0].name)) {
|
||||
return new zimArchive.ZIMArchive(files);
|
||||
return new zimArchive.ZIMArchive(files, null, callback);
|
||||
}
|
||||
else {
|
||||
var archive = new evopediaArchive.LocalArchive();
|
||||
archive.initializeFromArchiveFiles(files);
|
||||
archive.initializeFromArchiveFiles(files, callback);
|
||||
return archive;
|
||||
}
|
||||
};
|
||||
|
@ -259,20 +259,22 @@ define(['normalize_string', 'geometry', 'title', 'util', 'titleIterators', 'q'],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the localArchive from given directory, using DeviceStorage
|
||||
* @param {DeviceStorage} storage the directory resides in
|
||||
* @param {String} archiveDirectory
|
||||
* @param {callbackLocalArchive} callback Callback called when the LocalArchive is initialized
|
||||
*/
|
||||
LocalArchive.prototype.initializeFromDeviceStorage = function(storage, archiveDirectory) {
|
||||
LocalArchive.prototype.initializeFromDeviceStorage = function(storage, archiveDirectory, callback) {
|
||||
this.readTitleFilesFromStorage(storage, archiveDirectory);
|
||||
this.readDataFilesFromStorage(storage, archiveDirectory, 0);
|
||||
this.readMathFilesFromStorage(storage, archiveDirectory);
|
||||
this.readMetadataFileFromStorage(storage, archiveDirectory);
|
||||
this.readCoordinateFilesFromStorage(storage, archiveDirectory, 1);
|
||||
callback(this);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -374,6 +376,16 @@ define(['normalize_string', 'geometry', 'title', 'util', 'titleIterators', 'q'],
|
||||
});
|
||||
}).then(callbackFunction, errorHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks for the title of the main page
|
||||
* @param {callbackTitle} callback
|
||||
* @returns {Promise} that resolves to the Title
|
||||
*/
|
||||
LocalArchive.prototype.getMainPageTitle = function(callback) {
|
||||
// There's no such feature in Evopedia archives
|
||||
callback(null);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find titles that start with the given prefix, and call the callbackFunction with this list of Titles
|
||||
|
@ -126,6 +126,21 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
|
||||
ZIMArchive.prototype.hasCoordinates = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks for the title of the main page
|
||||
* @param {callbackTitle} callback
|
||||
* @returns {Promise} that resolves to the Title
|
||||
*/
|
||||
ZIMArchive.prototype.getMainPageTitle = function(callback) {
|
||||
if (this.isReady()) {
|
||||
var mainPageUrlIndex = this._file.mainPage;
|
||||
var that=this;
|
||||
this._file.dirEntryByUrlIndex(mainPageUrlIndex).then(function(dirEntry){
|
||||
return that._dirEntryToTitleObject(dirEntry);
|
||||
}).then(callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user