From 6422709551f27336879a67adab43a974723a4a00 Mon Sep 17 00:00:00 2001 From: Mossroy Date: Tue, 6 Aug 2013 09:55:27 +0200 Subject: [PATCH] Display a warning to the user if the "small" archive has been selected Fixes #48 --- js/app.js | 8 ++++++ js/lib/cookies.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 js/lib/cookies.js diff --git a/js/app.js b/js/app.js index b7509a50..4137d453 100644 --- a/js/app.js +++ b/js/app.js @@ -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) { diff --git a/js/lib/cookies.js b/js/lib/cookies.js new file mode 100644 index 00000000..0b72ef88 --- /dev/null +++ b/js/lib/cookies.js @@ -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 + }; +}); \ No newline at end of file