Skip to content

Commit

Permalink
Merge pull request #47 from Islandora/save-instance
Browse files Browse the repository at this point in the history
Save mirador instances in the DOM
  • Loading branch information
alxp authored Jul 18, 2024
2 parents 87d5248 + e13486c commit c6051ef
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions js/mirador_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@
*/
Drupal.behaviors.Mirador = {
attach: function (context, settings) {
Drupal.IslandoraMirador = Drupal.IslandoraMirador || {}
Drupal.IslandoraMirador.instances = Drupal.IslandoraMirador.instances || {}
Object.entries(settings.mirador.viewers).forEach(entry => {
const [base, values] = entry;
once('mirador-viewer', base, context).forEach(() =>
Mirador.viewer(values, window.miradorPlugins || {})
// save the mirador instance so other modules can interact
// with the store/actions at e.g. Drupal.IslandoraMirador.instances["#mirador-xyz"].store
Drupal.IslandoraMirador.instances[base] = Mirador.viewer(values, window.miradorPlugins || {})
);
});
},
detach: function (context, settings) {
Object.entries(settings.mirador.viewers).forEach(entry => {
const [base, ] = entry;
once.remove('mirador-viewer', base, context);
const removed = once.remove('mirador-viewer', base, context);
if (removed.length > 0) {
delete Drupal.IslandoraMirador.instances[base];
}
});
}
};
Expand Down

0 comments on commit c6051ef

Please sign in to comment.