mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
deploy: e954b34676
This commit is contained in:
@@ -58,7 +58,7 @@ function initSearch() {
|
||||
request.onload = function(){
|
||||
if (request.status >= 200 && request.status < 400) {
|
||||
var docs = JSON.parse(request.responseText);
|
||||
|
||||
|
||||
lunr.tokenizer.separator = /[\s\-/]+/
|
||||
|
||||
var index = lunr(function(){
|
||||
@@ -69,6 +69,7 @@ function initSearch() {
|
||||
this.metadataWhitelist = ['position']
|
||||
|
||||
for (var i in docs) {
|
||||
|
||||
this.add({
|
||||
id: i,
|
||||
title: docs[i].title,
|
||||
@@ -197,6 +198,7 @@ function searchLoaded(index, docs) {
|
||||
resultTitle.classList.add('search-result-title');
|
||||
resultLink.appendChild(resultTitle);
|
||||
|
||||
// note: the SVG svg-doc is only loaded as a Jekyll include if site.search_enabled is true; see _includes/icons/icons.html
|
||||
var resultDoc = document.createElement('div');
|
||||
resultDoc.classList.add('search-result-doc');
|
||||
resultDoc.innerHTML = '<svg viewBox="0 0 24 24" class="search-result-icon"><use xlink:href="#svg-doc"></use></svg>';
|
||||
@@ -453,6 +455,43 @@ jtd.onReady(function(){
|
||||
scrollNav();
|
||||
});
|
||||
|
||||
// Copy button on code
|
||||
|
||||
jtd.onReady(function(){
|
||||
|
||||
var codeBlocks = document.querySelectorAll('div.highlighter-rouge, div.listingblock, 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
|
||||
var svgCopied = '<svg viewBox="0 0 24 24" class="copy-icon"><use xlink:href="#svg-copied"></use></svg>';
|
||||
var svgCopy = '<svg viewBox="0 0 24 24" class="copy-icon"><use xlink:href="#svg-copy"></use></svg>';
|
||||
|
||||
codeBlocks.forEach(codeBlock => {
|
||||
var copyButton = document.createElement('button');
|
||||
var timeout = null;
|
||||
copyButton.type = 'button';
|
||||
copyButton.ariaLabel = 'Copy code to clipboard';
|
||||
copyButton.innerHTML = svgCopy;
|
||||
codeBlock.append(copyButton);
|
||||
|
||||
copyButton.addEventListener('click', function () {
|
||||
if(timeout === null) {
|
||||
var code = codeBlock.querySelector('pre:not(.lineno)').innerText;
|
||||
window.navigator.clipboard.writeText(code);
|
||||
|
||||
copyButton.innerHTML = svgCopied;
|
||||
|
||||
var timeoutSetting = 4000;
|
||||
|
||||
timeout = setTimeout(function () {
|
||||
copyButton.innerHTML = svgCopy;
|
||||
timeout = null;
|
||||
}, timeoutSetting);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})(window.jtd = window.jtd || {});
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Vendored
+58
-3
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user