MediaWiki:Gadget-copyTable.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
Line 34:
}
 
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( 'table.wikitable' ).not( '.copy-table-added' ).each( function () {
var $table = $( this ).addClass( 'copy-table-added' );
 
var $btn = $( '<button>' )
.addClass( 'copy-table-btn' )
.attr( 'title', 'Copy table' )
.html( COPY_ICON )
.on( 'click', function () {
var tsv = tableToTSV( $table[ 0 ] );
navigator.clipboard.writeText( tsv ).then( function () {
$btn.html( CHECK_ICON ).addClass( 'copy-table-btn--ok' );
setTimeout( function () {
$btn.html( COPY_ICON ).removeClass( 'copy-table-btn--ok' );
}, 2000 );
} );
} );
} );
 
// If the table //sits Wrapin tablea horizontal-scroll sobox button(the canhouse bestyle absolutelywraps positionedit
// in $table.wrap( '<div classstyle="copyoverflow-table-wrapperx:auto">' );, wrap THAT box so the button lives
// OUTSIDE the scrolling area and stays pinned. Otherwise wrap the table.
$table.parent().append( $btn );
}var $parent = $table.parent();
var $target = /auto|scroll/.test( $parent.css( 'overflow-x' ) ) ? $parent : $table;
 
$target.wrap( '<div class="copy-table-wrapper">' );
$target.parent().append( $btn ); // button is now a sibling of the scroller
} );
} );
}() );