Mobrovac has submitted this change and it was merged.

Change subject: Hide IPA
......................................................................


Hide IPA

Part of offloading DOM transformations

Ran into issues with the ipa_button div on the client side.
Had to change it to a span so that the paragraph flowed correctly
and didn't immediately start a new line.

Bug: T118203
Change-Id: I7c79548c9ea8c9cdc22551dfdc77f8455a514f8c
---
A lib/transformations/hideIPA.js
M lib/transforms.js
2 files changed, 53 insertions(+), 0 deletions(-)

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



diff --git a/lib/transformations/hideIPA.js b/lib/transformations/hideIPA.js
new file mode 100644
index 0000000..c45dc05
--- /dev/null
+++ b/lib/transformations/hideIPA.js
@@ -0,0 +1,51 @@
+/**
+ * DOM transformation shared with app. Let's keep this in sync with the app.
+ * Last sync: Android repo 601c663 www/js/transforms/hideIPA.js
+ *
+ * The main change from the original Android app file is to use
+ * content.createElement() instead of document.createElement().
+ * Had to change the ipa_button element from a div to a span since the
+ * div caused layout flow issues on the client side.
+ */
+
+'use strict';
+
+function hideIPA(content) {
+    var spans = content.querySelectorAll( "span.IPA" );
+    for (var i = 0; i < spans.length; i++) {
+        var parentSpan = spans[i].parentNode;
+        if (parentSpan === null) {
+            continue;
+        }
+        var doTransform = false;
+        // case 1: we have a sequence of IPA spans contained in a parent 
"nowrap" span
+        if (parentSpan.tagName === "SPAN" && 
spans[i].classList.contains('nopopups')) {
+            doTransform = true;
+        }
+        if (parentSpan.style.display === 'none') {
+            doTransform = false;
+        }
+        if (!doTransform) {
+            continue;
+        }
+
+        //we have a new IPA span!
+
+        var containerSpan = content.createElement('span');
+        parentSpan.parentNode.insertBefore(containerSpan, parentSpan);
+        parentSpan.parentNode.removeChild(parentSpan);
+
+        //create and add the button
+        var buttonDiv = content.createElement('span');
+        buttonDiv.classList.add('ipa_button');
+        containerSpan.appendChild(buttonDiv);
+        containerSpan.appendChild(parentSpan);
+
+        //set initial visibility
+        parentSpan.style.display = 'none';
+    }
+}
+
+module.exports = {
+    hideIPA: hideIPA
+};
diff --git a/lib/transforms.js b/lib/transforms.js
index d27d8eb..988a311 100644
--- a/lib/transforms.js
+++ b/lib/transforms.js
@@ -10,6 +10,7 @@
 var relocateFirstParagraph = 
require('./transformations/relocateFirstParagraph');
 var anchorPopUpMediaTransforms = 
require('./transformations/anchorPopUpMediaTransforms');
 var hideRedLinks = require('./transformations/hideRedLinks');
+var hideIPA = require('./transformations/hideIPA');
 var setMathFormulaImageMaxWidth = 
require('./transformations/setMathFormulaImageMaxWidth');
 
 var NodeType =
@@ -222,6 +223,7 @@
 
     anchorPopUpMediaTransforms.fixVideoAnchor(doc);
     hideRedLinks.hideRedLinks(doc);
+    hideIPA.hideIPA(doc);
     setMathFormulaImageMaxWidth.setMathFormulaImageMaxWidth(doc);
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7c79548c9ea8c9cdc22551dfdc77f8455a514f8c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
Gerrit-Reviewer: Bgerstle <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to