Added custom events
This commit is contained in:
parent
9ae50727ec
commit
f86f67ff24
|
@ -101,7 +101,7 @@ $(function() {
|
|||
};
|
||||
|
||||
$.fn.scrollToBottom = function() {
|
||||
this.scrollTop(this.prop("scrollHeight"));
|
||||
this.scrollTop(1e10);
|
||||
};
|
||||
|
||||
$.fn.isScrollAtBottom = function() {
|
||||
|
|
|
@ -45,19 +45,19 @@ models.Channel = Backbone.Model.extend({
|
|||
this.set("users", new models.UserCollection());
|
||||
this.get("users").on(
|
||||
"all",
|
||||
function() {
|
||||
function(e) {
|
||||
// Bubble event
|
||||
this.trigger("change", this);
|
||||
this.trigger("user", this);
|
||||
},
|
||||
this
|
||||
);
|
||||
|
||||
this.set("messages", new models.MessageCollection());
|
||||
this.get("messages").on(
|
||||
"all",
|
||||
"add",
|
||||
function() {
|
||||
// Bubble event
|
||||
this.trigger("change", this);
|
||||
this.trigger("message", this);
|
||||
},
|
||||
this
|
||||
);
|
||||
|
@ -82,9 +82,9 @@ models.Network = Backbone.Model.extend({
|
|||
this.set("channels", new models.ChannelCollection());
|
||||
this.get("channels").on(
|
||||
"all",
|
||||
function() {
|
||||
function(type) {
|
||||
// Bubble event
|
||||
this.trigger("change", this);
|
||||
this.trigger(type == "user" || type == "message" ? type : "channel", this);
|
||||
},
|
||||
this
|
||||
);
|
||||
|
|
|
@ -16,15 +16,19 @@ Server.prototype.listen = function(port) {
|
|||
var http = connect()
|
||||
.use(connect.static("client"))
|
||||
.listen(port);
|
||||
|
||||
this.sockets = io.listen(http).sockets;
|
||||
|
||||
this.networks.on(
|
||||
"all",
|
||||
function(type) {
|
||||
self.sockets.emit("event", self.networks);
|
||||
|
||||
// Debug
|
||||
console.log(type);
|
||||
}
|
||||
);
|
||||
|
||||
this.sockets = io.listen(http, {log: false}).sockets;
|
||||
this.sockets.on("connection", function(socket) {
|
||||
self.networks.on(
|
||||
"all",
|
||||
function() {
|
||||
self.sockets.emit("event", self.networks);
|
||||
}
|
||||
);
|
||||
socket.emit(
|
||||
"event",
|
||||
self.networks
|
||||
|
@ -92,4 +96,7 @@ function handleEvent(argv) {
|
|||
text: argv.args[1]
|
||||
})
|
||||
);
|
||||
|
||||
// Debug
|
||||
console.log(argv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue