add some documentation

This commit is contained in:
Martin Zimmermann 2013-11-16 21:41:54 +01:00
parent 320cb7313f
commit 519112a8fc

View File

@ -22,7 +22,8 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
} }
}); });
// update identicon, when the user provices an email address // update identicon on email input. Listens on keyup, after 200ms the
// new identicon is generated.
var active; var active;
$(".input-wrapper > [type=email]", el).on("keyup", function() { $(".input-wrapper > [type=email]", el).on("keyup", function() {
if (active) { if (active) {
@ -40,6 +41,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
clearTimeout(active); clearTimeout(active);
}, false); }, false);
// callback on success (e.g. to toggle the reply button)
el.onsuccess = function() {}; el.onsuccess = function() {};
el.validate = function() { el.validate = function() {
@ -50,6 +52,8 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
return true; return true;
}; };
// submit form, initialize optional fields with `null` and reset form.
// If replied to a comment, remove form completely.
$("[type=submit]", el).on("click", function() { $("[type=submit]", el).on("click", function() {
if (! el.validate()) { if (! el.validate()) {
return; return;
@ -75,11 +79,13 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
}); });
}); });
// copy'n'paste sluggy automagically dynamic textarea resize
fancy.autoresize($("textarea", el), 48); fancy.autoresize($("textarea", el), 48);
return el; return el;
}; };
// lookup table for responses (to link to the parent)
var map = {id: {}, name: {}}; var map = {id: {}, name: {}};
var insert = function(comment, scrollIntoView) { var insert = function(comment, scrollIntoView) {
@ -91,10 +97,15 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
var el = $.htmlify(Mark.up(templates["comment"], comment)); var el = $.htmlify(Mark.up(templates["comment"], comment));
// update datetime every 60 seconds
var refresh = function() { var refresh = function() {
$(".permalink > date", el).textContent = utils.ago(new Date(parseInt(comment.created, 10) * 1000)); $(".permalink > date", el).textContent = utils.ago(
new Date(parseInt(comment.created, 10) * 1000));
setTimeout(refresh, 60*1000); setTimeout(refresh, 60*1000);
}; refresh(); };
// run once to activate
refresh();
$("div.avatar > svg", el).replace(lib.identicons.generate(comment.hash, 4, 48)); $("div.avatar > svg", el).replace(lib.identicons.generate(comment.hash, 4, 48));
@ -120,7 +131,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
header = $("#isso-" + comment.id + " > .text-wrapper > .isso-comment-header"), header = $("#isso-" + comment.id + " > .text-wrapper > .isso-comment-header"),
text = $("#isso-" + comment.id + " > .text-wrapper > .text"); text = $("#isso-" + comment.id + " > .text-wrapper > .text");
var form = null; var form = null; // XXX: probably a good place for a closure
$("a.reply", footer).toggle("click", $("a.reply", footer).toggle("click",
function(toggler) { function(toggler) {
form = footer.insertAfter(new Postbox(comment.id)); form = footer.insertAfter(new Postbox(comment.id));
@ -143,12 +154,12 @@ define(["app/text/html", "app/dom", "app/utils", "app/api", "app/markup", "app/i
}); });
} }
// update vote counter, but hide if votes sum to 0
var votes = function(value) { var votes = function(value) {
var span = $("span.votes", footer); var span = $("span.votes", footer);
if (span === null) { if (span === null) {
if (value === 0) { if (value === 0) {
span.remove(); span.remove();
return;
} else { } else {
footer.prepend($.new("span.votes", value)); footer.prepend($.new("span.votes", value));
} }