0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-26 13:14:49 +00:00
healthchecks_healthchecks/static/js/snippet-copy.js
Pēteris Caune 67560c96e1
Change icon CSS class prefix to work around Fanboy's filter list
Problem: if you use uBlock Origin, and enable the
"Fanboy's Social" filter list, Healthchecks does not show
Telegram or WhatsApp icons. This is because the filter list
contains "##.icon-telegram" and "##.icon-whatsapp" entries.

This commit changes the CSS class prefix to "ic-". So we're
now using icon classes like "ic-telegram" and "ic-whatsapp".

As a bonus, we save 2 bytes in HTML per displayed icon :-)
2021-02-03 10:44:35 +02:00

41 lines
1.2 KiB
JavaScript

$(function() {
if (/Mac/i.test(navigator.userAgent)) {
// No support for Safari :(
return;
}
var markup = '<button class="btn btn-default hidden-sm">' +
'<span class="ic-clippy"></span>' +
'</button>';
$(".highlight").append(markup);
var reBlankLines = new RegExp("^\\s*[\\r\\n]", "gm");
var reTrailingWhitespace = new RegExp("\\s+$");
var clipboard = new Clipboard(".highlight button", {
text: function (trigger) {
var snippetElement = $(trigger).parent().children().clone();
/* remove pygmentize comment elements */
snippetElement.find(".c, .cm, .cp, .c1, .cs").remove();
/* remove blank lines and trailing whitespace */
return snippetElement.text().replace(reBlankLines, '').replace(reTrailingWhitespace, '');
}
});
clipboard.on("success", function(e) {
$(e.trigger)
.tooltip({title: "Copied!", trigger: "hover"})
.tooltip("show")
.on("hidden.bs.tooltip", function(){
$(this).tooltip("destroy");
})
});
clipboard.on("error", function(e) {
prompt("Press Ctrl+C to select:", e.text)
});
});