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;
top: 0;
}
#chat a {
color: inherit;
}
#chat form {
border-top: 1px solid #ddd;
bottom: 1px;

View File

@ -53,8 +53,10 @@ $(function() {
users: render("#user"),
messages: render("#message"),
};
json.forEach(function(network) {
html += render("#window", network, partials);
json.forEach(function(n) {
html += render(
"#window", n, partials
);
});
$("#windows")[0].innerHTML = html;
@ -62,13 +64,12 @@ $(function() {
render("#network", {networks: json}, {channels: render("#channel")})
).find(".channel")
.first()
.addClass("active");
.addClass("active")
.end();
chat.find(".messages")
.scrollGlue({animate: 400})
.scrollToBottom()
.find(".text")
.uri()
.end();
chat.find(".window")
.find("input")
@ -129,9 +130,6 @@ $(function() {
}
var msg = $(render("#message", {messages: message}))
.find(".text")
.uri()
.end();
target = target.find(".messages");
target.append(msg);
@ -245,6 +243,19 @@ $(function() {
chat.on("focus", "input[type=text]", function() {
$(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;
$.fn.bringToTop = function() {
@ -257,13 +268,4 @@ $(function() {
.removeClass("active")
.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>";
}));
});
};
});