mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
Avoid wrapping floated tables using computed styles
Bug: T366314
Change-Id: I71657b7f1f26bcf52f5ade5b7668955a1f4df24b
(cherry picked from commit 711f67ce00
)
This commit is contained in:
parent
e469d75505
commit
c117c2a43b
|
@ -3,14 +3,18 @@ const init = () => {
|
|||
if ( !config.VectorWrapTablesTemporary ) {
|
||||
return;
|
||||
}
|
||||
const tables = document.querySelectorAll( '.mw-parser-output table.wikitable:not(.floatright):not(.floatleft)' );
|
||||
const tables = document.querySelectorAll( '.mw-parser-output table.wikitable' );
|
||||
Array.from( tables ).forEach( ( table ) => {
|
||||
const styles = window.getComputedStyle( table );
|
||||
const isFloat = styles.getPropertyValue( 'float' ) === 'right' || styles.getPropertyValue( 'float' ) === 'left';
|
||||
|
||||
// Don't wrap tables within tables
|
||||
const parent = table.parentElement;
|
||||
if (
|
||||
parent && table.matches( '.wikitable' ) &&
|
||||
parent &&
|
||||
!parent.matches( '.noresize' ) &&
|
||||
!parent.closest( 'table' )
|
||||
!parent.closest( 'table' ) &&
|
||||
!isFloat
|
||||
) {
|
||||
const wrapper = document.createElement( 'div' );
|
||||
wrapper.classList.add( 'noresize' );
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`tables doesnt wrap floated tables 1`] = `
|
||||
"
|
||||
<table class=\\"wikitable\\" style=\\"float:right\\">
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`tables doesnt wrap nested tables 1`] = `
|
||||
"
|
||||
<section class=\\"mw-parser-output\\">
|
||||
|
@ -16,11 +26,10 @@ exports[`tables doesnt wrap nested tables 1`] = `
|
|||
exports[`tables doesnt wrap tables that are already wrapped 1`] = `
|
||||
"
|
||||
<div class=\\"mw-parser-output\\">
|
||||
<div>
|
||||
<table>
|
||||
<div class=\\"noresize\\">
|
||||
<table class=\\"wikitable\\">
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table></td><td></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -39,19 +48,6 @@ exports[`tables doesnt wrap tables that are not wikitables 1`] = `
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`tables only wraps wikitables 1`] = `
|
||||
"
|
||||
<section class=\\"mw-parser-output\\">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table></td><td></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`tables wraps multiple table with div 1`] = `
|
||||
"
|
||||
<section class=\\"mw-parser-output\\">
|
||||
|
|
|
@ -50,22 +50,6 @@ describe( 'tables', () => {
|
|||
expect( document.body.innerHTML ).toMatchSnapshot();
|
||||
} );
|
||||
|
||||
test( 'only wraps wikitables', () => {
|
||||
document.body.innerHTML = `
|
||||
<section class="mw-parser-output">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
`;
|
||||
tables();
|
||||
|
||||
expect( document.body.innerHTML ).toMatchSnapshot();
|
||||
} );
|
||||
|
||||
test( 'doesnt wrap tables that are not wikitables', () => {
|
||||
document.body.innerHTML = `
|
||||
<table>
|
||||
|
@ -83,11 +67,10 @@ describe( 'tables', () => {
|
|||
test( 'doesnt wrap tables that are already wrapped', () => {
|
||||
document.body.innerHTML = `
|
||||
<div class="mw-parser-output">
|
||||
<div>
|
||||
<table>
|
||||
<div class="noresize">
|
||||
<table class="wikitable">
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -97,4 +80,17 @@ describe( 'tables', () => {
|
|||
|
||||
expect( document.body.innerHTML ).toMatchSnapshot();
|
||||
} );
|
||||
|
||||
test( 'doesnt wrap floated tables', () => {
|
||||
document.body.innerHTML = `
|
||||
<table class="wikitable" style="float:right">
|
||||
<tbody>
|
||||
<tr><th>table table table</th></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
tables();
|
||||
|
||||
expect( document.body.innerHTML ).toMatchSnapshot();
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue