From 0d9021ad3e90c88a6248eb9ebfd41a478aeba025 Mon Sep 17 00:00:00 2001
From: Syndamia
Date: Sat, 21 Dec 2024 15:14:49 +0200
Subject: referat(WT): Implement code copy
---
Year 4/Web technologies/referat/css/style.css | 19 ++++++++++++++++++
Year 4/Web technologies/referat/img/clipboard.svg | 1 +
.../referat/javascript/code-copy.js | 9 +++++++++
Year 4/Web technologies/referat/referat.html | 23 +++++++++++-----------
4 files changed, 41 insertions(+), 11 deletions(-)
create mode 100644 Year 4/Web technologies/referat/img/clipboard.svg
create mode 100644 Year 4/Web technologies/referat/javascript/code-copy.js
diff --git a/Year 4/Web technologies/referat/css/style.css b/Year 4/Web technologies/referat/css/style.css
index c7c6db8..4f71017 100644
--- a/Year 4/Web technologies/referat/css/style.css
+++ b/Year 4/Web technologies/referat/css/style.css
@@ -95,8 +95,27 @@ pre > code {
display: inline-block;
width: 100%;
box-sizing: border-box;
+ position: relative;
}
ol.sources > li::before, sup a, sup a:visited {
color: var(--level4);
}
+
+.copy-to-clipboard {
+ position: absolute;
+ right: 0.5em;
+ top: 0.25em;
+ z-index: 50;
+ background-color: white;
+ border-radius: 0.25em;
+ cursor: pointer;
+}
+
+.copy-to-clipboard:hover {
+ background-color: rgb(68, 65, 118, 0.5);
+}
+
+.copy-to-clipboard:active {
+ transform: scale(0.8);
+}
diff --git a/Year 4/Web technologies/referat/img/clipboard.svg b/Year 4/Web technologies/referat/img/clipboard.svg
new file mode 100644
index 0000000..3ba32a4
--- /dev/null
+++ b/Year 4/Web technologies/referat/img/clipboard.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Year 4/Web technologies/referat/javascript/code-copy.js b/Year 4/Web technologies/referat/javascript/code-copy.js
new file mode 100644
index 0000000..780f950
--- /dev/null
+++ b/Year 4/Web technologies/referat/javascript/code-copy.js
@@ -0,0 +1,9 @@
+for (codeblock of document.getElementsByTagName('code')) {
+ const copy_btn = codeblock.lastChild;
+ if (copy_btn.tagName !== 'IMG') { continue; }
+
+ const codeText = codeblock.innerText;
+ copy_btn.addEventListener('click', function() {
+ navigator.clipboard.writeText(codeText);
+ });
+}
diff --git a/Year 4/Web technologies/referat/referat.html b/Year 4/Web technologies/referat/referat.html
index b9d96a9..570528b 100644
--- a/Year 4/Web technologies/referat/referat.html
+++ b/Year 4/Web technologies/referat/referat.html
@@ -92,7 +92,7 @@
Разбира се, екипът зад нея поддържат и Apache уеб-сървърът.
Инсталацията се свежда до една проста команда:[8]
-
brew install httpd
+
brew install httpd
Linux
@@ -102,13 +102,13 @@
Обаче действието е практически същото при всички тях и наподобява този под MacOS: изпълнява се команда, извикваща вградения пакетен мениджър да свръши работата.[10]