save name, email and website in localStorage, closes #119

This commit is contained in:
Martin Zimmermann 2014-08-11 12:48:55 +02:00
parent d9098b83f0
commit d21aed83f8
2 changed files with 20 additions and 10 deletions

View File

@ -7,7 +7,11 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
var Postbox = function(parent) { 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) // callback on success (e.g. to toggle the reply button)
el.onsuccess = function() {}; el.onsuccess = function() {};
@ -29,16 +33,19 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
return; 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"), { api.create($("#isso-thread").getAttribute("data-isso-id"), {
author: $("[name=author]", el).value || null, author: author, email: email, website: website,
email: $("[name=email]", el).value || null,
website: $("[name=website]", el).value || null,
text: utils.text($(".textarea", el).innerHTML), text: utils.text($(".textarea", el).innerHTML),
parent: parent || null parent: parent || null
}).then(function(comment) { }).then(function(comment) {
$("[name=author]", el).value = "";
$("[name=email]", el).value = "";
$("[name=website]", el).value = "";
$(".textarea", el).innerHTML = ""; $(".textarea", el).innerHTML = "";
$(".textarea", el).blur(); $(".textarea", el).blur();
insert(comment, true); insert(comment, true);

View File

@ -5,10 +5,13 @@ div(class='isso-postbox')
= i18n('postbox-text') = i18n('postbox-text')
section(class='auth-section') section(class='auth-section')
p(class='input-wrapper') 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') 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') 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') p(class='post-action')
input(type='submit' value=i18n('postbox-submit')) input(type='submit' value=i18n('postbox-submit'))