| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
( function () { |
| 5 |
const nav = require( './nav.js' ); |
| 6 |
nav.insertHints( mw.msg( 'prefs-sections-navigation-hint' ) ); |
| 7 |
|
| 8 |
|
| 9 |
const dialogFactory = new OO.Factory(); |
| 10 |
const windowManager = new OO.ui.WindowManager( { factory: dialogFactory } ); |
| 11 |
windowManager.on( 'opening', ( win ) => { |
| 12 |
if ( !win.$body.data( 'mw-section-infused' ) ) { |
| 13 |
win.$body.removeClass( 'mw-htmlform-autoinfuse-lazy' ); |
| 14 |
mw.hook( 'htmlform.enhance' ).fire( win.$body ); |
| 15 |
win.$body.data( 'mw-section-infused', true ); |
| 16 |
} |
| 17 |
} ); |
| 18 |
|
| 19 |
|
| 20 |
const setSection = function ( sectionName, fieldset ) { |
| 21 |
|
| 22 |
const section = sectionName.replace( 'mw-prefsection-', '' ).replace( 'mw-mobile-prefs-', '' ); |
| 23 |
const win = windowManager.getCurrentWindow(); |
| 24 |
if ( win && win.constructor.static.name !== 'mw-mobile-prefs-' + section ) { |
| 25 |
windowManager.closeWindow( win ); |
| 26 |
} |
| 27 |
|
| 28 |
windowManager.openWindow( 'mw-mobile-prefs-' + section ).opened.then( () => { |
| 29 |
|
| 30 |
if ( fieldset ) { |
| 31 |
|
| 32 |
setTimeout( () => { |
| 33 |
fieldset.scrollIntoView( { behavior: 'smooth' } ); |
| 34 |
} ); |
| 35 |
} |
| 36 |
} ); |
| 37 |
if ( nav.switchingNoHash ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
location.hash = '#mw-prefsection-' + section; |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
function createSectionDialog( sectionId, sectionTitle, sectionBody ) { |
| 47 |
function PrefDialog() { |
| 48 |
const conf = { classes: [ 'overlay-content', 'mw-mobile-pref-window' ] }; |
| 49 |
PrefDialog.super.call( this, conf ); |
| 50 |
} |
| 51 |
|
| 52 |
OO.inheritClass( PrefDialog, OO.ui.ProcessDialog ); |
| 53 |
PrefDialog.static.name = sectionId; |
| 54 |
PrefDialog.static.escapable = true; |
| 55 |
PrefDialog.static.size = 'larger'; |
| 56 |
PrefDialog.static.title = sectionTitle; |
| 57 |
PrefDialog.static.actions = [ |
| 58 |
{ action: 'cancel', label: mw.msg( 'prefs-back-title' ), flags: [ 'safe', 'close' ] } |
| 59 |
]; |
| 60 |
PrefDialog.prototype.initialize = function () { |
| 61 |
this.name = sectionId; |
| 62 |
PrefDialog.super.prototype.initialize.call( this ); |
| 63 |
this.$body.append( sectionBody ); |
| 64 |
this.content = new OO.ui.PanelLayout( { padded: true, expanded: true } ); |
| 65 |
this.$body.addClass( 'mw-mobile-pref-dialog-body' ); |
| 66 |
}; |
| 67 |
PrefDialog.prototype.getActionProcess = function ( action ) { |
| 68 |
const dialog = this; |
| 69 |
if ( action ) { |
| 70 |
return new OO.ui.Process( () => { |
| 71 |
dialog.close( { action: action } ); |
| 72 |
} ); |
| 73 |
} |
| 74 |
return PrefDialog.super.prototype.getActionProcess.call( this, action ); |
| 75 |
}; |
| 76 |
|
| 77 |
dialogFactory.register( PrefDialog ); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
function initDialogs() { |
| 84 |
|
| 85 |
const preferencesForm = document.getElementById( 'mw-prefs-form' ); |
| 86 |
const prefButtons = preferencesForm.querySelector( '.mw-htmlform-submit-buttons' ); |
| 87 |
const sections = preferencesForm.querySelectorAll( '.mw-mobile-prefsection' ); |
| 88 |
|
| 89 |
|
| 90 |
windowManager.on( 'opening', ( win, opened ) => { |
| 91 |
if ( opened ) { |
| 92 |
win.$foot[ 0 ].appendChild( prefButtons ); |
| 93 |
} |
| 94 |
} ); |
| 95 |
|
| 96 |
windowManager.on( 'closing', ( _win, closed ) => { |
| 97 |
document.getElementById( 'preferences' ).appendChild( prefButtons ); |
| 98 |
if ( closed ) { |
| 99 |
location.hash = ''; |
| 100 |
} |
| 101 |
} ); |
| 102 |
|
| 103 |
$( preferencesForm ).append( windowManager.$element ); |
| 104 |
|
| 105 |
Array.prototype.forEach.call( sections, ( section ) => { |
| 106 |
const sectionContent = document.getElementById( section.id + '-content' ); |
| 107 |
const sectionBody = sectionContent.querySelector( 'div > div.oo-ui-widget' ); |
| 108 |
const sectionText = sectionContent.querySelector( '.mw-prefs-title' ).textContent; |
| 109 |
createSectionDialog( section.id, sectionText, sectionBody ); |
| 110 |
} ); |
| 111 |
const prefSelect = OO.ui.infuse( $( '.mw-mobile-prefs-sections' ) ); |
| 112 |
prefSelect.aggregate( { |
| 113 |
click: 'itemClick' |
| 114 |
} ); |
| 115 |
prefSelect.on( 'itemClick', ( button ) => { |
| 116 |
setSection( button.getData() ); |
| 117 |
} ); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
$( () => { |
| 122 |
initDialogs(); |
| 123 |
nav.onLoad( setSection ); |
| 124 |
} ); |
| 125 |
}() ); |