User:Majr/galleryList.js

mw.loader.using( 'mediawiki.ui', function {	'use strict';

var $gallery = $( '.gallery' ), $boxes = $gallery.children( '.gallerybox' ), $list = $( ' ' ).prop( 'id', 'gallery-list' ), $textbox = $( ' ' ).addClass( 'mw-ui-input' ).appendTo( $list ), $all = $( ' ' ).addClass( 'mw-ui-button all' ).text( 'Select all' ).appendTo( $list ), $clear = $( ' ' ).addClass( 'mw-ui-button clear' ).text( 'Clear selection' ).appendTo( $list ); $boxes.css( 'position', 'relative' ).prepend( $( ' ' ).addClass( 'jslink add' ).text( '+' ) ); $list.css( {		position: 'fixed',		right: 0,		bottom: 0,		opacity: 0.9,		textAlign: 'right',		margin: '1px',		zIndex: 99	} ); $textbox.prop( {		readonly: true,		cols: 40,		rows: 10	} ).css( {		display: 'block',		resize: 'none'	} ); $gallery.on( 'click', '.add', function {		var name = $( this ).parent.find( '.gallerytext > a' ).prop( 'title' );		if ( $( this ).text === '+' ) {			$textbox.prop( 'value', function( $, text ) { return ( text + '\n' + name ).trim; } );			$textbox[0].scrollTop = $textbox[0].scrollHeight;			$( this ).text( '−' );		} else {			$textbox.prop( 'value', function( $, text ) { return text.replace( name, '' ).replace( /\n+/g, '\n' ).trim; } );			$textbox[0].scrollTop = $textbox[0].scrollHeight;			$( this ).text( '+' );		}	} ); $boxes.find( '.add' ).css( {		position: 'absolute',		top: '3px',		right: '5px',		fontSize: '24px'	} );

$all.click( function {		var files = [];		$textbox.val( '' );		$boxes.find( '.gallerytext > a' ).each( function { files.push( $( this ).prop( 'title' ) ); } );		$textbox.val( files.join( '\n' ) );		$boxes.find( '.add' ).text( '−' );	} );

$clear.click( function {		$textbox.val( '' );		$boxes.find( '.add' ).text( '+' );	} ); $list.appendTo( 'body' ); } );