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

View file

@ -1,7 +1,7 @@
{ {
"name": "shout", "name": "shout",
"description": "A web IRC client", "description": "A web IRC client",
"version": "0.21.3", "version": "0.21.4",
"author": "Mattias Erming", "author": "Mattias Erming",
"preferGlobal": true, "preferGlobal": true,
"bin": { "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() { Client.prototype.quit = function() {
this.networks.forEach(function(network) { this.networks.forEach(function(network) {
var irc = network.irc; var irc = network.irc;

View file

@ -65,9 +65,9 @@ function init(socket, client) {
} }
); );
socket.on( socket.on(
"showMore", "more",
function(data) { function(data) {
showMore(client, data); client.more(data);
} }
); );
socket.on( 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
});
}