Skip to content

Module upgrades and bug fixes #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Image Map",
"namespace": "ImageMap\\ExternalModule",
"description": "This module replaces an input, radio, or checkbox field with an interactive image where users can click on image regions to select one or more field options. Find the complete <b><a href='https://github.com/ctsit/imagemap' target='_blank'>documentation</a></b> and <b><a href='https://github.com/ctsit/imagemap/blob/master/docs/' target='_blank'>example instruments</a></b> on GitHub ",
"framework-version": 14,
"framework-version": 16,
"authors": [
{
"name": "University of Florida CTS-IT",
Expand Down
5 changes: 4 additions & 1 deletion docs/DEVELOPER_README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Notes on ImageMapster.js

The original creator's [repo](https://github.com/jamietre/ImageMapster) is no longer being maintained. Several forks exist, but they also see minimal commit frequency. The current local minified `imagemapster.js` is based on [this fork](https://github.com/davintoo/ImageMapster), specifically, [this commit](https://github.com/davintoo/ImageMapster/commit/47145f22cabb8ac3a415da3e5843fd204bb0abca) from another user who has not been active since March 2018.
The original creator's [repo](https://github.com/jamietre/ImageMapster) has a JavaScript eval() in the [imageMapster.js](https://github.com/jamietre/ImageMapster/blob/main/dist/jquery.imagemapster.js) in a test code. To remove this, we have followed the following steps:

- Remove the lines that use eval() in the [imageMapster.js](https://github.com/jamietre/ImageMapster/blob/2e6f0eaf9093b4407dffb84ef8bebf0769802d38/dist/jquery.imagemapster.js#L1325-L1327).
- Used an [online tool](https://www.toptal.com/developers/javascript-minifier) to minify the code.
20 changes: 7 additions & 13 deletions js/imageMapster.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions js/jsmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

// Startup function for data entry pages with imagemaps
start: function () {
/*
* Ensure idempotency: if this function has already run once (e.g., the
* form was re‑rendered after a language switch), first clean up any
* existing ImageMapster bindings and DOM elements before redrawing.
*/
if (module._initialized) {
module.cleanup();
}
module._initialized = true;
// Render each imagemap and create a pointer to it by field_name
if (!module.data) module.data = {};
module.data.fields = {};
Expand All @@ -28,6 +37,16 @@
$('#form').animate({ opacity: 1 }, 250);
},

// Cleanup function to remove imagemaps and bindings
cleanup: function () {
$('.imagemap').each(function () {
const $img = $('img', this);
try { $img.mapster('unbind'); } catch (e) { /* already unbound */ }
$(this).remove();
});
if (module.data) { module.data.fields = {}; }
},

// Startup function for online designer helper
onlineDesignerStart: function () {
module.log("Online Designer ImageMap Start");
Expand Down