Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions docs/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@

// Copy Button
function copyText() {
const copiedText = document.getElementById('copiedText').textContent
const textArea = document.createElement('textArea');
textArea.textContent = copiedText;
document.body.append(textArea);
textArea.select();
textArea.setSelectionRange(0, 99999)
document.execCommand('copy');
document.getElementById('copyButton')
.insertAdjacentHTML('afterend',
`<span style="margin-left:10px; font-size:14px;">Copied!</span>`
)
// alert("Code copied to clipboard: " + textArea.value);
}
const copiedText = document.querySelector("#copiedText");
const copyMsg = document.querySelector(".copyMessage");

const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(copiedText);
selection.removeAllRanges();
selection.addRange(range); // Select the text to be copied
document.execCommand("copy");
selection.removeAllRanges(); // Unselect after copying, so selection is not visible

copyMsg.style.opacity = 1; // Show message after copying
setTimeout(() => {
copyMsg.style.opacity = 0; // Hide message after a few seconds
}, 2000);
}
3 changes: 2 additions & 1 deletion pug/getting_started/getting_started_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ <h5>Sass</h5>
<h5>CDN</h5>
<p>You can find all the versions of the CDN at <a href="https://www.jsdelivr.com/package/npm/@materializecss/materialize">jsDelivr</a>.</p>
<p><a class="waves-effect waves-light btn" id="copyButton" onclick="copyText()">Copy code <i
class="material-icons right">content_copy</i></a></p>
class="material-icons right">content_copy</i></a>
<span class="copyMessage" style="margin-left:10px; font-size:14px; transition:all 0.2s ease-in; opacity:0;">Copied!</span></p>
<pre><code class="language-markup" id="copiedText">
&lt;!-- Compiled and minified CSS -->
&lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@materializecss/[email protected]/dist/css/materialize.min.css">
Expand Down