Debian Codegraph @

resources/src/mediawiki.filewarning/filewarning.js

raw symbols SCIP
1 /*!
2 * mediawiki.filewarning
3 *
4 * @author Mark Holmquist, 2015
5 * @since 1.25
6 */
7 ( function () {
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(),
13 $header = $( '<h3>' )
14 .addClass( 'mediawiki-filewarning-header empty' ),
15 $main = $( '<p>' )
16 .addClass( 'mediawiki-filewarning-main empty' ),
17 $info = $( '<a>' )
18 .addClass( 'mediawiki-filewarning-info empty' ),
19 $footer = $( '<p>' )
20 .addClass( 'mediawiki-filewarning-footer empty' ),
21 dialog = new OO.ui.PopupButtonWidget( {
22 classes: [ 'mediawiki-filewarning-anchor' ],
23 label: $mimetype,
24 flags: [ 'warning' ],
25 icon: 'alert',
26 framed: false,
27 popup: {
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)
30 autoClose: false,
31 classes: [ 'mediawiki-filewarning' ],
32 padded: true,
33 width: 400,
34 $content: $header.add( $main ).add( $info ).add( $footer )
35 }
36 } );
37
38 function loadMessage( $target, message ) {
39 if ( message ) {
40 $target.removeClass( 'empty' )
41 // eslint-disable-next-line mediawiki/msg-doc
42 .text( mw.msg( message ) );
43 }
44 }
45
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' );
49
50 $origMimetype.replaceWith( dialog.$element );
51
52 if ( warningMessages ) {
53 loadMessage( $main, warningMessages.main );
54 loadMessage( $header, warningMessages.header );
55 loadMessage( $footer, warningMessages.footer );
56
57 if ( warningLink ) {
58 loadMessage( $info, warningMessages.info );
59 $info.attr( 'href', warningLink );
60 }
61 }
62
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 );
66
67 // Make OOUI open the dialog, it won't appear until the user
68 // hovers over the warning.
69 dialog.getPopup().toggle( true );
70
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 () {};
74 }
75 }() );