From 75dbdb16dd158b71ba071e3475c8bf90e3c57e52 Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Fri, 26 Sep 2025 07:52:35 +0200 Subject: [PATCH] MBS-10330: Avoid jumping when reloading map --- lib.php | 10 +++++++++- templates/rendercontainer.mustache | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 3a7d6ff3..cf8397ed 100644 --- a/lib.php +++ b/lib.php @@ -234,7 +234,7 @@ function learningmap_cm_info_dynamic(cm_info $cm): void { * @return void */ function learningmap_cm_info_view(cm_info $cm): void { - global $DB, $OUTPUT; + global $DB, $OUTPUT, $_REQUEST; $learningmap = $DB->get_record('learningmap', ['id' => $cm->instance]); $intro = ''; @@ -269,6 +269,13 @@ function learningmap_cm_info_view(cm_info $cm): void { $contentbeforemap = $groupdropdown . $intro; $hascontentbeforemap = !empty($contentbeforemap); + $mapcontent = null; + + if (!empty($_REQUEST['info']) && $_REQUEST['info'] == 'core_course_get_module') { + // If this is an ajax request to get the cm, we need to return only the map code. + $mapcontent = learningmap_get_learningmap($cm); + } + $mapcontainer = $OUTPUT->render_from_template( 'mod_learningmap/rendercontainer', [ @@ -276,6 +283,7 @@ function learningmap_cm_info_view(cm_info $cm): void { 'enableLiveUpdater' => true, 'contentbeforemap' => $contentbeforemap, 'hascontentbeforemap' => $hascontentbeforemap, + 'mapcontent' => $mapcontent, ] ); diff --git a/templates/rendercontainer.mustache b/templates/rendercontainer.mustache index 81bd9da4..b23a5c5e 100644 --- a/templates/rendercontainer.mustache +++ b/templates/rendercontainer.mustache @@ -44,13 +44,16 @@ {{/hascontentbeforemap}}
- {{> mod_learningmap/loadingplaceholder}} + {{^mapcontent}}{{> mod_learningmap/loadingplaceholder}}{{/mapcontent}} + {{{mapcontent}}}
{{#js}} + {{^mapcontent}} require(['mod_learningmap/renderer'], function(renderer) { renderer.init({{cmId}}); }); + {{/mapcontent}} {{#enableLiveUpdater}} require(['mod_learningmap/initliveupdater'], function(initliveupdater) { initliveupdater.init({{cmId}});