From 8049e93703ec3d680769b0459fdb0e6c03979dbf Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 22 Mar 2014 22:42:02 +0100 Subject: [PATCH] Use handlebars instead of mustache --- client/css/style.css | 3 ++- client/index.html | 23 +++++++++++++++++++---- client/js/chat.js | 23 +++++------------------ lib/server.js | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/client/css/style.css b/client/css/style.css index 3632c79..a72a0b5 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -200,7 +200,8 @@ h2 { #chat .message.part, #chat .message.nick, #chat .message.quit, -#chat .message.notice { +#chat .message.notice, +#chat .message.error { color: #999; } diff --git a/client/index.html b/client/index.html index 6456cbb..fb574a0 100644 --- a/client/index.html +++ b/client/index.html @@ -58,7 +58,12 @@ @@ -84,10 +89,20 @@
- {{> users}} + {{#each users}} + + {{mode}}{{name}} + + {{/each}}
- {{> messages}} + {{#each messages}} +
+ {{time}} + {{mode}}{{user}} + {{type}} {{text}} +
+ {{/each}}
@@ -116,7 +131,7 @@ - + diff --git a/client/js/chat.js b/client/js/chat.js index c0231bb..2aaab0d 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -10,18 +10,9 @@ $(function() { var sidebar = $("#sidebar"); var tpl = []; - function render(id, json, partials) { - tpl[id] = tpl[id] || $(id).html(); - if (!json) { - // If no data is supplied, return the template instead. - // Handy when fetching partials. - return tpl[id]; - } - return Mustache.render( - tpl[id], - json, - partials || {} - ); + function render(id, json) { + tpl[id] = tpl[id] || Handlebars.compile($(id).html()); + return tpl[id](json); } function event(type, json) { @@ -29,17 +20,13 @@ $(function() { case "NETWORKS": var html = ""; - var partials = { - messages: render("#message"), - users: render("#user") - }; json.forEach(function(network) { - html += render("#window", network, partials); + html += render("#window", network); }); $("#windows")[0].innerHTML = html; sidebar.find("#list").html( - render("#network", {networks: json}, {channels: render("#channel")}) + render("#network", {networks: json}) ).find(".channel") .first() .addClass("active"); diff --git a/lib/server.js b/lib/server.js index 694fe68..2f42232 100644 --- a/lib/server.js +++ b/lib/server.js @@ -507,7 +507,7 @@ function handleEvent(argv) { ); break; - case "001": // `registered` + case "001": // 'registered' event network.set("nick", argv.args[0]); case "rpl_motdstart": case "rpl_endofmotd":