Merge branch 'master' into jquery-fallback

This commit is contained in:
mossroy 2016-01-07 18:06:11 +01:00
commit 4ccdee6324
4 changed files with 22 additions and 15 deletions

View File

@ -19,8 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/
define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geometry'],
function($, evopediaTitle, evopediaArchive, zimArchive, zimDirEntry, util, geometry) {
define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geometry', 'utf8'],
function($, evopediaTitle, evopediaArchive, zimArchive, zimDirEntry, util, geometry, utf8) {
var localEvopediaArchive;
var localZimArchive;
@ -505,7 +505,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
});
asyncTest("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function() {
expect(6);
localZimArchive.getTitleByName("(The_Night_Time_Is)_The_Right_Time.html").then(function(title) {
localZimArchive.getTitleByName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(title) {
ok(title !== null, "Title found");
ok(title.isRedirect(), "Title is a redirect.");
equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name.");
@ -519,10 +519,9 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
});
asyncTest("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function() {
expect(4);
localZimArchive.getTitleByName("m/RayCharles_AManAndHisSoul.jpg").then(function(title) {
console.log(title);
localZimArchive.getTitleByName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(title) {
ok(title !== null, "Title found");
equal(title.url, "m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
equal(title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 4951, "Data length is correct.");
var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70,

View File

@ -856,9 +856,10 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
var titleName = event.data.titleName;
var messagePort = event.ports[0];
var readFile = function(title) {
console.log("Found title.");
if (title.isRedirect()) {
console.log("Following redirect...");
if (title === null) {
console.error("Title " + titleName + " not found in archive.");
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': ''});
} else if (title.isRedirect()) {
selectedArchive.resolveRedirect(title, readFile);
} else {
console.log("Reading binary file...");
@ -868,9 +869,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
});
}
}
console.log("Fetching title " + titleName);
selectedArchive.getTitleByName(titleName).then(readFile).fail(function() {
console.log("could not find title:" + arguments);
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': new UInt8Array()});
});
}

View File

@ -121,6 +121,10 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
return that._file.dirEntryByTitleIndex(i).then(function(dirEntry) {
if (dirEntry.title == "")
return -1; // ZIM sorts empty titles (assets) to the end
else if (dirEntry.namespace < "A")
return 1;
else if (dirEntry.namespace > "A")
return -1;
return prefix < dirEntry.title ? -1 : 1;
});
}, true).then(function(firstIndex) {
@ -206,17 +210,22 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
var that = this;
return util.binarySearch(0, this._file.articleCount, function(i) {
return that._file.dirEntryByUrlIndex(i).then(function(dirEntry) {
if (titleName < dirEntry.url)
var url = dirEntry.namespace + "/" + dirEntry.url;
if (titleName < url)
return -1;
else if (titleName > dirEntry.url)
else if (titleName > url)
return 1;
else
return 0;
});
}).then(function(index) {
if (index === null) return null;
return that._file.dirEntryByUrlIndex(index);
}).then(function(dirEntry) {
return that._dirEntryToTitleObject(dirEntry);
if (dirEntry === null)
return null;
else
return that._dirEntryToTitleObject(dirEntry);
});
};

View File

@ -54,7 +54,7 @@ define([], function() {
this.redirectTarget = dirEntryData.redirectTarget;
this.cluster = dirEntryData.cluster;
this.blob = dirEntryData.blob;
this.url = dirEntryData.url;
this.url = dirEntryData.namespace + '/' + dirEntryData.url;
this.title = dirEntryData.title;
};