summaryrefslogtreecommitdiff
path: root/extensions/TimedMediaHandler/resources/mw.TMHGalleryHook.js
blob: fd23690e928b571f3469e67d65825a2af6e2a02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Simple script to add pop-up video dialog link support for video thumbnails
*/
( function ( mw ) {
	// Hook to allow dynamically resizing videos in image galleries
	mw.hook( 'mediawiki.page.gallery.resize' ).add( function ( info ) {
		var $mwPlayerContainer,
			$popUp,
			$tmhVideo,
			$mwContainer = info.$imageDiv.find( '.mediaContainer' );
		if ( info.resolved ) {
			// Everything is already done here.
			return;
		}

		$mwContainer = info.$imageDiv.find( '.mediaContainer' );
		if ( $mwContainer.length ) {
			// Add some padding, so caption doesn't overlap video controls if
			// we are overlaying the caption on top of the image.
			if ( !info.$outerDiv.parent().hasClass( 'mw-gallery-packed' ) ) {
				info.$outerDiv.find( 'div.gallerytext' ).css( 'padding-bottom', '20px' );
			}

			info.$imageDiv.width( info.imgWidth );
			$mwContainer.width( info.imgWidth );
			$mwPlayerContainer = $mwContainer.children( '.mwPlayerContainer' );
			if ( $mwPlayerContainer.length ) {
				// Case 1: HTML5 player already loaded
				$mwPlayerContainer.width( info.imgWidth ).height( info.imgHeight );
				$mwPlayerContainer.find( 'img.playerPoster' ).width( info.imgWidth ).height( info.imgHeight );
			} else {
				// Case 2: Raw video element
				$tmhVideo = info.$imageDiv.find( 'video' );
				$tmhVideo.width( info.imgWidth ).height( info.imgHeight );
			}
			info.resolved = true;
			return;
		}

		$popUp = info.$imageDiv.find( '.PopUpMediaTransform' );
		if ( $popUp.length ) {
			info.$imageDiv.width( info.imgWidth );
			$popUp.add( $popUp.find( 'img' ) ).width( info.imgWidth ).height( info.imgHeight );
		}
	} );
} )( mediaWiki );