Dbrant has uploaded a new change for review. https://gerrit.wikimedia.org/r/166078
Change subject: Fix for infobox relocation leaving parent table with empty space. ...................................................................... Fix for infobox relocation leaving parent table with empty space. Thanks, Monte! Change-Id: I342157475233bfb0e42585bba553b640d86284d4 --- M wikipedia/assets/bundle.js M www/js/sections.js M www/js/transforms.js 3 files changed, 38 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/78/166078/1 diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js index f8f474f..ea0e55c 100644 --- a/wikipedia/assets/bundle.js +++ b/wikipedia/assets/bundle.js @@ -424,7 +424,7 @@ var content = document.createElement( "div" ); content.setAttribute( "dir", window.directionality ); content.innerHTML = payload.section.text; - content.id = "#content_block_0"; + content.id = "content_block_0"; content = transformer.transform( "leadSection", content ); content = transformer.transform( "section", content ); @@ -582,6 +582,24 @@ transformer.register( "leadSection", function( leadContent ) { var infobox = leadContent.querySelector( "table.infobox" ); if ( infobox ) { + + /* + If the infobox table itself sits within a table or series of tables, + move the most distant ancestor table instead of just moving the + infobox. Otherwise you end up with table(s) with a hole where the + infobox had been. World War II article on enWiki has this issue. + Note that we need to stop checking ancestor tables when we hit + content_block_0. + */ + var infoboxParentTable = null; + var el = infobox; + while (el.parentNode) { + el = el.parentNode; + if (el.id === 'content_block_0') break; + if (el.tagName === 'TABLE') infoboxParentTable = el; + } + if (infoboxParentTable) infobox = infoboxParentTable; + infobox.parentNode.removeChild( infobox ); var pTags = leadContent.getElementsByTagName( "p" ); if ( pTags.length ) { diff --git a/www/js/sections.js b/www/js/sections.js index 7e3854a..b32d966 100644 --- a/www/js/sections.js +++ b/www/js/sections.js @@ -32,7 +32,7 @@ var content = document.createElement( "div" ); content.setAttribute( "dir", window.directionality ); content.innerHTML = payload.section.text; - content.id = "#content_block_0"; + content.id = "content_block_0"; content = transformer.transform( "leadSection", content ); content = transformer.transform( "section", content ); diff --git a/www/js/transforms.js b/www/js/transforms.js index c7783c9..027b078 100644 --- a/www/js/transforms.js +++ b/www/js/transforms.js @@ -5,6 +5,24 @@ transformer.register( "leadSection", function( leadContent ) { var infobox = leadContent.querySelector( "table.infobox" ); if ( infobox ) { + + /* + If the infobox table itself sits within a table or series of tables, + move the most distant ancestor table instead of just moving the + infobox. Otherwise you end up with table(s) with a hole where the + infobox had been. World War II article on enWiki has this issue. + Note that we need to stop checking ancestor tables when we hit + content_block_0. + */ + var infoboxParentTable = null; + var el = infobox; + while (el.parentNode) { + el = el.parentNode; + if (el.id === 'content_block_0') break; + if (el.tagName === 'TABLE') infoboxParentTable = el; + } + if (infoboxParentTable) infobox = infoboxParentTable; + infobox.parentNode.removeChild( infobox ); var pTags = leadContent.getElementsByTagName( "p" ); if ( pTags.length ) { -- To view, visit https://gerrit.wikimedia.org/r/166078 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I342157475233bfb0e42585bba553b640d86284d4 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits