Module: Asciidoctor::Html::Popovers

Defined in:
lib/asciidoctor/html/popovers.rb

Overview

Configure the popovers for footnotes and citations.

Constant Summary collapse

POPOVERS =
<<~JS
  (function() {
    const popovers = []
    function initPopovers() {
      document.querySelectorAll('.btn-po[data-contentid]').forEach(el => {
        const id = el.dataset.contentid;
        let content = document.getElementById(id);
        if(content) {
          if(content.tagName == 'A') {
            // This is an anchor of a bibitem
            const listItem = content.parentElement.cloneNode(true)
            listItem.removeChild(listItem.firstChild)
            content = listItem
          }
          popovers.push(new bootstrap.Popover(el, {
            content: content,
            html: true,
            sanitize: false
          }));
        }
      });
    }
    addEventListener('click', e => {
      const match = e.target.closest('.btn-po[aria-describedby],.popover');
      if(!match) {
        popovers.forEach(po => po.hide());
      }
    })
    MathJax.startup.promise.then(initPopovers);
    addEventListener('load', function() {
      // Enable tooltips on images
      document.querySelectorAll('img[data-bs-toggle="tooltip"]').forEach(el => {
        bootstrap.Tooltip.getOrCreateInstance(el);
      });
    });
  })();
JS