User:Yair rand/PropCollapser.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$( function () {
var settings = JSON.parse( localStorage.propCollapser || '{}' );
function collapse( elem, $button ) {
elem.style.overflow = 'auto';
elem.style.height = '100px';
$button.text( 'Expand' );
}
function expand( elem, $button ) {
elem.style.height = '';
elem.style.overflow = '';
$button.text( 'Collapse' );
}
$( ".wikibase-statementgroupview" ).each( function ( i, elem ) {
var $button = $( '<span />' )
.css( { position: 'absolute', top: 0, right: 0 } )
.text( 'Collapse' )
.appendTo( elem )
.on( 'click', function ( e ) {
var expanding = settings[ id ];
( expanding ? expand : collapse )( elem, $button );
if ( expanding ) {
delete settings[ id ];
} else {
settings[ id ] = true;
}
localStorage.propCollapser = JSON.stringify( settings );
} );
var id = elem.id;
if ( settings[ id ] ) {
collapse( elem, $button );
}
} );
} );