2 * mediawiki.filewarning
4 * @author Mark Holmquist, 2015
8 const warningConfig = mw.config.get( 'wgFileWarning' ),
9 warningMessages = warningConfig.messages,
10 warningLink = warningConfig.link,
11 $origMimetype = $( '.fullMedia .fileInfo .mime-type' ),
12 $mimetype = $origMimetype.clone(),
14 .addClass( 'mediawiki-filewarning-header empty' ),
16 .addClass( 'mediawiki-filewarning-main empty' ),
18 .addClass( 'mediawiki-filewarning-info empty' ),
20 .addClass( 'mediawiki-filewarning-footer empty' ),
21 dialog = new OO.ui.PopupButtonWidget( {
22 classes: [ 'mediawiki-filewarning-anchor' ],
28 // This popup is always "visible", but hidden using CSS. OOUI event handlers that try to
29 // close it interfere with other things on the page. (T309093)
31 classes: [ 'mediawiki-filewarning' ],
34 $content: $header.add( $main ).add( $info ).add( $footer )
38 function loadMessage( $target, message ) {
40 $target.removeClass( 'empty' )
41 // eslint-disable-next-line mediawiki/msg-doc
42 .text( mw.msg( message ) );
46 // The main message must be populated for the dialog to show.
47 if ( warningConfig && warningConfig.messages && warningConfig.messages.main ) {
48 $mimetype.addClass( 'has-warning' );
50 $origMimetype.replaceWith( dialog.$element );
52 if ( warningMessages ) {
53 loadMessage( $main, warningMessages.main );
54 loadMessage( $header, warningMessages.header );
55 loadMessage( $footer, warningMessages.footer );
58 loadMessage( $info, warningMessages.info );
59 $info.attr( 'href', warningLink );
63 // Position the popup relative to $button rather than the default $element, so that it isn't
64 // pushed away by padding added to .mediawiki-filewarning-anchor in CSS. (T363157)
65 dialog.getPopup().setFloatableContainer( dialog.$button );
67 // Make OOUI open the dialog, it won't appear until the user
68 // hovers over the warning.
69 dialog.getPopup().toggle( true );
71 // Override toggle handler because we don't need it for this popup
72 // object at all. Sort of nasty, but it gets the job done.
73 dialog.getPopup().toggle = function () {};