MediaWiki:Gadget-Panoviewer.js
(Redirected from User:Jon Harald Søby/Panoviewer.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.
/**
* This replaces the image in P4640 statements with an iframe showing the
* contents of panoviewer.toolforge.org.
*
* Based on [[User:Nikki/Panoviewer.js]]
*
* @license CC0
*/
( function () {
'use strict';
var prop = 'P4640';
mw.hook( 'wikibase.entityPage.entityView.rendered' ).add( function () {
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( e ) {
if ( !e.claims.hasOwnProperty( prop ) )
return;
$.each( e.claims[ prop ], function ( i, v ) {
var file = v.mainsnak.datavalue.value.replace( / /g, '_' ),
url = 'https://panoviewer.toolforge.org/#' + file,
parentelement = $( document.getElementById( v.id ) ).find( '.thumb' ),
imgelement = $( parentelement ).find( 'a img' ),
width = imgelement.attr( 'width' ),
height = imgelement.attr( 'height' );
$( parentelement )
.append(
$( '<a>' ).attr( {
'class': 'fullscreen',
'href': url,
'target': '_blank',
} )
);
$( parentelement )
.find( '.image' )
.replaceWith( $( '<iframe>' )
.attr( {
'src': url,
'width': width,
'height': height,
} )
);
} );
} );
} );
} )();