Fix the 'Show More' button

This commit is contained in:
Mattias Erming 2014-09-10 12:23:56 -07:00
parent 37b68b7bc4
commit 05a51f74a7
5 changed files with 33 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@ $(function() {
var sidebar = $("#sidebar");
var chat = $("#chat");
try {
var pop = new Audio();
pop.src = "/audio/pop.ogg";
@ -152,15 +152,18 @@ $(function() {
]);
});
socket.on("showMore", function(data) {
socket.on("more", function(data) {
var target = data.chan;
chat.find("#chan-" + target)
.find(".show-more")
.remove()
.end()
var chan = chat
.find("#chan-" + target)
.find(".messages")
.prepend(render("msg", {messages: data.messages}))
.end();
if (data.messages.length != 100) {
var more = chan
.find(".show-more")
.remove();
}
});
socket.on("network", function(data) {
@ -264,7 +267,7 @@ $(function() {
var input = $("#input")
.history()
.tab(complete, {hint: false});
var form = $("#form").on("submit", function(e) {
e.preventDefault();
var text = input.val();
@ -311,7 +314,7 @@ $(function() {
.find(".chat")
.sticky()
.end();
if (screen.width > 768 && chan.hasClass("chan")) {
input.focus();
}
@ -387,7 +390,7 @@ $(function() {
if (btn.length === 0) {
return;
}
var ignore = [
"join",
"part",
@ -412,7 +415,7 @@ $(function() {
var self = $(this);
var id = self.data("id");
var count = self.next(".messages").children().length;
socket.emit("showMore", {
socket.emit("more", {
target: id,
count: count
});
@ -476,7 +479,7 @@ $(function() {
var i = Math.max(0, index - 1);
channels.eq(i).click();
break;
case "down":
var i = Math.min(channels.length, index + 1);
channels.eq(i).click();

View File

@ -1,7 +1,7 @@
{
"name": "shout",
"description": "A web IRC client",
"version": "0.21.3",
"version": "0.21.4",
"author": "Mattias Erming",
"preferGlobal": true,
"bin": {

View File

@ -193,6 +193,21 @@ Client.prototype.input = function(data) {
});
}
Client.prototype.more = function(data) {
var client = this;
var target = client.find(data.target);
if (!target) {
return;
}
var chan = target.chan;
var count = chan.messages.length - (data.count || 0);
var messages = chan.messages.slice(Math.max(0, count - 100), count);
client.emit("more", {
chan: chan.id,
messages: messages
});
}
Client.prototype.quit = function() {
this.networks.forEach(function(network) {
var irc = network.irc;

View File

@ -65,9 +65,9 @@ function init(socket, client) {
}
);
socket.on(
"showMore",
"more",
function(data) {
showMore(client, data);
client.more(data);
}
);
socket.on(
@ -106,16 +106,3 @@ function auth(data) {
}
}
}
function showMore(client, data) {
var target = client.find(data.target);
if (!target) {
return;
}
var chan = target.chan;
var messages = chan.messages.slice(0, chan.messages.length - (data.count || 0));
client.emit("showMore", {
chan: chan.id,
messages: messages
});
}