Skip to content

Commit

Permalink
Using bigger wrappers for MathJax. This improves speed by a lot, arou…
Browse files Browse the repository at this point in the history
…nd 2-3 times faster.
  • Loading branch information
sebastsg committed Oct 31, 2018
1 parent 0f13d53 commit c2f7bfe
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion amd/build/core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/instructor.min.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions amd/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(['jquery', 'core/config', 'core/str', 'core/yui'], function ($, mConfig, mString, Y) {
define(['jquery', 'core/config', 'core/str', 'core/yui', 'core/event'], function ($, mConfig, mString, Y, mEvent) {

// Contains the needed values for using the ajax script.
let session = {
Expand Down Expand Up @@ -320,9 +320,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui'], function ($, mConfig,
* Triggers a dynamic content update event, which MathJax listens to.
*/
static renderAllMathjax() {
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {
nodes: new Y.NodeList(document.getElementsByClassName('jazzquiz-latex-wrapper'))
});
mEvent.notifyFilterContentUpdated(document.getElementsByClassName('jazzquiz-response-container'));
}

/**
Expand All @@ -331,7 +329,7 @@ define(['jquery', 'core/config', 'core/str', 'core/yui'], function ($, mConfig,
* @param {string} latex
*/
static addMathjaxElement($target, latex) {
$target.html('<span class="jazzquiz-latex-wrapper"><span class="filter_mathjaxloader_equation">' + latex + '</span></span>');
$target.html('<span class="filter_mathjaxloader_equation">' + latex + '</span>');
Quiz.renderAllMathjax();
}

Expand Down
3 changes: 1 addition & 2 deletions amd/src/instructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,7 @@ define(['jquery', 'mod_jazzquiz/core'], function ($, Jazz) {
return;
}
Ajax.get('get_right_response', {}, data => {
const answer = '<span class="jazzquiz-latex-wrapper">' + data.right_answer + '</span>';
Quiz.show(Instructor.correctAnswer.html(answer));
Quiz.show(Instructor.correctAnswer.html(data.right_answer));
Quiz.renderAllMathjax();
Quiz.check(Instructor.control('answer'));
this.isShowingCorrectAnswer = true;
Expand Down
8 changes: 3 additions & 5 deletions templates/edit_question_list.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="generalbox boxaligncenter jazzquiz-box">
<div class="generalbox boxaligncenter jazzquiz-box jazzquiz-response-container">
<div id="questionrow" class="row">
<div class="inline-block span6">
<h2>{{# str }} questions, jazzquiz {{/ str }}</h2>
Expand All @@ -13,10 +13,8 @@
{{{ icon }}}
</div>
<div class="name">
<span class="jazzquiz-latex-wrapper">
<span class="filter_mathjaxloader_equation">
{{{ name }}}
</span>
<span class="filter_mathjaxloader_equation">
{{{ name }}}
</span>
</div>
{{# first }}{{# pix }} spacer, core {{/ pix }}{{/ first }}
Expand Down
4 changes: 2 additions & 2 deletions templates/quiz.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div id="jazzquiz_control_separator"></div>
</div>
</div>
<div id="jazzquiz_correct_answer_container" class="jazzquiz-box hidden"></div>
<div id="jazzquiz_correct_answer_container" class="jazzquiz-response-container jazzquiz-box hidden"></div>
<div id="jazzquiz_side_container" class="jazzquiz-box">
<div id="jazzquiz_responded_container" class="jazzquiz-box">
<div>
Expand All @@ -46,6 +46,6 @@
<i class="fa fa-undo"></i>
</button>
</div>
<div id="jazzquiz_responses_container" class="jazzquiz-box hidden"></div>
<div id="jazzquiz_responses_container" class="jazzquiz-response-container jazzquiz-box hidden"></div>
{{/ instructor }}
</div>
12 changes: 4 additions & 8 deletions templates/report.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@
{{# str }} download_report, jazzquiz {{/str}}
</a>
</div>
<div id="report_overview_responses" class="hidden">
<div id="report_overview_responses" class="jazzquiz-response-container hidden">
{{# slots }}
<div class="jazzquiz-box">
<h2>
<span class="jazzquiz-latex-wrapper">
<span class="filter_mathjaxloader_equation">
<span class="filter_mathjaxloader_equation">
{{{ name }}}
</span>
</span>
</h2>
<span class="jazzquiz-latex-wrapper">
<span class="filter_mathjaxloader_equation">
{{{ description }}}
</span>
<span class="filter_mathjaxloader_equation">
{{{ description }}}
</span>
<table id="responses_wrapper_table_{{ num }}" class="jazzquiz-responses-overview"></table>
<br>
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018103101; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2018103102; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2016052304; // Moodle 3.1 (or above)
$plugin->cron = 0; // Period in seconds for cron to run.
$plugin->component = 'mod_jazzquiz';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '0.9.1 (Build: 2018103101)';
$plugin->release = '0.9.1 (Build: 2018103102)';

0 comments on commit c2f7bfe

Please sign in to comment.