From 27de2fb30182d5e6e330f2e87fed49b2d82056c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 29 Nov 2023 17:11:04 +0100 Subject: [PATCH] =?UTF-8?q?clipboard:=20fix=20O(n=C2=B2)=20buttons=20#738?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/theme.js | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index 24b525703a..33b4dbc151 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -599,38 +599,6 @@ function initCodeClipboard(){ code.parentNode.parentNode.parentNode.querySelector( 'td:first-child > pre > code' ) == code; if( !isFirstLineCell && ( inPre || text.length > 5 ) ){ - var clip = new ClipboardJS( '.copy-to-clipboard-button', { - text: function( trigger ){ - if( !trigger.previousElementSibling ){ - return ''; - } - return trigger.previousElementSibling.dataset.code || ''; - } - }); - - clip.on( 'success', function( e ){ - e.clearSelection(); - var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre'; - var isCodeRtl = !inPre ? isRtl : false; - var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); - e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); - e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); - }); - - clip.on( 'error', function( e ){ - var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre'; - var isCodeRtl = !inPre ? isRtl : false; - var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); - e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) ); - e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); - var f = function(){ - e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); - e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); - document.removeEventListener( 'copy', f ); - }; - document.addEventListener( 'copy', f ); - }); - code.classList.add( 'copy-to-clipboard-code' ); if( inPre ){ code.classList.add( 'copy-to-clipboard' ); @@ -681,6 +649,38 @@ function initCodeClipboard(){ } } } + + var clip = new ClipboardJS( '.copy-to-clipboard-button', { + text: function( trigger ){ + if( !trigger.previousElementSibling ){ + return ''; + } + return trigger.previousElementSibling.dataset.code || ''; + } + }); + + clip.on( 'success', function( e ){ + e.clearSelection(); + var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre'; + var isCodeRtl = !inPre ? isRtl : false; + var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); + e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); + e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); + }); + + clip.on( 'error', function( e ){ + var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre'; + var isCodeRtl = !inPre ? isRtl : false; + var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); + e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) ); + e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); + var f = function(){ + e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); + e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) ); + document.removeEventListener( 'copy', f ); + }; + document.addEventListener( 'copy', f ); + }); } function initChroma( update ){