Better 'Show more' implementation

This commit is contained in:
Mattias Erming 2014-06-14 22:28:17 +02:00
parent d2c7c72c38
commit 0f456596ed
3 changed files with 28 additions and 11 deletions

View File

@ -63,9 +63,11 @@
</ul> </ul>
</div> </div>
<div class="chat"> <div class="chat">
{{#equal <%= messages %> messages.length}}
<button class="show-more" data-id="{{id}}"> <button class="show-more" data-id="{{id}}">
Show more Show more
</button> </button>
{{/equal}}
<div class="messages"> <div class="messages">
{{partial "messages"}} {{partial "messages"}}
</div> </div>

View File

@ -65,7 +65,7 @@ $(function() {
.sticky() .sticky()
.end() .end()
.find(".input") .find(".input")
.tabcomplete(commands, {hint: false}) .tabcomplete(complete, {hint: false})
.history(); .history();
$("#network-" + data.id) $("#network-" + data.id)
@ -97,16 +97,12 @@ $(function() {
case "networks": case "networks":
var channels = $.map(data.networks, function(n) { return n.channels; }); var channels = $.map(data.networks, function(n) { return n.channels; });
chat.html(render("windows", {windows: channels})) chat.html(render("windows", {windows: channels}))
.find(".input") .find(".chat")
.tabcomplete(commands, {hint: false})
.history()
.end()
.find(".hidden")
.prev(".show-more")
.show();
chat.find(".chat")
.sticky() .sticky()
.end(); .end()
.find(".input")
.tabcomplete(complete, {hint: false})
.history();
var networks = $("#networks") var networks = $("#networks")
.html(render("networks", {networks: data.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) { function toArray(val) {
return Array.isArray(val) ? val : [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( Handlebars.registerHelper(
"uri", function(text) { "uri", function(text) {
text = escape(text); text = escape(text);

View File

@ -61,7 +61,7 @@ function index(req, res, next) {
fs.readFile("client/index.html", function(err, file) { fs.readFile("client/index.html", function(err, file) {
var data = _.merge( var data = _.merge(
require("../package.json"), require("../package.json"),
{} // config config
); );
res.end(_.template( res.end(_.template(
file, file,