From d21aed83f8c72ebab94a147ef4d8a200984971b0 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Mon, 11 Aug 2014 12:48:55 +0200 Subject: [PATCH] save name, email and website in localStorage, closes #119 --- isso/js/app/isso.js | 21 ++++++++++++++------- isso/js/app/text/postbox.jade | 9 ++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 168e3ea..603f27e 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -7,7 +7,11 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n", var Postbox = function(parent) { - var el = $.htmlify(jade.render("postbox")); + var el = $.htmlify(jade.render("postbox", { + "author": JSON.parse(localStorage.getItem("author")), + "email": JSON.parse(localStorage.getItem("email")), + "website": JSON.parse(localStorage.getItem("website")) + })); // callback on success (e.g. to toggle the reply button) el.onsuccess = function() {}; @@ -29,16 +33,19 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n", return; } + var author = $("[name=author]", el).value || null, + email = $("[name=email]", el).value || null, + website = $("[name=website]", el).value || null; + + localStorage.setItem("author", JSON.stringify(author)); + localStorage.setItem("email", JSON.stringify(email)); + localStorage.setItem("website", JSON.stringify(website)); + api.create($("#isso-thread").getAttribute("data-isso-id"), { - author: $("[name=author]", el).value || null, - email: $("[name=email]", el).value || null, - website: $("[name=website]", el).value || null, + author: author, email: email, website: website, text: utils.text($(".textarea", el).innerHTML), parent: parent || null }).then(function(comment) { - $("[name=author]", el).value = ""; - $("[name=email]", el).value = ""; - $("[name=website]", el).value = ""; $(".textarea", el).innerHTML = ""; $(".textarea", el).blur(); insert(comment, true); diff --git a/isso/js/app/text/postbox.jade b/isso/js/app/text/postbox.jade index a2428de..0a85ae1 100644 --- a/isso/js/app/text/postbox.jade +++ b/isso/js/app/text/postbox.jade @@ -5,10 +5,13 @@ div(class='isso-postbox') = i18n('postbox-text') section(class='auth-section') p(class='input-wrapper') - input(type='text' name='author' placeholder=i18n('postbox-author')) + input(type='text' name='author' placeholder=i18n('postbox-author') + value=author !== null ? '#{author}' : '') p(class='input-wrapper') - input(type='email' name='email' placeholder=i18n('postbox-email')) + input(type='email' name='email' placeholder=i18n('postbox-email') + value=email != null ? '#{email}' : '') p(class='input-wrapper') - input(type='text' name='website' placeholder=i18n('postbox-website')) + input(type='text' name='website' placeholder=i18n('postbox-website') + value=website != null ? '#{website}' : '') p(class='post-action') input(type='submit' value=i18n('postbox-submit'))