browser: fix broken inline clipboard buttons after IE11 refactor #452

This commit is contained in:
Sören Weber 2023-02-04 22:50:19 +01:00
parent 6b96c2d662
commit 6d90be3015
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -335,8 +335,7 @@ function initCodeClipboard(){
for( var i = 0; i < codeElements.length; i++ ){ for( var i = 0; i < codeElements.length; i++ ){
var code = codeElements[i]; var code = codeElements[i];
var text = code.textContent; var text = code.textContent;
var parent = code.parentNode; var inPre = code.parentNode.tagName.toLowerCase() == 'pre';
var inPre = parent.tagName.toLowerCase() == 'pre';
if( inPre || text.length > 5 ){ if( inPre || text.length > 5 ){
var clip = new ClipboardJS( '.copy-to-clipboard-button', { var clip = new ClipboardJS( '.copy-to-clipboard-button', {
@ -382,7 +381,7 @@ function initCodeClipboard(){
var span = document.createElement( 'span' ); var span = document.createElement( 'span' );
span.classList.add( 'copy-to-clipboard' ); span.classList.add( 'copy-to-clipboard' );
span.appendChild( clone ); span.appendChild( clone );
parent.replaceChild( span, code ); code.parentNode.replaceChild( span, code );
code = clone; code = clone;
} }
var button = document.createElement( 'span' ); var button = document.createElement( 'span' );
@ -394,7 +393,7 @@ function initCodeClipboard(){
this.removeAttribute( 'aria-label' ); this.removeAttribute( 'aria-label' );
this.classList.remove( 'tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw' ); this.classList.remove( 'tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw' );
}); });
parent.insertBefore( button, code.nextSibling ); code.parentNode.insertBefore( button, code.nextSibling );
} }
} }
} }