Debian Codegraph @

resources/src/mediawiki.page.media.js

raw symbols SCIP
1 /*!
2 * Add magnify links to thumbs and resize broken media spans, where needed
3 */
4 ( function () {
5 mw.hook( 'wikipage.content' ).add( ( $content ) => {
6 $content.find(
7 'figure[typeof~="mw:File/Thumb"] > :not(figcaption) .mw-file-element'
8 ).each( function () {
9 const inner = this.parentNode;
10 const wrapper = inner.parentNode;
11
12 if ( this.classList.contains( 'mw-broken-media' ) ) {
13 // Resize broken media spans, where needed
14 const isDefault = wrapper.classList.contains( 'mw-default-size' );
15 if ( isDefault ) {
16 return;
17 }
18 if ( this.hasAttribute( 'data-width' ) ) {
19 this.style.width = this.getAttribute( 'data-width' ) + 'px';
20 }
21 if ( this.hasAttribute( 'data-height' ) ) {
22 this.style.height = this.getAttribute( 'data-height' ) + 'px';
23 }
24 } else {
25 // Add magnify links to thumbs, where needed
26 const resource = this.getAttribute( 'resource' );
27 if ( !resource ) {
28 return;
29 }
30 if ( inner.classList.contains( 'mw-file-description' ) ) {
31 return;
32 }
33 const desc = this.ownerDocument.createElement( 'a' );
34 desc.setAttribute( 'href', resource );
35 // Using a different class than mw-file-description to avoid the
36 // expectation that the media will be found inside it
37 desc.classList.add( 'mw-file-magnify' );
38 wrapper.insertBefore( desc, inner.nextSibling );
39 }
40 } );
41 } );
42 }() );