From 72703d9ae88ae12dd92117dc819eeb71f71c1238 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Palma Date: Wed, 16 Oct 2024 23:12:28 -0400 Subject: [PATCH] fix: remove error ReferenceError: JavascriptLoader is not defined in Zoom Image Tool --- xmodule/templates/html/zooming_image.yaml | 86 +++++++++++++++++------ 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/xmodule/templates/html/zooming_image.yaml b/xmodule/templates/html/zooming_image.yaml index b91717550b27..00567a2e1708 100644 --- a/xmodule/templates/html/zooming_image.yaml +++ b/xmodule/templates/html/zooming_image.yaml @@ -14,17 +14,39 @@ data: | <img alt="Text for screen readers" src="path to the image you want to display in the unit" /> </a> - <div class="script_placeholder" - data-src="path to the jquery.loupeAndLightbox.js JavaScript file in your course"/> - </div> <script type="text/javascript">// >![CDATA[ - JavascriptLoader.executeModuleScripts($('.zooming-image-place').eq(0), function() { - $('.loupe').loupeAndLightbox({ - width: 350, - height: 350, - lightbox: false + function loadScript(url, callback) { + let script = document.createElement("script"); + script.type = "text/javascript"; + + if (script.readyState) { // IE + script.onreadystatechange = function() { + if (script.readyState === "loaded" || script.readyState === "complete") { + script.onreadystatechange = null; + callback(); + } + }; + } else { // Other browsers + script.onload = function() { + callback(); + }; + } + + script.src = url; + document.head.appendChild(script); + } + + function callback() { + JavascriptLoader.executeModuleScripts($('.zooming-image-place').eq(0), function() { + $('.loupe').loupeAndLightbox({ + width: 350, + height: 350, + lightbox: false + }); }); - }); + } + + loadScript("path to jquery.loupeAndLightbox.js JavaScript file to your course", callback); // ]]></script> <div id="ap_listener_added"></div> @@ -34,24 +56,48 @@ data: |
  • Replace the value of the link's href attribute with the path to the magnified image. Do not change the value of the class attribute.
  • Replace the value of the image's src attribute with the path to the image that will appear in the unit.
  • Replace the value of the image's alt attribute with text that both describes the image and the action or destination of clicking on the image. You must include alt text to provide an accessible label.
  • -
  • Replace the value of the div element's data-src attribute with the path to the jquery.loupeAndLightbox.js JavaScript file in your course.
  • +
  • Replace the value of the first parameter in loadScript function with the path to the jquery.loupeAndLightbox.js JavaScript file in your course.
  • The example below shows a subset of the biochemical reactions that cells carry out.

    You can view the chemical structures of the molecules by clicking on them. The magnified view also lists the enzymes involved in each step.

    Press spacebar to open the magnifier.

    - magnify - -
    + magnify +