Bgerstle has submitted this change and it was merged.

Change subject: Fix for side to side scrolling of wide images with div overlays.
......................................................................


Fix for side to side scrolling of wide images with div overlays.

See the following enwiki articles > sections:
      - "Historic Counties of England" > "Southern England"
      - "Poland" > "Administrive Divisions" > "More information" (collapsed 
table)

The images in the locations specified above were not able to be dragged 
side-to-side properly before this patch.

T95787

Change-Id: Ic488e55b047afa549f31f2658fb51324f21c415f
---
M Wikipedia/assets/bundle.js
M www/js/transforms.js
2 files changed, 24 insertions(+), 14 deletions(-)

Approvals:
  Fjalapeno: Looks good to me, but someone else must approve
  Bgerstle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Wikipedia/assets/bundle.js b/Wikipedia/assets/bundle.js
index 23d1589..c492b8f 100644
--- a/Wikipedia/assets/bundle.js
+++ b/Wikipedia/assets/bundle.js
@@ -701,16 +701,21 @@
     }
 } );
 
+function firstAncestorWithMultipleChildren (el) {
+    while ((el = el.parentElement) && (el.childElementCount == 1));
+    return el;
+}
+
 function addImageOverflowXContainer() {
     var image = this;
     if (image.width > (window.screen.width * 0.8)){
-        var div = document.createElement( 'div' );
-        div.className = 'image_overflow_x_container';
-        image.parentElement.insertBefore( div, image );
-        // Reminder: appendChild removes "image" from its previous location
-        // so no need to do so explicitly.
-        // See: 
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
-        div.appendChild( image );
+        var ancestor = firstAncestorWithMultipleChildren (image);
+        if(ancestor){
+            var div = document.createElement( 'div' );
+            div.className = 'image_overflow_x_container';
+            ancestor.parentElement.insertBefore( div, ancestor );
+            div.appendChild( ancestor );
+        }
     }
 }
 
diff --git a/www/js/transforms.js b/www/js/transforms.js
index e95aafb..2c288bb 100644
--- a/www/js/transforms.js
+++ b/www/js/transforms.js
@@ -254,16 +254,21 @@
     }
 } );
 
+function firstAncestorWithMultipleChildren (el) {
+    while ((el = el.parentElement) && (el.childElementCount == 1));
+    return el;
+}
+
 function addImageOverflowXContainer() {
     var image = this;
     if (image.width > (window.screen.width * 0.8)){
-        var div = document.createElement( 'div' );
-        div.className = 'image_overflow_x_container';
-        image.parentElement.insertBefore( div, image );
-        // Reminder: appendChild removes "image" from its previous location
-        // so no need to do so explicitly.
-        // See: 
https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
-        div.appendChild( image );
+        var ancestor = firstAncestorWithMultipleChildren (image);
+        if(ancestor){
+            var div = document.createElement( 'div' );
+            div.className = 'image_overflow_x_container';
+            ancestor.parentElement.insertBefore( div, ancestor );
+            div.appendChild( ancestor );
+        }
     }
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/203495
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic488e55b047afa549f31f2658fb51324f21c415f
Gerrit-PatchSet: 6
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Bgerstle <bgers...@wikimedia.org>
Gerrit-Reviewer: Dr0ptp4kt <ab...@wikimedia.org>
Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Phuedx <g...@samsmith.io>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to