Correct copy code block text
This commit is contained in:
		
							
								
								
									
										15
									
								
								js/script.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								js/script.js
									
									
									
									
									
								
							@@ -34,15 +34,24 @@ docReady(function() {
 | 
			
		||||
        boxCopy.textContent = "Copy"
 | 
			
		||||
 | 
			
		||||
        boxCopy.onclick = function() {
 | 
			
		||||
            // Get text inside (remove 4 first char corresponding to "Copy")
 | 
			
		||||
            let srcText = this.parentNode.textContent.slice(4)
 | 
			
		||||
            // Create a clone the node to not affect the original one
 | 
			
		||||
            let nodeClone = this.parentNode.cloneNode(true)
 | 
			
		||||
 | 
			
		||||
            // Remove Line Numbers and Copy Button
 | 
			
		||||
            let linenumNodes = nodeClone.querySelectorAll('.linenr,.src-copy')
 | 
			
		||||
            for (var i = linenumNodes.length - 1 ; i >= 0 ; --i) {
 | 
			
		||||
                nodeClone.removeChild(linenumNodes[i])
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Copy the filetered content to the clipboard
 | 
			
		||||
            let srcText = nodeClone.textContent
 | 
			
		||||
            navigator.clipboard.writeText(srcText).then(function() {
 | 
			
		||||
                boxCopy.textContent = "Copied"
 | 
			
		||||
                boxCopy.classList.add("src-copied")
 | 
			
		||||
                setTimeout(function() {
 | 
			
		||||
                    boxCopy.textContent = "Copy"
 | 
			
		||||
                    boxCopy.classList.remove("src-copied")
 | 
			
		||||
                },1000);
 | 
			
		||||
                }, 2000);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user