Table of contents doesn't respect NOTOC after an edit

* majorly done in VE by VE team by sending empty array,
since firing an event in beneficial for removing the TOC if needed

Bug: T315863
Bug: T315862
Change-Id: I128c550f039a812dde36fcefa56334842e36fbe2
This commit is contained in:
Moh'd Khier Abualruz 2022-08-26 16:47:16 +02:00
parent 2b63f5c1c3
commit 4f47c744fd
1 changed files with 7 additions and 3 deletions

View File

@ -408,8 +408,12 @@ module.exports = function tableOfContents( props ) {
* @param {Section[]} sections * @param {Section[]} sections
*/ */
function reloadTableOfContents( sections ) { function reloadTableOfContents( sections ) {
if ( sections.length < 1 ) {
reloadPartialHTML( TOC_ID, '' );
return;
}
mw.loader.using( 'mediawiki.template.mustache' ).then( () => { mw.loader.using( 'mediawiki.template.mustache' ).then( () => {
reloadPartialHTML( getTableOfContentsHTML( sections ), TOC_ID ); reloadPartialHTML( TOC_ID, getTableOfContentsHTML( sections ) );
// Reexpand sections that were expanded before the table of contents was reloaded. // Reexpand sections that were expanded before the table of contents was reloaded.
reExpandSections(); reExpandSections();
// Initialize Collapse toggle buttons // Initialize Collapse toggle buttons
@ -420,11 +424,11 @@ module.exports = function tableOfContents( props ) {
/** /**
* Replaces the contents of the given element with the given HTML * Replaces the contents of the given element with the given HTML
* *
* @param {string} html
* @param {string} elementId * @param {string} elementId
* @param {string} html
* @param {boolean} setInnerHTML * @param {boolean} setInnerHTML
*/ */
function reloadPartialHTML( html, elementId, setInnerHTML = true ) { function reloadPartialHTML( elementId, html, setInnerHTML = true ) {
const htmlElement = document.getElementById( elementId ); const htmlElement = document.getElementById( elementId );
if ( htmlElement ) { if ( htmlElement ) {
if ( setInnerHTML ) { if ( setInnerHTML ) {