mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-22 12:01:15 -04:00
Change new line format back to unix style
This commit is contained in:
parent
8dd14095e6
commit
166c87118e
1212
www/js/app.js
1212
www/js/app.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,126 +1,126 @@
|
|||||||
/**
|
/**
|
||||||
* titleIterators.js : Various classes to iterate over titles, for example as a
|
* titleIterators.js : Various classes to iterate over titles, for example as a
|
||||||
* result of searching.
|
* result of searching.
|
||||||
*
|
*
|
||||||
* Copyright 2014 Evopedia developers
|
* Copyright 2014 Evopedia developers
|
||||||
* License GPL v3:
|
* License GPL v3:
|
||||||
*
|
*
|
||||||
* This file is part of Evopedia.
|
* This file is part of Evopedia.
|
||||||
*
|
*
|
||||||
* Evopedia is free software: you can redistribute it and/or modify
|
* Evopedia is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Evopedia is distributed in the hope that it will be useful,
|
* Evopedia is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* 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/>
|
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util, jQuery) {
|
define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util, jQuery) {
|
||||||
// Maximum length of a title
|
// Maximum length of a title
|
||||||
// 300 bytes is arbitrary : we actually do not really know how long the titles will be
|
// 300 bytes is arbitrary : we actually do not really know how long the titles will be
|
||||||
// But mediawiki titles seem to be limited to ~200 bytes, so 300 should be more than enough
|
// But mediawiki titles seem to be limited to ~200 bytes, so 300 should be more than enough
|
||||||
var MAX_TITLE_LENGTH = 300;
|
var MAX_TITLE_LENGTH = 300;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates over all titles starting at the given offset.
|
* Iterates over all titles starting at the given offset.
|
||||||
* The asynchronous method advance has to be called before this.title is
|
* The asynchronous method advance has to be called before this.title is
|
||||||
* valid.
|
* valid.
|
||||||
* @param archive
|
* @param archive
|
||||||
* @param offset
|
* @param offset
|
||||||
*/
|
*/
|
||||||
function SequentialTitleIterator(archive, offset) {
|
function SequentialTitleIterator(archive, offset) {
|
||||||
this._titleFile = archive.titleFile;
|
this._titleFile = archive.titleFile;
|
||||||
this._archive = archive;
|
this._archive = archive;
|
||||||
this._offset = offset;
|
this._offset = offset;
|
||||||
this.title = null;
|
this.title = null;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Advances to the next title (or the first), if possible.
|
* Advances to the next title (or the first), if possible.
|
||||||
* @returns jQuery promise containing the next title or null if there is no
|
* @returns jQuery promise containing the next title or null if there is no
|
||||||
* next title
|
* next title
|
||||||
*/
|
*/
|
||||||
SequentialTitleIterator.prototype.advance = function() {
|
SequentialTitleIterator.prototype.advance = function() {
|
||||||
if (this._offset >= this._titleFile.size) {
|
if (this._offset >= this._titleFile.size) {
|
||||||
this.title = null;
|
this.title = null;
|
||||||
return jQuery.when(this.title);
|
return jQuery.when(this.title);
|
||||||
}
|
}
|
||||||
var that = this;
|
var that = this;
|
||||||
return util.readFileSlice(this._titleFile, this._offset,
|
return util.readFileSlice(this._titleFile, this._offset,
|
||||||
this._offset + MAX_TITLE_LENGTH).then(function(byteArray) {
|
this._offset + MAX_TITLE_LENGTH).then(function(byteArray) {
|
||||||
var newLineIndex = 15;
|
var newLineIndex = 15;
|
||||||
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
||||||
newLineIndex++;
|
newLineIndex++;
|
||||||
}
|
}
|
||||||
var encodedTitle = byteArray.subarray(0, newLineIndex);
|
var encodedTitle = byteArray.subarray(0, newLineIndex);
|
||||||
that._title = evopediaTitle.Title.parseTitle(encodedTitle, that._archive, that._offset);
|
that._title = evopediaTitle.Title.parseTitle(encodedTitle, that._archive, that._offset);
|
||||||
that._offset += newLineIndex + 1;
|
that._offset += newLineIndex + 1;
|
||||||
return that._title;
|
return that._title;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for the offset into the given title file where the first title
|
* Searches for the offset into the given title file where the first title
|
||||||
* with the given prefix (or lexicographically larger) is located.
|
* with the given prefix (or lexicographically larger) is located.
|
||||||
* The given function normalize is applied to every title before comparison.
|
* The given function normalize is applied to every title before comparison.
|
||||||
* @param titleFile
|
* @param titleFile
|
||||||
* @param prefix
|
* @param prefix
|
||||||
* @param normalize function to be applied to every title before comparison
|
* @param normalize function to be applied to every title before comparison
|
||||||
* @returns jQuery promise giving the offset
|
* @returns jQuery promise giving the offset
|
||||||
*/
|
*/
|
||||||
function findPrefixOffset(titleFile, prefix, normalize) {
|
function findPrefixOffset(titleFile, prefix, normalize) {
|
||||||
prefix = normalize(prefix);
|
prefix = normalize(prefix);
|
||||||
var lo = 0;
|
var lo = 0;
|
||||||
var hi = titleFile.size;
|
var hi = titleFile.size;
|
||||||
var iterate = function() {
|
var iterate = function() {
|
||||||
if (lo >= hi - 1) {
|
if (lo >= hi - 1) {
|
||||||
if (lo > 0)
|
if (lo > 0)
|
||||||
lo += 2; // Let lo point to the start of an entry
|
lo += 2; // Let lo point to the start of an entry
|
||||||
return jQuery.when(lo);
|
return jQuery.when(lo);
|
||||||
} else {
|
} else {
|
||||||
var mid = Math.floor((lo + hi) / 2);
|
var mid = Math.floor((lo + hi) / 2);
|
||||||
return util.readFileSlice(titleFile, mid, mid + MAX_TITLE_LENGTH).then(function(byteArray) {
|
return util.readFileSlice(titleFile, mid, mid + MAX_TITLE_LENGTH).then(function(byteArray) {
|
||||||
// Look for the index of the next NewLine
|
// Look for the index of the next NewLine
|
||||||
var newLineIndex = 0;
|
var newLineIndex = 0;
|
||||||
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
||||||
newLineIndex++;
|
newLineIndex++;
|
||||||
}
|
}
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
if (mid > 0) {
|
if (mid > 0) {
|
||||||
startIndex = newLineIndex + 16;
|
startIndex = newLineIndex + 16;
|
||||||
newLineIndex = startIndex;
|
newLineIndex = startIndex;
|
||||||
// Look for the index of the next NewLine
|
// Look for the index of the next NewLine
|
||||||
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
while (newLineIndex < byteArray.length && byteArray[newLineIndex] !== 10) {
|
||||||
newLineIndex++;
|
newLineIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newLineIndex === startIndex) {
|
if (newLineIndex === startIndex) {
|
||||||
// End of file reached
|
// End of file reached
|
||||||
hi = mid;
|
hi = mid;
|
||||||
} else {
|
} else {
|
||||||
var normalizedTitle = normalize(utf8.parse(byteArray.subarray(startIndex, newLineIndex)));
|
var normalizedTitle = normalize(utf8.parse(byteArray.subarray(startIndex, newLineIndex)));
|
||||||
if (normalizedTitle < prefix) {
|
if (normalizedTitle < prefix) {
|
||||||
lo = mid + newLineIndex - 1;
|
lo = mid + newLineIndex - 1;
|
||||||
} else {
|
} else {
|
||||||
hi = mid;
|
hi = mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return iterate();
|
return iterate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return iterate();
|
return iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions and classes exposed by this module
|
* Functions and classes exposed by this module
|
||||||
*/
|
*/
|
||||||
return {
|
return {
|
||||||
SequentialTitleIterator : SequentialTitleIterator,
|
SequentialTitleIterator : SequentialTitleIterator,
|
||||||
findPrefixOffset : findPrefixOffset
|
findPrefixOffset : findPrefixOffset
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -1,151 +1,151 @@
|
|||||||
/**
|
/**
|
||||||
* util.js : Utility functions
|
* util.js : Utility functions
|
||||||
*
|
*
|
||||||
* Copyright 2013 Mossroy
|
* Copyright 2013 Mossroy
|
||||||
* License GPL v3:
|
* License GPL v3:
|
||||||
*
|
*
|
||||||
* This file is part of Evopedia.
|
* This file is part of Evopedia.
|
||||||
*
|
*
|
||||||
* Evopedia is free software: you can redistribute it and/or modify
|
* Evopedia is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Evopedia is distributed in the hope that it will be useful,
|
* Evopedia is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* 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/>
|
* along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
define(function(require) {
|
define(function(require) {
|
||||||
var jQuery = require('jquery');
|
var jQuery = require('jquery');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function : return true if the given string ends with the suffix
|
* Utility function : return true if the given string ends with the suffix
|
||||||
* @param str
|
* @param str
|
||||||
* @param suffix
|
* @param suffix
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
function endsWith(str, suffix) {
|
function endsWith(str, suffix) {
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an integer encoded in 4 bytes, little endian
|
* Read an integer encoded in 4 bytes, little endian
|
||||||
* @param {type} byteArray
|
* @param {type} byteArray
|
||||||
* @param {type} firstIndex
|
* @param {type} firstIndex
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
function readIntegerFrom4Bytes(byteArray, firstIndex) {
|
function readIntegerFrom4Bytes(byteArray, firstIndex) {
|
||||||
var dataView = new DataView(byteArray.buffer, firstIndex, 4);
|
var dataView = new DataView(byteArray.buffer, firstIndex, 4);
|
||||||
var integer = dataView.getUint32(0, true);
|
var integer = dataView.getUint32(0, true);
|
||||||
return integer;
|
return integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read an integer encoded in 2 bytes, little endian
|
* Read an integer encoded in 2 bytes, little endian
|
||||||
* @param {type} byteArray
|
* @param {type} byteArray
|
||||||
* @param {type} firstIndex
|
* @param {type} firstIndex
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
function readIntegerFrom2Bytes(byteArray, firstIndex) {
|
function readIntegerFrom2Bytes(byteArray, firstIndex) {
|
||||||
var dataView = new DataView(byteArray.buffer, firstIndex, 2);
|
var dataView = new DataView(byteArray.buffer, firstIndex, 2);
|
||||||
var integer = dataView.getUint16(0, true);
|
var integer = dataView.getUint16(0, true);
|
||||||
return integer;
|
return integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a float encoded in 2 bytes
|
* Read a float encoded in 2 bytes
|
||||||
* @param {type} byteArray
|
* @param {type} byteArray
|
||||||
* @param {type} firstIndex
|
* @param {type} firstIndex
|
||||||
* @param {bool} littleEndian (optional)
|
* @param {bool} littleEndian (optional)
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
function readFloatFrom4Bytes(byteArray, firstIndex, littleEndian) {
|
function readFloatFrom4Bytes(byteArray, firstIndex, littleEndian) {
|
||||||
var dataView = new DataView(byteArray.buffer, firstIndex, 4);
|
var dataView = new DataView(byteArray.buffer, firstIndex, 4);
|
||||||
var float = dataView.getFloat32(0, littleEndian);
|
var float = dataView.getFloat32(0, littleEndian);
|
||||||
return float;
|
return float;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Uint8Array to a lowercase hex string
|
* Convert a Uint8Array to a lowercase hex string
|
||||||
* @param {type} byteArray
|
* @param {type} byteArray
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
function uint8ArrayToHex(byteArray) {
|
function uint8ArrayToHex(byteArray) {
|
||||||
var s = '';
|
var s = '';
|
||||||
var hexDigits = '0123456789abcdef';
|
var hexDigits = '0123456789abcdef';
|
||||||
for (var i = 0; i < byteArray.length; i++) {
|
for (var i = 0; i < byteArray.length; i++) {
|
||||||
var v = byteArray[i];
|
var v = byteArray[i];
|
||||||
s += hexDigits[(v & 0xff) >> 4];
|
s += hexDigits[(v & 0xff) >> 4];
|
||||||
s += hexDigits[v & 0xf];
|
s += hexDigits[v & 0xf];
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Uint8Array to base64
|
* Convert a Uint8Array to base64
|
||||||
* TODO : might be replaced by btoa() built-in function? https://developer.mozilla.org/en-US/docs/Web/API/window.btoa
|
* TODO : might be replaced by btoa() built-in function? https://developer.mozilla.org/en-US/docs/Web/API/window.btoa
|
||||||
* @param {type} byteArray
|
* @param {type} byteArray
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
function uint8ArrayToBase64(byteArray) {
|
function uint8ArrayToBase64(byteArray) {
|
||||||
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
var bits, h1, h2, h3, h4, i = 0;
|
var bits, h1, h2, h3, h4, i = 0;
|
||||||
var enc = "";
|
var enc = "";
|
||||||
|
|
||||||
for (var i = 0; i < byteArray.length; ) {
|
for (var i = 0; i < byteArray.length; ) {
|
||||||
bits = byteArray[i++] << 16;
|
bits = byteArray[i++] << 16;
|
||||||
bits |= byteArray[i++] << 8;
|
bits |= byteArray[i++] << 8;
|
||||||
bits |= byteArray[i++];
|
bits |= byteArray[i++];
|
||||||
|
|
||||||
h1 = bits >> 18 & 0x3f;
|
h1 = bits >> 18 & 0x3f;
|
||||||
h2 = bits >> 12 & 0x3f;
|
h2 = bits >> 12 & 0x3f;
|
||||||
h3 = bits >> 6 & 0x3f;
|
h3 = bits >> 6 & 0x3f;
|
||||||
h4 = bits & 0x3f;
|
h4 = bits & 0x3f;
|
||||||
|
|
||||||
enc += b64[h1] + b64[h2] + b64[h3] + b64[h4];
|
enc += b64[h1] + b64[h2] + b64[h3] + b64[h4];
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = byteArray.length % 3;
|
var r = byteArray.length % 3;
|
||||||
|
|
||||||
return (r > 0 ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
|
return (r > 0 ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a Uint8Array from the given file starting at byte offset begin and
|
* Reads a Uint8Array from the given file starting at byte offset begin and
|
||||||
* not including byte offset end.
|
* not including byte offset end.
|
||||||
* @param file
|
* @param file
|
||||||
* @param begin
|
* @param begin
|
||||||
* @param end
|
* @param end
|
||||||
* @returns jQuery promise
|
* @returns jQuery promise
|
||||||
*/
|
*/
|
||||||
function readFileSlice(file, begin, end) {
|
function readFileSlice(file, begin, end) {
|
||||||
var deferred = jQuery.Deferred();
|
var deferred = jQuery.Deferred();
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
deferred.resolve(new Uint8Array(e.target.result));
|
deferred.resolve(new Uint8Array(e.target.result));
|
||||||
};
|
};
|
||||||
reader.onerror = reader.onabort = function(e) {
|
reader.onerror = reader.onabort = function(e) {
|
||||||
deferred.reject(e);
|
deferred.reject(e);
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(file.slice(begin, end));
|
reader.readAsArrayBuffer(file.slice(begin, end));
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions and classes exposed by this module
|
* Functions and classes exposed by this module
|
||||||
*/
|
*/
|
||||||
return {
|
return {
|
||||||
endsWith: endsWith,
|
endsWith: endsWith,
|
||||||
readIntegerFrom4Bytes: readIntegerFrom4Bytes,
|
readIntegerFrom4Bytes: readIntegerFrom4Bytes,
|
||||||
readIntegerFrom2Bytes : readIntegerFrom2Bytes,
|
readIntegerFrom2Bytes : readIntegerFrom2Bytes,
|
||||||
readFloatFrom4Bytes : readFloatFrom4Bytes,
|
readFloatFrom4Bytes : readFloatFrom4Bytes,
|
||||||
uint8ArrayToHex : uint8ArrayToHex,
|
uint8ArrayToHex : uint8ArrayToHex,
|
||||||
uint8ArrayToBase64 : uint8ArrayToBase64,
|
uint8ArrayToBase64 : uint8ArrayToBase64,
|
||||||
readFileSlice : readFileSlice
|
readFileSlice : readFileSlice
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user