aboutsummaryrefslogtreecommitdiffstats
path: root/importAddrBook.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-05-22 23:52:43 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-05-22 23:53:34 +0200
commitfb35a5e541342cdf9f73961c575c123f00dac79a (patch)
treea5a9d4f32c1be7553106ba599b56cd24f5b3f67a /importAddrBook.js
parentbb2685eed25e1f347188c6dfc32d5756adf3d006 (diff)
downloadimportLDIF-fb35a5e541342cdf9f73961c575c123f00dac79a.tar.gz
Add storage of the last URL to the localStorage.
Fixes #102
Diffstat (limited to 'importAddrBook.js')
-rw-r--r--importAddrBook.js69
1 files changed, 39 insertions, 30 deletions
diff --git a/importAddrBook.js b/importAddrBook.js
index 75c45df..83256c4 100644
--- a/importAddrBook.js
+++ b/importAddrBook.js
@@ -307,46 +307,55 @@
}
+ function submitHandler (evt) {
+ var URL = document.getElementsByName("URL")[0].value;
+ var progressForm = document.getElementById("progress-div");
+ document.getElementById("URL-form").style.display = "none";
+ progressForm.style.display = "block";
- window.onload = function() {
- document.body.addEventListener("submit",
- function(evt) {
+ var req = new XMLHttpRequest();
+ req.open("GET", URL, true);
+ var progressEl = progressForm.getElementsByTagName("progress")[0];
- var URL = document.getElementsByName("URL")[0].value;
- var progressForm = document.getElementById("progress-div");
+ req.onprogress = function(evt) {
+ if (evt.lengthComputable) {
+ progressEl.max = evt.total;
+ progressEl.value = evt.loaded;
+ }
+ };
- document.getElementById("URL-form").style.display = "none";
- progressForm.style.display = "block";
+ req.onload = function() {
+ var inText = req.responseText;
+ if (inText.length > 0) {
+ insertData(inText);
- var req = new XMLHttpRequest();
- req.open("GET", URL, true);
- var progressEl = progressForm.getElementsByTagName("progress")[0];
+ if (localStorage) {
+ localStorage.setItem("lastURL", URL);
+ }
- req.onprogress = function(evt) {
- if (evt.lengthComputable) {
- progressEl.max = evt.total;
- progressEl.value = evt.loaded;
- }
- };
+ }
+ };
- req.onload = function() {
- var inText = req.responseText;
- if (inText.length > 0) {
- insertData(inText);
- }
- };
+ req.onerror = function() {
+ window.alert("Cannot load " + URL + "!");
+ restoreURLForm(URL);
+ };
- req.onerror = function() {
- window.alert("Cannot load " + URL + "!");
- restoreURLForm(URL);
- };
+ req.send();
+
+ evt.stopPropagation();
+ evt.preventDefault();
+ }
- req.send();
+ window.onload = function() {
+ if (localStorage && localStorage.lastURL) {
+ var oldURL = localStorage.getItem('lastURL');
+ document.getElementsByName("URL")[0].value = oldURL;
+ }
- evt.stopPropagation();
- evt.preventDefault();
- }, false);
+ document.body.addEventListener("submit",
+ submitHandler, false);
};
}());