hardlounge/client/js/shout.js

117 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-06-26 16:14:45 +00:00
$(function() {
2014-06-27 00:47:36 +00:00
new Shout();
2014-06-26 16:14:45 +00:00
});
2014-06-27 00:47:36 +00:00
function Shout() {
var client = this;
var socket = io();
var events = [
"auth",
"init",
"join",
"msg",
"network",
"nick",
"part",
"quit",
"users"
].forEach(function(e) {
2014-06-29 01:07:38 +00:00
client[e].call(client, socket);
2014-06-27 00:47:36 +00:00
});
}
Shout.prototype.auth = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("auth", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.init = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("init", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.join = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("join", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.msg = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("msg", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.network = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("network", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.nick = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("nick", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.part = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("part", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.quit = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("quit", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
Shout.prototype.users = function(socket) {
2014-06-29 01:07:38 +00:00
socket.on("users", function(data) {
console.log(data);
2014-06-27 00:47:36 +00:00
});
};
var tpl = [];
function render(name, data) {
tpl[name] = tpl[name] || Handlebars.compile($("#templates ." + name).html());
return tpl[name](data);
}
function escape(text) {
var e = {
"<": "&lt;",
">": "&gt;"
};
return text.replace(/[<>]/g, function (c) {
return e[c];
});
}
Handlebars.registerHelper(
"partial", function(id) {
return new Handlebars.SafeString(render(id, this));
}
);
Handlebars.registerHelper(
"uri", function(text) {
var urls = [];
text = URI.withinString(text, function(url) {
urls.push(url);
return "$(" + (urls.length - 1) + ")";
});
text = escape(text);
for (var i in urls) {
var url = escape(urls[i]);
text = text.replace(
"$(" + i + ")",
"<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>"
);
}
return text;
}
);