Added custom events

This commit is contained in:
Mattias Erming 2014-03-11 23:57:29 +01:00
parent 9ae50727ec
commit f86f67ff24
3 changed files with 22 additions and 15 deletions

View File

@ -101,7 +101,7 @@ $(function() {
}; };
$.fn.scrollToBottom = function() { $.fn.scrollToBottom = function() {
this.scrollTop(this.prop("scrollHeight")); this.scrollTop(1e10);
}; };
$.fn.isScrollAtBottom = function() { $.fn.isScrollAtBottom = function() {

View File

@ -45,19 +45,19 @@ models.Channel = Backbone.Model.extend({
this.set("users", new models.UserCollection()); this.set("users", new models.UserCollection());
this.get("users").on( this.get("users").on(
"all", "all",
function() { function(e) {
// Bubble event // Bubble event
this.trigger("change", this); this.trigger("user", this);
}, },
this this
); );
this.set("messages", new models.MessageCollection()); this.set("messages", new models.MessageCollection());
this.get("messages").on( this.get("messages").on(
"all", "add",
function() { function() {
// Bubble event // Bubble event
this.trigger("change", this); this.trigger("message", this);
}, },
this this
); );
@ -82,9 +82,9 @@ models.Network = Backbone.Model.extend({
this.set("channels", new models.ChannelCollection()); this.set("channels", new models.ChannelCollection());
this.get("channels").on( this.get("channels").on(
"all", "all",
function() { function(type) {
// Bubble event // Bubble event
this.trigger("change", this); this.trigger(type == "user" || type == "message" ? type : "channel", this);
}, },
this this
); );

View File

@ -17,14 +17,18 @@ Server.prototype.listen = function(port) {
.use(connect.static("client")) .use(connect.static("client"))
.listen(port); .listen(port);
this.sockets = io.listen(http).sockets; this.networks.on(
this.sockets.on("connection", function(socket) {
self.networks.on(
"all", "all",
function() { function(type) {
self.sockets.emit("event", self.networks); self.sockets.emit("event", self.networks);
// Debug
console.log(type);
} }
); );
this.sockets = io.listen(http, {log: false}).sockets;
this.sockets.on("connection", function(socket) {
socket.emit( socket.emit(
"event", "event",
self.networks self.networks
@ -92,4 +96,7 @@ function handleEvent(argv) {
text: argv.args[1] text: argv.args[1]
}) })
); );
// Debug
console.log(argv);
} }