|
|
@@ -4,6 +4,48 @@ const expandButton = document.getElementById( 'expandButton' );
|
|
|
const clearSearchButton = document.getElementById( 'clearSearchButton' );
|
|
|
const filterInput = document.getElementById( 'filterInput' );
|
|
|
|
|
|
+// code copy buttons
|
|
|
+
|
|
|
+const elements = document.getElementsByTagName( 'pre' );
|
|
|
+
|
|
|
+for ( let i = 0; i < elements.length; i ++ ) {
|
|
|
+
|
|
|
+ const element = elements[ i ];
|
|
|
+
|
|
|
+ if ( element.classList.contains( 'linenums' ) === false ) {
|
|
|
+
|
|
|
+ addCopyButton( element );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function addCopyButton( element ) {
|
|
|
+
|
|
|
+ const copyButton = document.createElement( 'button' );
|
|
|
+ copyButton.className = 'copy-btn';
|
|
|
+
|
|
|
+ element.appendChild( copyButton );
|
|
|
+
|
|
|
+ copyButton.addEventListener( 'click', function () {
|
|
|
+
|
|
|
+ const codeContent = element.textContent;
|
|
|
+ navigator.clipboard.writeText( codeContent ).then( () => {
|
|
|
+
|
|
|
+ copyButton.classList.add( 'copied' );
|
|
|
+
|
|
|
+ setTimeout( () => {
|
|
|
+
|
|
|
+ copyButton.classList.remove( 'copied' );
|
|
|
+
|
|
|
+ }, 1000 );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
// Functionality for hamburger button (on small devices)
|
|
|
|
|
|
expandButton.onclick = function ( event ) {
|