mirror of
https://github.com/thelounge/thelounge
synced 2024-11-15 00:37:13 +00:00
37 lines
799 B
JavaScript
37 lines
799 B
JavaScript
Handlebars.registerHelper(
|
|
"slice", function(items, block) {
|
|
var limit = block.hash.limit;
|
|
var rows = [];
|
|
items.forEach(function(i) {
|
|
rows.push(block.fn(i));
|
|
});
|
|
var html = "";
|
|
var hidden = rows
|
|
.slice(0, Math.max(0, rows.length - limit))
|
|
.join("");
|
|
if (hidden != "") {
|
|
html = "<script type='text/html' class='hidden'>" + hidden + "</script>";
|
|
}
|
|
html += rows.slice(-limit).join("");
|
|
return html;
|
|
}
|
|
);
|
|
|
|
function escape(text) {
|
|
var e = {
|
|
"<": "<",
|
|
">": ">"
|
|
};
|
|
return text.replace(/[<>]/g, function (c) {
|
|
return e[c];
|
|
});
|
|
}
|
|
|
|
Handlebars.registerHelper(
|
|
"uri", function(text) {
|
|
text = escape(text);
|
|
return URI.withinString(text, function(url) {
|
|
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
|
|
});
|
|
}
|
|
);
|