clipboard: ignore RTL for code #660

This commit is contained in:
Sören Weber 2023-10-01 12:23:50 +02:00
parent 394ff3f7b2
commit 67264dba47
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -551,6 +551,7 @@ function initAnchorClipboard(){
} }
function initCodeClipboard(){ function initCodeClipboard(){
var isCodeRtl = false;
function getCodeText( node ){ function getCodeText( node ){
// if highlight shortcode is used in inline lineno mode, remove lineno nodes before generating text, otherwise it doesn't hurt // if highlight shortcode is used in inline lineno mode, remove lineno nodes before generating text, otherwise it doesn't hurt
var code = node.cloneNode( true ); var code = node.cloneNode( true );
@ -604,16 +605,16 @@ function initCodeClipboard(){
e.clearSelection(); e.clearSelection();
var doBeside = e.trigger.parentNode.tagName.toLowerCase() == 'pre' || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); var doBeside = e.trigger.parentNode.tagName.toLowerCase() == 'pre' || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' );
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isRtl?'e':'w')) ); e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
}); });
clip.on( 'error', function( e ){ clip.on( 'error', function( e ){
var doBeside = e.trigger.parentNode.tagName.toLowerCase() == 'pre' || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' ); var doBeside = e.trigger.parentNode.tagName.toLowerCase() == 'pre' || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' );
e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) ); e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) );
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isRtl?'e':'w')) ); e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
var f = function(){ var f = function(){
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard ); e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isRtl?'e':'w')) ); e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
document.removeEventListener( 'copy', f ); document.removeEventListener( 'copy', f );
}; };
document.addEventListener( 'copy', f ); document.addEventListener( 'copy', f );