Merge pull request #445 from thelounge/xpaw/single-network-func

Create a single function to render networks to reduce code duplication
This commit is contained in:
Jérémie Astori 2016-07-23 00:33:14 -04:00 committed by GitHub
commit 179698887d
2 changed files with 31 additions and 36 deletions

View File

@ -140,26 +140,7 @@ $(function() {
if (data.networks.length === 0) { if (data.networks.length === 0) {
$("#footer").find(".connect").trigger("click"); $("#footer").find(".connect").trigger("click");
} else { } else {
sidebar.find(".empty").hide(); renderNetworks(data);
sidebar.find(".networks").html(
render("network", {
networks: data.networks
})
);
var channels = $.map(data.networks, function(n) {
return n.channels;
});
chat.html(
render("chat", {
channels: channels
})
);
channels.forEach(renderChannel);
confirmExit();
if (sidebar.find(".highlight").length) {
toggleNotificationMarkers(true);
}
} }
if (data.token && $("#sign-in-remember").is(":checked")) { if (data.token && $("#sign-in-remember").is(":checked")) {
@ -182,8 +163,6 @@ $(function() {
$("#footer").find(".connect").trigger("click"); $("#footer").find(".connect").trigger("click");
} }
} }
sortable();
}); });
socket.on("join", function(data) { socket.on("join", function(data) {
@ -325,6 +304,32 @@ $(function() {
users.html(render("user", data)).data("nicks", nicks); users.html(render("user", data)).data("nicks", nicks);
} }
function renderNetworks(data) {
sidebar.find(".empty").hide();
sidebar.find(".networks").append(
render("network", {
networks: data.networks
})
);
var channels = $.map(data.networks, function(n) {
return n.channels;
});
chat.append(
render("chat", {
channels: channels
})
);
channels.forEach(renderChannel);
confirmExit();
sortable();
if (sidebar.find(".highlight").length) {
toggleNotificationMarkers(true);
}
}
socket.on("msg", function(data) { socket.on("msg", function(data) {
var msg = buildChatMessage(data); var msg = buildChatMessage(data);
var target = "#chan-" + data.chan; var target = "#chan-" + data.chan;
@ -357,26 +362,16 @@ $(function() {
}); });
socket.on("network", function(data) { socket.on("network", function(data) {
sidebar.find(".empty").hide(); renderNetworks(data);
sidebar.find(".networks").append(
render("network", {
networks: [data.network]
})
);
chat.append(
render("chat", {
channels: data.network.channels
})
);
sidebar.find(".chan") sidebar.find(".chan")
.last() .last()
.trigger("click"); .trigger("click");
$("#connect") $("#connect")
.find(".btn") .find(".btn")
.prop("disabled", false) .prop("disabled", false)
.end(); .end();
confirmExit();
sortable();
}); });
socket.on("network_changed", function(data) { socket.on("network_changed", function(data) {

View File

@ -189,7 +189,7 @@ Client.prototype.connect = function(args) {
client.networks.push(network); client.networks.push(network);
client.emit("network", { client.emit("network", {
network: network networks: [network]
}); });
if (config.lockNetwork) { if (config.lockNetwork) {