Debian Codegraph @

extensions/SyntaxHighlight_GeSHi/modules/pygments.copy.js

raw symbols SCIP
1 /**
2 * Adapted from https://www.mediawiki.org/wiki/MediaWiki:Gadget-site-tpl-copy.js
3 * Original author: Krinkle
4 */
5
6 // eslint-disable-next-line compat/compat
7 const hasFeature = navigator.clipboard && 'writeText' in navigator.clipboard;
8 if ( hasFeature ) {
9 // Add type=button to avoid form submission in preview
10 const $btn = $( '<button>' )
11 .attr( 'type', 'button' )
12 .text( mw.msg( 'syntaxhighlight-button-copy' ) )
13 .on( 'click', function () {
14 const btn = this;
15 const wrapper = btn.closest( '.mw-highlight-copy' );
16 const preNode = wrapper && wrapper.querySelector( 'pre' );
17 const content = preNode && preNode.textContent.trim();
18 try {
19 navigator.clipboard.writeText( content );
20 } catch ( e ) {
21 return;
22 }
23 btn.textContent = mw.msg( 'syntaxhighlight-button-copied' );
24 setTimeout( () => {
25 btn.textContent = mw.msg( 'syntaxhighlight-button-copy' );
26 }, 5000 );
27 } );
28
29 mw.hook( 'wikipage.content' ).add( ( $content ) => {
30 $content.find( '.mw-highlight-copy:not(.mw-highlight-copy--bound)' )
31 .append( $btn.clone( true ) )
32 .addClass( 'mw-highlight-copy--bound' );
33 } );
34 }