From 54cb31c8e76515b3245bf90ffb3735ae31918b9e Mon Sep 17 00:00:00 2001
From: bogdankol <68349689+bogdankol@users.noreply.github.com>
Date: Mon, 19 Feb 2024 15:53:51 +0200
Subject: Styles refactoring (#1278)
---
docs/_static/js/codecopier.js | 67 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 docs/_static/js/codecopier.js
(limited to 'docs/_static/js/codecopier.js')
diff --git a/docs/_static/js/codecopier.js b/docs/_static/js/codecopier.js
new file mode 100644
index 00000000..bf0b3b4d
--- /dev/null
+++ b/docs/_static/js/codecopier.js
@@ -0,0 +1,67 @@
+const hamburgerIcon = `
+
+`
+
+const innersOfCopyDiv = `
+
Copy
+
+`
+
+function formDiv(id) {
+ return `
+
+ ${innersOfCopyDiv}
+
+`
+}
+
+$(document).ready(async function () {
+ const codeSnippets = $(
+ '.rst-content div[class^=highlight] div[class^=highlight], .rst-content pre.literal-block div[class^=highlight], .rst-content pre.literal-block div[class^=highlight]'
+ )
+
+ codeSnippets.each((index, el) => {
+ el.insertAdjacentHTML('beforeend', formDiv(index))
+ })
+
+ const copyButton = $('.copyDiv')
+
+ copyButton.click(async ({
+ currentTarget
+ }) => {
+ // we obtain text and copy it
+ const id = currentTarget.dataset.identifier
+
+ try {
+ await navigator.clipboard.writeText(currentTarget.offsetParent.innerText)
+ } catch (error) {
+ console.log('Copiing text failed, please try again', {
+ error
+ })
+ }
+
+ // we edit the copyDiv connected to copied text
+ const divWithNeededId = $(`div[data-identifier='${id}']`)
+ divWithNeededId.addClass('copiedNotifier')
+ divWithNeededId.html('Copied!')
+
+ setTimeout(() => {
+ divWithNeededId.html(innersOfCopyDiv)
+ divWithNeededId.removeClass('copiedNotifier')
+
+ }, 2000)
+ })
+
+ // we edit the button that is added by readthedocs portal
+ const readTheDocsButton = $('div.rst-versions')
+ const navbar = $('nav[data-toggle=wy-nav-shift]')
+
+ navbar.append(readTheDocsButton)
+
+});
+
--
cgit v1.2.3