From 0f456596ed8795479212fc325484fb3ca122ccd3 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 14 Jun 2014 22:28:17 +0200 Subject: [PATCH] Better 'Show more' implementation --- client/index.html | 2 ++ client/js/chat.js | 35 +++++++++++++++++++++++++---------- lib/server.js | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/client/index.html b/client/index.html index 048b0b75..9a988191 100644 --- a/client/index.html +++ b/client/index.html @@ -63,9 +63,11 @@
+ {{#equal <%= messages %> messages.length}} + {{/equal}}
{{partial "messages"}}
diff --git a/client/js/chat.js b/client/js/chat.js index 0f655dbb..f043f518 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -65,7 +65,7 @@ $(function() { .sticky() .end() .find(".input") - .tabcomplete(commands, {hint: false}) + .tabcomplete(complete, {hint: false}) .history(); $("#network-" + data.id) @@ -97,16 +97,12 @@ $(function() { case "networks": var channels = $.map(data.networks, function(n) { return n.channels; }); chat.html(render("windows", {windows: channels})) - .find(".input") - .tabcomplete(commands, {hint: false}) - .history() - .end() - .find(".hidden") - .prev(".show-more") - .show(); - chat.find(".chat") + .find(".chat") .sticky() - .end(); + .end() + .find(".input") + .tabcomplete(complete, {hint: false}) + .history(); var networks = $("#networks") .html(render("networks", {networks: data.networks})) @@ -294,6 +290,15 @@ $(function() { }); + function complete(word) { + return $.grep( + commands, + function(cmd) { + return !cmd.indexOf(word); + } + ); + } + function toArray(val) { return Array.isArray(val) ? val : [val]; } @@ -308,6 +313,16 @@ $(function() { }); } + Handlebars.registerHelper( + "equal", function(a, b, opt) { + a = parseInt(a); + b = parseInt(b); + if (a == b) { + return opt.fn(this); + } + } + ); + Handlebars.registerHelper( "uri", function(text) { text = escape(text); diff --git a/lib/server.js b/lib/server.js index 0a263d06..239d45f9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -61,7 +61,7 @@ function index(req, res, next) { fs.readFile("client/index.html", function(err, file) { var data = _.merge( require("../package.json"), - {} // config + config ); res.end(_.template( file,