jenkins-bot has submitted this change and it was merged.
Change subject: Hide IPA.
......................................................................
Hide IPA.
Transforms an IPA span into a clickable icon that displays the pronunciation in
a separate dialog box.
Note: only handles a single type of IPA span (they are not very consistent
across different articles). More invetigation to follow.
Change-Id: Ie084658807cfa7037ee14c6b1a991cc77ac58391
---
M wikipedia/assets/bundle.js
M wikipedia/assets/styles.css
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M www/js/sections.js
M www/js/transforms.js
5 files changed, 135 insertions(+), 3 deletions(-)
Approvals:
BearND: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js
index a79b2e7..36405b2 100644
--- a/wikipedia/assets/bundle.js
+++ b/wikipedia/assets/bundle.js
@@ -457,6 +457,7 @@
content = transformer.transform( "leadSection", content );
content = transformer.transform( "section", content );
content = transformer.transform( "hideTables", content );
+ content = transformer.transform( "hideIPA", content );
content = transformer.transform("displayDisambigLink", content);
content = transformer.transform("displayIssuesLink", content);
@@ -515,6 +516,7 @@
content.id = "content_block_" + section.id;
content = transformer.transform( "section", content );
content = transformer.transform( "hideTables", content );
+ content = transformer.transform( "hideIPA", content );
return [ heading, content ];
}
@@ -620,6 +622,7 @@
},{}],12:[function(require,module,exports){
var transformer = require("./transformer");
var night = require("./night");
+var bridge = require( "./bridge" );
// Move infobox to the bottom of the lead section
transformer.register( "leadSection", function( leadContent ) {
@@ -796,6 +799,53 @@
return content;
} );
+/*
+OnClick handler function for IPA spans.
+*/
+function ipaClickHandler() {
+ var container = this;
+ bridge.sendMessage( "ipaSpan", { "contents": container.innerHTML });
+}
+
+transformer.register( "hideIPA", function( 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 = document.createElement( 'span' );
+ parentSpan.parentNode.insertBefore(containerSpan, parentSpan);
+ parentSpan.parentNode.removeChild(parentSpan);
+
+ //create and add the button
+ var buttonDiv = document.createElement( 'div' );
+ buttonDiv.classList.add('ipa_button');
+ containerSpan.appendChild(buttonDiv);
+ containerSpan.appendChild(parentSpan);
+
+ //set initial visibility
+ parentSpan.style.display = 'none';
+ //and assign the click handler to it
+ containerSpan.onclick = ipaClickHandler;
+ }
+ return content;
+} );
+
transformer.register( "section", function( content ) {
if ( window.isNightMode ) {
night.invertElement ( content );
@@ -815,7 +865,7 @@
return content;
} );
-},{"./night":8,"./transformer":11}],13:[function(require,module,exports){
+},{"./bridge":2,"./night":8,"./transformer":11}],13:[function(require,module,exports){
/**
* MIT LICENSCE
* From: https://github.com/remy/polyfills
@@ -1094,4 +1144,4 @@
try { module.exports = parseCSSColor } catch(e) { }
-},{}]},{},[6,14,7,8,11,12,2,1,4,5,3,10,9,13])
\ No newline at end of file
+},{}]},{},[6,14,7,8,11,12,2,1,4,5,3,10,9,13])
diff --git a/wikipedia/assets/styles.css b/wikipedia/assets/styles.css
index ff40925..aa88a93 100644
--- a/wikipedia/assets/styles.css
+++ b/wikipedia/assets/styles.css
@@ -894,6 +894,16 @@
background-size: 20px 20px;
}
+.ipa_button {
+ display: inline-block;
+ margin-bottom: -3px;
+ background-image:
url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAAgCAYAAABHA7voAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAABBRJREFUWEfdWflPFkEM5U9HQUGj0WiMmnhrRBMVUeOt4fQG8cALBU8OEUEURK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OhQB/F7TFFFIQoxNuyKQtRlhgWCXOR94Dpw97YPG3PI0/X9FOWcqdhmQtRnZAnE+7Ew68DXsWwtjIlg0yrI2I1sg+GrCOSVAOuqxrVbiKAybwb0MyPqMfIH4wVe/PXzj7TVpWgullaBg4RMNvTMW+rlshGV9Rr5AEFML7sdvLkXbQCwreiaPbFKRMTo2cwHDkH+Es8e2Jwu9DsMJzBW5kzc6WWMhqUYZqktm6o8vVSP5n9FpcgLr6+vXLYmo7i97FXYYGMQFoAAAAABJRU5ErkJggg==);
+ background-image:
url(//127.0.0.1:8080/w/extensions/MobileApp/less/../images/ipa.png?2014-11-13T16:05:00Z)!ie;
+ background-size: 28px 16px;
+ height: 16px;
+ width: 28px;
+}
+
/* FIXME: Copied over from
http://en.wikipedia.org/w/index.php?title=MediaWiki:Mobile.css&oldid=609508028
This fixes some styling issues in the app, primarily hlists.
Eventually fix this by supporting loading Mobile.css in the app
@@ -1208,4 +1218,4 @@
-moz-column-count: 1 !important;
-webkit-column-count: 1 !important;
column-count: 1 !important;
-}
\ No newline at end of file
+}
diff --git
a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
index 70c00b6..24a9eaa 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
@@ -32,18 +32,22 @@
import org.mediawiki.api.json.RequestBuilder;
import org.json.JSONException;
import org.json.JSONObject;
+import android.app.AlertDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode;
+import android.text.Html;
import android.util.Log;
+import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
import android.widget.Toast;
import javax.net.ssl.SSLException;
import java.util.ArrayList;
@@ -409,6 +413,24 @@
}
}
});
+ bridge.addListener("ipaSpan", new
CommunicationBridge.JSEventListener() {
+ @Override
+ public void onMessage(String messageType, JSONObject
messagePayload) {
+ try {
+ String text = messagePayload.getString("contents");
+ final int textSize = 30;
+ TextView textView = new TextView(getActivity());
+ textView.setGravity(Gravity.CENTER);
+ textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
+ textView.setText(Html.fromHtml(text));
+ AlertDialog.Builder builder = new
AlertDialog.Builder(getActivity());
+ builder.setView(textView);
+ builder.show();
+ } catch (JSONException e) {
+ //nope
+ }
+ }
+ });
bridge.addListener("pageLoadComplete", new
CommunicationBridge.JSEventListener() {
@Override
public void onMessage(String messageType, JSONObject
messagePayload) {
diff --git a/www/js/sections.js b/www/js/sections.js
index 53b02f6..58d52d7 100644
--- a/www/js/sections.js
+++ b/www/js/sections.js
@@ -42,6 +42,7 @@
content = transformer.transform( "leadSection", content );
content = transformer.transform( "section", content );
content = transformer.transform( "hideTables", content );
+ content = transformer.transform( "hideIPA", content );
content = transformer.transform("displayDisambigLink", content);
content = transformer.transform("displayIssuesLink", content);
@@ -100,6 +101,7 @@
content.id = "content_block_" + section.id;
content = transformer.transform( "section", content );
content = transformer.transform( "hideTables", content );
+ content = transformer.transform( "hideIPA", content );
return [ heading, content ];
}
diff --git a/www/js/transforms.js b/www/js/transforms.js
index e7287ad..430d43a 100644
--- a/www/js/transforms.js
+++ b/www/js/transforms.js
@@ -1,5 +1,6 @@
var transformer = require("./transformer");
var night = require("./night");
+var bridge = require( "./bridge" );
// Move infobox to the bottom of the lead section
transformer.register( "leadSection", function( leadContent ) {
@@ -176,6 +177,53 @@
return content;
} );
+/*
+OnClick handler function for IPA spans.
+*/
+function ipaClickHandler() {
+ var container = this;
+ bridge.sendMessage( "ipaSpan", { "contents": container.innerHTML });
+}
+
+transformer.register( "hideIPA", function( 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 = document.createElement( 'span' );
+ parentSpan.parentNode.insertBefore(containerSpan, parentSpan);
+ parentSpan.parentNode.removeChild(parentSpan);
+
+ //create and add the button
+ var buttonDiv = document.createElement( 'div' );
+ buttonDiv.classList.add('ipa_button');
+ containerSpan.appendChild(buttonDiv);
+ containerSpan.appendChild(parentSpan);
+
+ //set initial visibility
+ parentSpan.style.display = 'none';
+ //and assign the click handler to it
+ containerSpan.onclick = ipaClickHandler;
+ }
+ return content;
+} );
+
transformer.register( "section", function( content ) {
if ( window.isNightMode ) {
night.invertElement ( content );
--
To view, visit https://gerrit.wikimedia.org/r/165650
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie084658807cfa7037ee14c6b1a991cc77ac58391
Gerrit-PatchSet: 11
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits