Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/preinit/ve.init.MWVESwitchPopupWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface MWVESwitchPopupWidget class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 mw.libs.ve = mw.libs.ve || {};
9 /**
10 * @class
11 * @extends OO.ui.PopupWidget
12 *
13 * @constructor
14 * @param {string} mode Current edit mode
15 * @param {Object} [config] Configuration options
16 */
17 mw.libs.ve.SwitchPopupWidget = function MWLibsVESwitchPopupWidget( mode, config ) {
18 const prefix = mode === 'visual' ? 'visualeditor-mweditmodewt' : 'visualeditor-mweditmodeve',
19 option = mode === 'visual' ? 'visualeditor-hidevisualswitchpopup' : 'visualeditor-hidesourceswitchpopup';
20
21 // Parent constructor
22 mw.libs.ve.SwitchPopupWidget.super.call( this, $.extend( {
23 autoClose: true,
24 head: true,
25 // The following messages are used here:
26 // * visualeditor-mweditmodewt-popup-title
27 // * visualeditor-mweditmodeve-popup-title
28 label: mw.msg( prefix + '-popup-title' ),
29 padded: true
30 }, config ) );
31
32 // The following messages are used here:
33 // * visualeditor-mweditmodewt-popup-body
34 // * visualeditor-mweditmodeve-popup-body
35 let $content = $( '<p>' ).text( mw.msg( prefix + '-popup-body' ) );
36
37 if ( mw.user.isNamed() ) {
38 const showAgainCheckbox = new OO.ui.CheckboxInputWidget()
39 .on( 'change', ( value ) => {
40 const configValue = value ? '1' : '';
41 new mw.Api().saveOption( option, configValue );
42 mw.user.options.set( option, configValue );
43 } );
44
45 const showAgainLayout = new OO.ui.FieldLayout( showAgainCheckbox, {
46 align: 'inline',
47 label: mw.msg( 'visualeditor-mweditmodeve-showagain' )
48 } );
49 $content = $content.add( showAgainLayout.$element );
50 }
51
52 this.$body.append( $content );
53
54 this.$element
55 // HACK: Pretend to be a PopupTool
56 // TODO: Create upstream PopupListToolGroup
57 .addClass( 've-init-mw-switchPopupWidget' );
58 };
59
60 /* Inheritance */
61
62 OO.inheritClass( mw.libs.ve.SwitchPopupWidget, OO.ui.PopupWidget );