| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
( function () { |
| 5 |
let switchingNoHash; |
| 6 |
const session = require( 'mediawiki.storage' ).session; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
module.exports = { |
| 11 |
switchingNoHash: switchingNoHash, |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
insertHints: function ( hintMsg ) { |
| 22 |
return $( '<div>' ).addClass( 'mw-navigation-hint' ) |
| 23 |
.text( hintMsg ) |
| 24 |
.attr( { |
| 25 |
tabIndex: 0 |
| 26 |
} ) |
| 27 |
.insertBefore( '.mw-htmlform-ooui-wrapper' ); |
| 28 |
}, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
switchPrefSection: function ( setSection, sectionName, fieldset, noHash ) { |
| 41 |
if ( noHash ) { |
| 42 |
this.switchingNoHash = true; |
| 43 |
} |
| 44 |
setSection( sectionName, fieldset ); |
| 45 |
if ( noHash ) { |
| 46 |
this.switchingNoHash = false; |
| 47 |
} |
| 48 |
}, |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
detectHash: function ( setSection ) { |
| 58 |
const hash = location.hash; |
| 59 |
if ( /^#mw-prefsection-[\w]+$/.test( hash ) ) { |
| 60 |
session.remove( 'mwpreferences-prevTab' ); |
| 61 |
|
| 62 |
this.switchPrefSection( setSection, hash.slice( 1 ) ); |
| 63 |
} else if ( /^#mw-[\w-]+$/.test( hash ) ) { |
| 64 |
const subsection = document.getElementById( hash.slice( 1 ) ); |
| 65 |
const $section = $( subsection ).closest( '.mw-prefs-section-fieldset' ); |
| 66 |
if ( $section.length ) { |
| 67 |
session.remove( 'mwpreferences-prevTab' ); |
| 68 |
|
| 69 |
this.switchPrefSection( setSection, $section.attr( 'id' ), subsection, true ); |
| 70 |
} |
| 71 |
} |
| 72 |
}, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
onHashChange: function ( setSection, defaultSectionName ) { |
| 82 |
const hash = location.hash; |
| 83 |
if ( /^#mw-[\w-]+/.test( hash ) ) { |
| 84 |
this.detectHash( setSection ); |
| 85 |
} else if ( hash === '' && defaultSectionName ) { |
| 86 |
this.switchPrefSection( setSection, defaultSectionName, undefined, true ); |
| 87 |
} |
| 88 |
}, |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
onLoad: function ( setSection, defaultSection ) { |
| 98 |
$( window ).on( 'hashchange', this.onHashChange.bind( this, setSection, defaultSection ) |
| 99 |
).trigger( 'hashchange' ); |
| 100 |
}, |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
restorePrevSection: function ( setSection, onSubmit ) { |
| 110 |
const sectionName = session.get( 'mwpreferences-prevTab' ); |
| 111 |
if ( sectionName ) { |
| 112 |
this.switchPrefSection( setSection, sectionName, undefined, true ); |
| 113 |
|
| 114 |
session.remove( 'mwpreferences-prevTab' ); |
| 115 |
} |
| 116 |
$( '#mw-prefs-form' ).on( 'submit', onSubmit ); |
| 117 |
} |
| 118 |
|
| 119 |
}; |
| 120 |
}() ); |