MediaWiki:Gadget-PreloadEditor.js: Difference between revisions
MediaWiki interface page
More actions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 517: | Line 517: | ||
// ------------------------------------------------------------ | // ------------------------------------------------------------ | ||
applyPageMode() { | |||
$('body') | |||
.addClass( | |||
'preload-editor-page' | |||
); | |||
/* | |||
* Hide the normal MediaWiki page heading. | |||
* The editor supplies its own internal headings. | |||
*/ | |||
$( | |||
'#firstHeading, ' + | |||
'.firstHeading, ' + | |||
'.mw-body-header' | |||
).hide(); | |||
/* | |||
* Remove the normal heading spacing. | |||
*/ | |||
$( | |||
'#mw-content-text' | |||
).css({ | |||
marginTop: 0 | |||
}); | |||
/* | |||
* Make the editor occupy the remaining viewport | |||
* and keep the outer page from scrolling. | |||
*/ | |||
this.updatePageHeight(); | |||
if (!this.pageResizeHandler) { | |||
this.pageResizeHandler = | |||
() => | |||
this.updatePageHeight(); | |||
window.addEventListener( | |||
'resize', | |||
this.pageResizeHandler | |||
); | |||
} | |||
}, | |||
updatePageHeight() { | updatePageHeight() { | ||
| Line 3,941: | Line 3,942: | ||
}, | }, | ||
selectVariable(name) { | |||
name = | |||
String(name || '') | |||
.trim() | |||
.toUpperCase(); | |||
if (!name) { | |||
return; | |||
} | |||
const available = | |||
['PAGE'].concat( | |||
( | |||
this.analysis && | |||
this.analysis.variables | |||
? this.analysis.variables | |||
: [] | |||
).filter( | |||
variable => | |||
variable !== 'PAGE' | |||
) | |||
); | |||
const configuredUnused = | |||
this.state.config && | |||
this.state.config.fields | |||
? Object.keys( | |||
this.state.config.fields | |||
) | |||
.map( | |||
variable => | |||
variable.toUpperCase() | |||
) | |||
: []; | |||
configuredUnused.forEach( | |||
variable => { | |||
if ( | |||
!available.includes(variable) && | |||
variable !== 'PAGE' | |||
) { | |||
available.push(variable); | |||
} | |||
} | |||
); | |||
if (!available.includes(name)) { | |||
return; | |||
} | |||
this.state.selectedVariable = | |||
name; | |||
this.renderVariablesBySelector(); | |||
this.renderVariableConfigurationBySelector(); | |||
/* | |||
* Bring the selected variable configuration back | |||
* into view, as before. | |||
*/ | |||
const configuration = | |||
this.root && | |||
this.root.find( | |||
'.preload-editor-variable-configuration' | |||
); | |||
if ( | |||
configuration && | |||
configuration.length | |||
) { | |||
configuration.get(0).scrollIntoView({ | |||
behavior: 'smooth', | |||
block: 'start' | |||
}); | |||
} | |||
}, | |||
renderVariableConfigurationBySelector() { | renderVariableConfigurationBySelector() { | ||