| 1 |
|
| 2 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 36 |
|
| 37 |
desc.classList.add( 'mw-file-magnify' ); |
| 38 |
wrapper.insertBefore( desc, inner.nextSibling ); |
| 39 |
} |
| 40 |
} ); |
| 41 |
} ); |
| 42 |
}() ); |