Amsterdam-Music-Lab / MUSCLE

An application to easily set up and run online listening experiments for music research.
https://www.amsterdammusiclab.nl/
MIT License
4 stars 1 forks source link

Fixed: `MarkdownPreview` widget's initialization issues #1253

Closed drikusroor closed 2 months ago

drikusroor commented 2 months ago

This PR fixes the following issues:

  1. First, whenever a form would have multiple markdown preview widgets, the widget's JavaScript would be loaded & initialized multiple times, thereby causing "redeclaration of MarkdownPreview class" errors. This is fixed by attaching the JavaScript separately as part of the widget's Media subclass. (same for the css)
  2. Whenever you would click "new exp/block translated content", a new form would be added dynamically by Djano. However, the newly added MarkdownPreview widget would not be "initialized" or "hydrated" as this process already happened on page load. This meant that the user could not preview the rendered markdown in newly added markdown preview widgets. The script is now extended by observing newly added form inputs and re-initializing all markdown preview widgets whenever that happens.