Displays an Altmetric badge on repository object pages using a DOI stored in a node field. Drupal 11 ready
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
781 B

/**
* @file
* Refreshes Altmetric badges inserted by Drupal AJAX or BigPipe.
*/
(function (Drupal, once) {
'use strict';
Drupal.behaviors.islandoraAltmetric = {
attach(context) {
// Altmetric scans the initial document itself. For later fragments,
// request another scan only when a previously unseen badge is present.
const candidates = Array.from(context.querySelectorAll('.altmetric-embed'));
if (context.matches && context.matches('.altmetric-embed')) {
candidates.push(context);
}
const badges = once('islandora-altmetric', candidates);
if (context !== document && badges.length && typeof window._altmetric_embed_init === 'function') {
window._altmetric_embed_init();
}
}
};
})(Drupal, once);