From 385d6236270b08bee2ca0d205206e5f3690ce7c0 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 12 Feb 2018 12:32:43 +0100
Subject: [PATCH] aftre refreshing mathml tags mathjax is called to process
 them again

---
 frontend-js/src/main/js/map/AbstractCustomMap.js     |  4 +++-
 .../src/main/js/map/window/AbstractInfoWindow.js     | 12 ++++++------
 .../src/main/js/map/window/ReactionInfoWindow.js     |  5 -----
 .../test/js/map/window/ReactionInfoWindow-test.js    |  8 ++++----
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js
index 0241373a2a..0793b60d3b 100644
--- a/frontend-js/src/main/js/map/AbstractCustomMap.js
+++ b/frontend-js/src/main/js/map/AbstractCustomMap.js
@@ -805,10 +805,12 @@ AbstractCustomMap.prototype._openInfoWindowForReaction = function (reaction, goo
       infoWindow = new ReactionInfoWindow({
         reaction: reaction,
         map: self,
-        marker: googleMarker,
+        marker: googleMarker
       });
       self._reactionInfoWindow[reaction.getId()] = infoWindow;
       return infoWindow.init();
+    }).then(function () {
+      return infoWindow.open();
     }).then(function () {
       return infoWindow;
     });
diff --git a/frontend-js/src/main/js/map/window/AbstractInfoWindow.js b/frontend-js/src/main/js/map/window/AbstractInfoWindow.js
index 7b0378b139..544fb08307 100644
--- a/frontend-js/src/main/js/map/window/AbstractInfoWindow.js
+++ b/frontend-js/src/main/js/map/window/AbstractInfoWindow.js
@@ -147,9 +147,10 @@ AbstractInfoWindow.prototype.open = function (newMarker) {
  *          new content of the window
  */
 AbstractInfoWindow.prototype.setContent = function (content) {
-  this._content = content;
-  if (this.googleInfowindow !== undefined) {
-    this.googleInfowindow.setContent(content);
+  var self = this;
+  self._content = content;
+  if (self.googleInfowindow !== undefined) {
+    self.googleInfowindow.setContent(content);
   }
 };
 
@@ -381,9 +382,8 @@ AbstractInfoWindow.prototype._updateContent = function () {
         contentDiv.appendChild(overlaysDiv);
       }
       self.setContent(contentDiv);
-
-      self.callListeners("onUpdate");
-
+      return self.callListeners("onUpdate");
+    }).then(function () {
       return contentDiv;
     });
   }
diff --git a/frontend-js/src/main/js/map/window/ReactionInfoWindow.js b/frontend-js/src/main/js/map/window/ReactionInfoWindow.js
index 1f566037b9..200384d00e 100644
--- a/frontend-js/src/main/js/map/window/ReactionInfoWindow.js
+++ b/frontend-js/src/main/js/map/window/ReactionInfoWindow.js
@@ -36,7 +36,6 @@ function ReactionInfoWindow(params) {
       return MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
     });
   }
-  self.googleInfowindow.open(self.getCustomMap().getGoogleMap(), self.getGoogleMarker());
 }
 
 ReactionInfoWindow.prototype = Object.create(AbstractInfoWindow.prototype);
@@ -88,10 +87,6 @@ ReactionInfoWindow.prototype.createContentDiv = function () {
     }).then(function (parameters) {
       result.appendChild(self.createSbmlParameterDiv(parameters));
       result.appendChild(self.createKineticsElementsDiv(reaction.getElements()));
-
-      if (global.MathJax !== undefined) {
-        return MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
-      }
     }).then(function () {
       return Promise.resolve(result);
     });
diff --git a/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js b/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js
index 125ab1088d..b8f33d0f26 100644
--- a/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js
+++ b/frontend-js/src/test/js/map/window/ReactionInfoWindow-test.js
@@ -32,7 +32,7 @@ describe('ReactionInfoWindow', function () {
     it("with invalid kinetics", function () {
       var map = helper.createCustomMap();
 
-      var reaction = helper.createReaction(map);
+      var reaction = helper.createReaction(map, true);
       reaction.setKineticLaw(new KineticLaw({
         definition: '<math xmlns="http://www.w3.org/1998/Math/MathML">' +
         '<apply xmlns="http://www.w3.org/1998/Math/MathML">' +
@@ -53,7 +53,7 @@ describe('ReactionInfoWindow', function () {
     it("with kinetics", function () {
       var map = helper.createCustomMap();
 
-      var reaction = helper.createReaction(map);
+      var reaction = helper.createReaction(map, true);
       reaction.setKineticLaw(new KineticLaw({
         definition: '<math xmlns="http://www.w3.org/1998/Math/MathML">' +
         '<apply xmlns="http://www.w3.org/1998/Math/MathML">' +
@@ -81,7 +81,7 @@ describe('ReactionInfoWindow', function () {
       var sbmlFunction = helper.createSbmlFunction();
       map.getModel().addSbmlFunction(sbmlFunction);
 
-      var reaction = helper.createReaction(map);
+      var reaction = helper.createReaction(map, true);
       reaction.setKineticLaw(helper.createKineticLaw());
       reaction.getKineticLaw().getFunctionIds().push(sbmlFunction.getId());
 
@@ -101,7 +101,7 @@ describe('ReactionInfoWindow', function () {
       var sbmlParameter = helper.createSbmlParameter();
       map.getModel().addSbmlParameter(sbmlParameter);
 
-      var reaction = helper.createReaction(map);
+      var reaction = helper.createReaction(map, true);
       reaction.setKineticLaw(helper.createKineticLaw());
       reaction.getKineticLaw().getParameterIds().push(sbmlParameter.getId());
 
-- 
GitLab