Skip to content

Commit

Permalink
Merge pull request #67 from prasanna-lmsace/moodle_44_dev
Browse files Browse the repository at this point in the history
Improvement: Update for Moodle 4.4 compatibility and improved MathJax support 1658984705
  • Loading branch information
HAASLEWER authored Oct 10, 2024
2 parents 796639d + f9b100a commit 53e396d
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 43 deletions.
3 changes: 3 additions & 0 deletions amd/build/initmathjax-backward.min.js

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

1 change: 1 addition & 0 deletions amd/build/initmathjax-backward.min.js.map

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

23 changes: 2 additions & 21 deletions amd/build/initmathjax.min.js

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

1 change: 1 addition & 0 deletions amd/build/initmathjax.min.js.map

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

22 changes: 22 additions & 0 deletions amd/src/initmathjax-backward.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(["jquery", "core/ajax"], function ($, Ajax) {
return {
init: function () {
$(document).ready(function () {
// Initialise MathJax typesetting
var nodes = Y.all(".latex-math");
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, { nodes: nodes });

var waitForMathJax = setInterval(function () {
try {
if (MathJax) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
clearInterval(waitForMathJax);
}
} catch (e) {
// MathJax has not yet been loaded.
}
}, 100);
});
},
};
});
72 changes: 53 additions & 19 deletions amd/src/initmathjax.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
define(["jquery", "core/ajax"], function ($, Ajax) {
return {
init: function () {
$(document).ready(function () {
// Initialise MathJax typesetting
var nodes = Y.all(".latex-math");
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, { nodes: nodes });

var waitForMathJax = setInterval(function () {
try {
if (MathJax) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
clearInterval(waitForMathJax);
define(["jquery", "core/ajax", "core_filters/events"], function ($, Ajax, FilterEvents) {

// Selectors and other strings defined here.
const SELECTORS = {
root: '.monassis',
mathEquation: '.latex-math',
questionContent: '.question-content',
classes: {
filterMathjax: 'filter_mathjaxloader_equation'
}
};

// Parent element of the questions.
const root = document.querySelector(SELECTORS.root);

const mathJaxFilterByEvents = function() {

/**
* Update the equations by mathjax filter.
*/
function updateMathJax() {

if (root.querySelector(SELECTORS.questionContent) === null) {
return false;
}

// Initialise MathJax typesetting.
root.querySelector(SELECTORS.questionContent).classList.add(SELECTORS.classes.filterMathjax);
// Notifiy the siyavula filtered content are updated.
FilterEvents.notifyFilterContentUpdated(document.querySelectorAll(SELECTORS.root));

return true;

}

// Update the equations, if the content loaded before JS initiated.
var waitForMathJax = setInterval(function() {
try {
if (window.MathJax && updateMathJax()) {
window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub]);
clearInterval(waitForMathJax);
}
} catch (e) {
// MathJax has not yet been loaded.
}
} catch (e) {
// MathJax has not yet been loaded.
}
}, 100);
});
},
};

};

return {

init: function () {
mathJaxFilterByEvents();
},
};
});
2 changes: 2 additions & 0 deletions classes/renderables/activity_renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class activity_renderable implements \renderable {
public $token;
public $usertoken;
public $activitytype;
public $showlivepreview;
public $templatelist;
}
13 changes: 12 additions & 1 deletion filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function filter($text, array $options = array()) {
$showlivepreview = $siyavulaconfig->showlivepreview;
$baseurl = $siyavulaconfig->url_base;

$result = $PAGE->requires->js_call_amd('filter_siyavula/initmathjax', 'init');

$result = '';

if ($activitytype == 'standalone') {
list($templateid, $randomseed) = $this->get_standalone_activity_data($text);
Expand Down Expand Up @@ -214,9 +215,19 @@ public function filter($text, array $options = array()) {

// Render questions not apply format siyavula.
if (!empty($result)) {

// Current version is Moodle 3.9 or higher use the event types. Otherwise use the older versions.
if ($CFG->version >= 2022041904) {
$PAGE->requires->js_call_amd('filter_siyavula/initmathjax', 'init');
} else {
$PAGE->requires->js_call_amd('filter_siyavula/initmathjax-backward', 'init');
}

return $result;

} else {
return $text;
}

}
}
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

form#form_test_token{
padding-top: 60px;
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

defined('MOODLE_INTERNAL') || die();
$plugin->version = 2023121300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2023121301; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2019111809; // Requires this Moodle version
$plugin->component = 'filter_siyavula'; // Full name of the plugin (used for diagnostics)
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 53e396d

Please sign in to comment.