Skip to content

Commit

Permalink
added copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
4-dash committed Feb 1, 2025
1 parent ded29aa commit a5201f8
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/templates/intern/free_questions.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,42 @@ <h1>{% translate "Liste der freien Fragen im aktuellen Semester" %}</h1>
<hr>
{% for v in veranstaltungen %}
{% if v.freiefrage1 or v.freiefrage2 %}
<h2> {{ v.name }} </h2>
<h2>{{ v.name }}</h2>
<ul>
{% if v.freiefrage1 %}
<li>{% translate "Frage 1" %} : {{v.freiefrage1}}</li>
<li>
<button class="btn btn-outline-secondary btn-sm" onclick="copyToClipboard(this)" data-text="{{v.freiefrage1}}">
<i class="fa fa-clipboard"></i> Copy
</button>
<span class="ms-2">{% translate "Frage 1" %} : {{v.freiefrage1}}</span>
</li>
{% endif %}
{% if v.freiefrage2 %}
<li>{% translate "Frage 2" %} : {{v.freiefrage2}}</li>
<li>
<button class="btn btn-outline-secondary btn-sm" onclick="copyToClipboard(this)" data-text="{{v.freiefrage2}}">
<i class="fa fa-clipboard"></i> Copy
</button>
<span class="ms-2">{% translate "Frage 2" %} : {{v.freiefrage2}}</span>
</li>
{% endif %}
</ul>
<hr>
{% endif %}
{% endfor %}

<script>
function copyToClipboard(button) {
var text = button.getAttribute("data-text");

navigator.clipboard.writeText(text).then(function() {
let alertBox = document.createElement("span");
alertBox.className = "text-success ms-2";
alertBox.innerText = "Copied!";

button.parentElement.appendChild(alertBox);
setTimeout(() => alertBox.remove(), 2000);
}).catch(err => console.error('Copy failed:', err));
}
</script>

{% endblock %}

0 comments on commit a5201f8

Please sign in to comment.