mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-22 03:52:21 -04:00
Display a warning to the user if the "small" archive has been selected
Fixes #48
This commit is contained in:
parent
37da0db928
commit
6422709551
@ -10,6 +10,7 @@ define(function(require) {
|
||||
var evopediaTitle = require('title');
|
||||
var evopediaArchive = require('archive');
|
||||
var util = require('util');
|
||||
var cookies = require('cookies');
|
||||
|
||||
// Maximum number of titles to display in a search
|
||||
var MAX_SEARCH_RESULT_SIZE = 50;
|
||||
@ -19,6 +20,13 @@ define(function(require) {
|
||||
|
||||
// Define behavior of HTML elements
|
||||
$('#searchTitles').on('click', function(e) {
|
||||
if (localArchive.language === "small" && !cookies.getItem("warned_small_archive")) {
|
||||
// The user selected the "small" archive, which is quite incomplete
|
||||
// So let's display a warning to the user
|
||||
alert("You selected the 'small' archive. This archive is OK for testing, but be aware that very few hyperlinks in the articles will work because it's only a very small subset of the English dump.");
|
||||
// We will not display this warning again for one day
|
||||
cookies.setItem("warned_small_archive",true,86400);
|
||||
}
|
||||
searchTitlesFromPrefix($('#prefix').val());
|
||||
});
|
||||
$('#formTitleSearch').on('submit', function(e) {
|
||||
|
68
js/lib/cookies.js
Normal file
68
js/lib/cookies.js
Normal file
@ -0,0 +1,68 @@
|
||||
define(function(require) {
|
||||
/*\
|
||||
|*|
|
||||
|*| :: cookies.js ::
|
||||
|*|
|
||||
|*| A complete cookies reader/writer framework with full unicode support.
|
||||
|*|
|
||||
|*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
|
||||
|*|
|
||||
|*| This framework is released under the GNU Public License, version 3 or later.
|
||||
|*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
||||
|*|
|
||||
|*| Syntaxes:
|
||||
|*|
|
||||
|*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
|
||||
|*| * docCookies.getItem(name)
|
||||
|*| * docCookies.removeItem(name[, path])
|
||||
|*| * docCookies.hasItem(name)
|
||||
|*| * docCookies.keys()
|
||||
|*|
|
||||
\*/
|
||||
|
||||
var docCookies = {
|
||||
getItem: function (sKey) {
|
||||
return unescape(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
|
||||
},
|
||||
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
|
||||
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
|
||||
var sExpires = "";
|
||||
if (vEnd) {
|
||||
switch (vEnd.constructor) {
|
||||
case Number:
|
||||
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
|
||||
break;
|
||||
case String:
|
||||
sExpires = "; expires=" + vEnd;
|
||||
break;
|
||||
case Date:
|
||||
sExpires = "; expires=" + vEnd.toGMTString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.cookie = escape(sKey) + "=" + escape(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
|
||||
return true;
|
||||
},
|
||||
removeItem: function (sKey, sPath) {
|
||||
if (!sKey || !this.hasItem(sKey)) { return false; }
|
||||
document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sPath ? "; path=" + sPath : "");
|
||||
return true;
|
||||
},
|
||||
hasItem: function (sKey) {
|
||||
return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
|
||||
},
|
||||
keys: /* optional method: you can safely remove it! */ function () {
|
||||
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
|
||||
for (var nIdx = 0; nIdx < aKeys.length; nIdx++) { aKeys[nIdx] = unescape(aKeys[nIdx]); }
|
||||
return aKeys;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
getItem: docCookies.getItem,
|
||||
setItem: docCookies.setItem,
|
||||
removeItem: docCookies.removeItem,
|
||||
hasItem: docCookies.hasItem,
|
||||
keys: docCookies.keys
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user