Better URL parse with jQuery

This commit is contained in:
Mattias Erming 2014-04-14 02:39:34 +02:00
parent 421f585d23
commit 56956ec85a
2 changed files with 22 additions and 17 deletions

View File

@ -92,6 +92,9 @@ h2 {
right: 0; right: 0;
top: 0; top: 0;
} }
#chat a {
color: inherit;
}
#chat form { #chat form {
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
bottom: 1px; bottom: 1px;

View File

@ -53,8 +53,10 @@ $(function() {
users: render("#user"), users: render("#user"),
messages: render("#message"), messages: render("#message"),
}; };
json.forEach(function(network) { json.forEach(function(n) {
html += render("#window", network, partials); html += render(
"#window", n, partials
);
}); });
$("#windows")[0].innerHTML = html; $("#windows")[0].innerHTML = html;
@ -62,13 +64,12 @@ $(function() {
render("#network", {networks: json}, {channels: render("#channel")}) render("#network", {networks: json}, {channels: render("#channel")})
).find(".channel") ).find(".channel")
.first() .first()
.addClass("active"); .addClass("active")
.end();
chat.find(".messages") chat.find(".messages")
.scrollGlue({animate: 400}) .scrollGlue({animate: 400})
.scrollToBottom() .scrollToBottom()
.find(".text")
.uri()
.end(); .end();
chat.find(".window") chat.find(".window")
.find("input") .find("input")
@ -129,9 +130,6 @@ $(function() {
} }
var msg = $(render("#message", {messages: message})) var msg = $(render("#message", {messages: message}))
.find(".text")
.uri()
.end();
target = target.find(".messages"); target = target.find(".messages");
target.append(msg); target.append(msg);
@ -246,6 +244,19 @@ $(function() {
$(this).closest(".window").find(".messages").scrollToBottom(); $(this).closest(".window").find(".messages").scrollToBottom();
}); });
chat.on("mouseover", ".text", function() {
var self = $(this);
if (!self.hasClass("parsed")) {
self.addClass("parsed").html(uri(self.html()));
}
});
function uri(text) {
return URI.withinString(text, function(url) {
return "<a href='" + url + "' target='_blank'>" + url + "</a>";
});
}
var highest = 1; var highest = 1;
$.fn.bringToTop = function() { $.fn.bringToTop = function() {
return this.css('z-index', highest++) return this.css('z-index', highest++)
@ -257,13 +268,4 @@ $(function() {
.removeClass("active") .removeClass("active")
.end(); .end();
}; };
$.fn.uri = function() {
return this.each(function() {
var html = $(this).html();
return $(this).html(URI.withinString(html, function(url) {
return "<a href='" + url + "' target='_blank'>" + url + "</a>";
}));
});
};
}); });