Disable copy code button in insecure contexts (#1226)

Implements point (2a) of https://github.com/just-the-docs/just-the-docs/issues/1202

## Secure context - behaviour unchanged

![image](https://user-images.githubusercontent.com/3671582/232823898-1b683b51-20ca-4e79-91cc-d543ae76aacd.png)

## Unsecure context - copy icon not shown and console message logged

![image](https://user-images.githubusercontent.com/3671582/232823972-94e2ef83-e526-4ca3-b16f-5f0f4243b50c.png)
This commit is contained in:
Robin Moffatt 2023-04-22 21:38:02 +01:00 committed by GitHub
parent d107faaff4
commit 7daf042a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -488,6 +488,11 @@ jtd.onReady(function(){
jtd.onReady(function(){
if (!window.isSecureContext) {
console.log('Window does not have a secure context, therefore code clipboard copy functionality will not be available. For more details see https://web.dev/async-clipboard/#security-and-permissions');
return;
}
var codeBlocks = document.querySelectorAll('div.highlighter-rouge, div.listingblock > div.content, figure.highlight');
// note: the SVG svg-copied and svg-copy is only loaded as a Jekyll include if site.enable_copy_code_button is true; see _includes/icons/icons.html