Remove jQuery from ve.dm.MWLanguageVariantNode

Change-Id: I849cb6756171aa7bba43dc390cbd390b323328d2
This commit is contained in:
Ed Sanders 2019-11-02 16:28:32 +00:00
parent 22098d6b16
commit 2d4234fac8
3 changed files with 14 additions and 16 deletions

View file

@ -160,27 +160,23 @@ ve.dm.MWLanguageVariantNode.static.toDomElements = function ( dataElement, doc,
* renderings.
*
* @static
* @param {jQuery} $element Element to process
* @param {HTMLElement} container Container element to process
* @param {Object|null} opts Preview options
* @param {boolean} [opts.describeAll=false] Treat all rules as if the
* "describe" flag was set. This displays every language and its associated
* text, not just the one appropriate for the current user.
* @return {jQuery} $element
*/
ve.dm.MWLanguageVariantNode.static.processVariants = function ( $element, opts ) {
var self = this,
selector = '[typeof="mw:LanguageVariant"]',
$variantElements = $element.find( selector ).addBack( selector );
ve.dm.MWLanguageVariantNode.static.processVariants = function ( container, opts ) {
var self = this;
$variantElements.each( function ( _, child ) {
var dataMwvJSON = child.getAttribute( 'data-mw-variant' );
if ( dataMwvJSON && child.tagName !== 'META' ) {
Array.prototype.forEach.call( container.querySelectorAll( '[typeof="mw:LanguageVariant"]' ), function ( element ) {
var dataMwvJSON = element.getAttribute( 'data-mw-variant' );
if ( dataMwvJSON && element.tagName !== 'META' ) {
self.insertPreviewElements(
child, JSON.parse( dataMwvJSON ), opts
element, JSON.parse( dataMwvJSON ), opts
);
}
} );
return $element;
};
/**
@ -197,10 +193,10 @@ ve.dm.MWLanguageVariantNode.static.processVariants = function ( $element, opts )
*/
ve.dm.MWLanguageVariantNode.static.insertPreviewElements = function ( element, variantInfo, opts ) {
// Note that `element` can't be a <meta> (or other void tag)
$( element ).html( this.getPreviewHtml( variantInfo, opts ) );
element.innerHTML = this.getPreviewHtml( variantInfo, opts );
// This recurses into the children added by the `html` clause to ensure
// that nested variants are expanded.
this.processVariants( $( element ).children(), opts );
this.processVariants( element, opts );
return element;
};

View file

@ -118,7 +118,9 @@ ve.init.mw.LinkCache.prototype.styleElement = function ( title, $element, hasFra
ve.init.mw.LinkCache.prototype.styleParsoidElements = function ( $elements ) {
if ( ve.dm.MWLanguageVariantNode ) {
// Render the user's preferred variant in language converter markup
ve.dm.MWLanguageVariantNode.static.processVariants( $elements );
$elements.each( function ( i, element ) {
ve.dm.MWLanguageVariantNode.static.processVariants( element );
} );
}
};

View file

@ -156,7 +156,7 @@ ve.ui.MWLanguageVariantNodeContextItem.prototype.renderBody = function () {
name = ve.init.platform.getLanguageName( code.toLowerCase() ),
$text = $( '<td>' ).html( item.t );
ve.dm.MWLanguageVariantNode.static.processVariants(
$text, { showHidden: true }
$text[ 0 ], { showHidden: true }
);
$table
.append( $( '<tr>' )
@ -174,7 +174,7 @@ ve.ui.MWLanguageVariantNodeContextItem.prototype.renderBody = function () {
// Don't put $table in $body if the table is empty; this allows
// CSS :empty rules to have their proper effect.
ve.dm.MWLanguageVariantNode.static.processVariants(
$table, { showHidden: true }
$table[ 0 ], { showHidden: true }
);
$body.append( $table );
}