From 5ef2c13c483079e055e29fa528ef23a840c84549 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 29 Mar 2024 13:04:40 +0000 Subject: [PATCH] Preserve reflist CSS in dynamic mode Bug: T361359 Change-Id: I4c48129a54103f47ce512d685d2ab4b3c188a5b0 --- modules/ve-cite/ve.ce.MWReferencesListNode.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/ve-cite/ve.ce.MWReferencesListNode.js b/modules/ve-cite/ve.ce.MWReferencesListNode.js index a72c006a6..f0f8ed678 100644 --- a/modules/ve-cite/ve.ce.MWReferencesListNode.js +++ b/modules/ve-cite/ve.ce.MWReferencesListNode.js @@ -187,6 +187,12 @@ ve.ce.MWReferencesListNode.prototype.update = function () { emptyText = ve.msg( 'cite-ve-referenceslist-isempty-default' ); } + let originalDomElements; + if ( model.getElement().originalDomElementsHash ) { + originalDomElements = model.getStore().value( + model.getElement().originalDomElementsHash + ); + } // Use the Parsoid-provided DOM if: // // * There are no references in the model @@ -196,13 +202,11 @@ ve.ce.MWReferencesListNode.prototype.update = function () { if ( !hasModelReferences && !this.modified && - model.getElement().originalDomElementsHash + originalDomElements ) { // Create a copy when importing to the main document, as extensions may + this.$originalRefList = $( ve.copyDomElements( originalDomElements, document ) ); // modify DOM nodes in the main doc. - this.$originalRefList = $( ve.copyDomElements( model.getStore().value( - model.getElement().originalDomElementsHash - ), document ) ); if ( this.$originalRefList.find( 'li' ).length ) { this.$element.append( this.$originalRefList ); } else { @@ -216,6 +220,17 @@ ve.ce.MWReferencesListNode.prototype.update = function () { this.$originalRefList.remove(); this.$originalRefList = null; } + // Copy CSS to dynamic ref list + if ( originalDomElements ) { + // Get first container, e.g. skipping TemplateStyles + const divs = originalDomElements.filter( ( element ) => element.tagName === 'DIV' ); + if ( divs.length ) { + // eslint-disable-next-line mediawiki/class-doc + this.$element.addClass( divs[ 0 ].getAttribute( 'class' ) ); + this.$element.attr( 'style', divs[ 0 ].getAttribute( 'style' ) ); + } + } + this.$reflist.detach().empty().attr( 'data-mw-group', refGroup || null ); this.$refmsg.detach();