From b08e6e68b5de4d51d303e22151f7ee828b483446 Mon Sep 17 00:00:00 2001 From: dmouriss Date: Wed, 11 May 2016 17:55:09 +0200 Subject: [PATCH 1/3] Fix #59: mathjax is only run when necessary --- app/assets/javascripts/exercise.js | 12 +++- .../javascripts/strip/strip.pkgd.min.js | 56 ++++++++++++++----- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/exercise.js b/app/assets/javascripts/exercise.js index c3e8b98e67..58847f563f 100644 --- a/app/assets/javascripts/exercise.js +++ b/app/assets/javascripts/exercise.js @@ -7,10 +7,12 @@ function init_exercise_show(exerciseId, loggedIn, tests) { centerImagesAndTables(); + // create feedback table var feedbackTable = new FeedbackTable(tests); $("#feedback-loading").hide(); + // test source code if button is clicked on editor panel $("#editor-process-btn").click(function () { // test submitted source code @@ -34,8 +36,6 @@ function init_exercise_show(exerciseId, loggedIn, tests) { $('#exercise-feedback-link').tab('show'); }); - MathJax.Hub.Typeset(); - // hide/show correct test cases if button is clicked in menu on feedback // panel $("#feedback-menu-toggle-correct").click(function () { @@ -51,6 +51,14 @@ function init_exercise_show(exerciseId, loggedIn, tests) { $(this).dropdown('toggle'); return false; }); + + MathJax.Hub.Queue(function() { + elements = MathJax.Hub.getAllJax(); + /* MathJax should be rerun/run */ + if (elements.length !== 0 || $('span.MathJax').length === 0) { + MathJax.Hub.Queue(["Typeset",MathJax.Hub]); + } + }); } function initEditor() { diff --git a/vendor/assets/javascripts/strip/strip.pkgd.min.js b/vendor/assets/javascripts/strip/strip.pkgd.min.js index 1fc761e7b3..b7a1475b85 100755 --- a/vendor/assets/javascripts/strip/strip.pkgd.min.js +++ b/vendor/assets/javascripts/strip/strip.pkgd.min.js @@ -765,23 +765,51 @@ function initStrip() { d = this.view && this.view.options.onShow; "function" == $.type(d) && d.call(Strip); - /* MathJax in caption */ + /* BEGIN MathJax in caption */ + + function _resize(element) { + var e = Window.resize(element[c], function() { + --b < 1 && a() + }, e); + return e; + } + + var numberMathJax = 0; if (typeof MathJax !== 'undefined') { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, "div.strp-caption"]); - MathJax.Hub.Queue(function() { - $("div.strp-caption div.MathJax_Display").each(function() { - $(this).contents().unwrap(); - }); - //force resize after mathjax is done - var a; - (a = Pages.page) && (a.animated || a.animatingWindow ? (a.fitToWindow(), a.show()) : (a.fitToWindow(), Window.resize(a.z, null, 0), Window.adjustPrevNext(null, !0))) - - }) + + $('div.strp-caption').each(function() { + //There is math in this caption + if ($(this).html().indexOf('$$') > -1) { + numberMathJax += 1; + MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this)[0]]); + } + }); + + parent = this; + + if (numberMathJax > 0) { + + MathJax.Hub.Queue(function() { + $("div.strp-caption div.MathJax_Display").each(function() { + $(this).contents().unwrap(); + }); + e = _resize(this); + //force explicit resize after mathjax is done + var a; + (a = Pages.page) && (a.animated || a.animatingWindow ? (a.fitToWindow(), a.show()) : (a.fitToWindow(), Window.resize(a.z, null, 0), Window.adjustPrevNext(null, !0))) + }) + + } else { + var e = _resize(this); + } + + + } else { + var e = _resize(this); } - var e = Window.resize(this[c], function() { - --b < 1 && a() - }, e); + /* END MathJax in caption */ + this._show(function() { --b < 1 && a() }, e), Window.adjustPrevNext(function() { From 9ef28ef8014466eb5cebd017a7fb474164e6cf65 Mon Sep 17 00:00:00 2001 From: dmouriss Date: Fri, 13 May 2016 11:48:54 +0200 Subject: [PATCH 2/3] Improved mathjax fix --- app/assets/javascripts/exercise.js | 5 ++--- vendor/assets/javascripts/strip/strip.pkgd.min.js | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/exercise.js b/app/assets/javascripts/exercise.js index 58847f563f..a62a4b9dbe 100644 --- a/app/assets/javascripts/exercise.js +++ b/app/assets/javascripts/exercise.js @@ -53,9 +53,8 @@ function init_exercise_show(exerciseId, loggedIn, tests) { }); MathJax.Hub.Queue(function() { - elements = MathJax.Hub.getAllJax(); - /* MathJax should be rerun/run */ - if (elements.length !== 0 || $('span.MathJax').length === 0) { + /* MathJax has not been run yet*/ + if ($('span.MathJax').length === 0) { MathJax.Hub.Queue(["Typeset",MathJax.Hub]); } }); diff --git a/vendor/assets/javascripts/strip/strip.pkgd.min.js b/vendor/assets/javascripts/strip/strip.pkgd.min.js index b7a1475b85..b0573e2f16 100755 --- a/vendor/assets/javascripts/strip/strip.pkgd.min.js +++ b/vendor/assets/javascripts/strip/strip.pkgd.min.js @@ -778,7 +778,7 @@ function initStrip() { if (typeof MathJax !== 'undefined') { $('div.strp-caption').each(function() { - //There is math in this caption + //There is math in this caption -> Typeset it if ($(this).html().indexOf('$$') > -1) { numberMathJax += 1; MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this)[0]]); @@ -787,6 +787,7 @@ function initStrip() { parent = this; + /* Put Mathjax inline, but only when necessary */ if (numberMathJax > 0) { MathJax.Hub.Queue(function() { From cd58505677236d65210b3d3fe09534b3f7520472 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Tue, 7 Jun 2016 11:40:40 +0200 Subject: [PATCH 3/3] user must be logged in to test code --- app/views/exercises/show.html.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/exercises/show.html.erb b/app/views/exercises/show.html.erb index e7ed3823ff..6b7b4b70c9 100644 --- a/app/views/exercises/show.html.erb +++ b/app/views/exercises/show.html.erb @@ -23,9 +23,11 @@
+ <% if user_signed_in? %> + <% end %>