{"version":3,"file":"footnote.js","names":["define","_exports","_core","_pluginApi","_iconLibrary","inlineFootnotePopper","footNoteEventHandler","event","destroy","tooltip","document","getElementById","removeAttribute","target","classList","contains","preventDefault","stopPropagation","expandableFootnote","cooked","closest","footnoteId","dataset","footnoteContent","querySelector","newContent","innerHTML","show","createPopper","modifiers","name","options","element","altAxis","padding","offset","Object","defineProperty","value","default","initialize","container","lookup","display_footnotes_inline","documentElement","append","html","template","createElement","trim","content","firstChild","buildTooltip","window","addEventListener","withPluginApi","api","decorateCookedElement","elem","footnoteRefs","querySelectorAll","forEach","footnoteRef","refLink","add","iconHTML","href","role","getAttribute","after","length","applyInlineFootnotes","onlyStream","id","onPageChange","teardown","removeEventListener","remove","setup","helper","registerOptions","opts","siteSettings","features","markdownitFootnote","enable_markdown_footnotes","allowList","custom","tag","match","registerPlugin"],"sources":["discourse/plugins/footnote/initializers/inline-footnotes.js","discourse/plugins/footnote/lib/discourse-markdown/footnotes.js"],"sourcesContent":["define(\"discourse/plugins/footnote/initializers/inline-footnotes\", [\"exports\", \"@popperjs/core\", \"discourse/lib/plugin-api\", \"discourse-common/lib/icon-library\"], function (_exports, _core, _pluginApi, _iconLibrary) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  let inlineFootnotePopper;\n  function applyInlineFootnotes(elem) {\n    const footnoteRefs = elem.querySelectorAll(\"sup.footnote-ref\");\n    footnoteRefs.forEach(footnoteRef => {\n      const refLink = footnoteRef.querySelector(\"a\");\n      if (!refLink) {\n        return;\n      }\n      const expandableFootnote = document.createElement(\"a\");\n      expandableFootnote.classList.add(\"expand-footnote\");\n      expandableFootnote.innerHTML = (0, _iconLibrary.iconHTML)(\"ellipsis-h\");\n      expandableFootnote.href = \"\";\n      expandableFootnote.role = \"button\";\n      expandableFootnote.dataset.footnoteId = refLink.getAttribute(\"href\");\n      footnoteRef.after(expandableFootnote);\n    });\n    if (footnoteRefs.length) {\n      elem.classList.add(\"inline-footnotes\");\n    }\n  }\n  function buildTooltip() {\n    let html = `\n    <div id=\"footnote-tooltip\" role=\"tooltip\">\n      <div class=\"footnote-tooltip-content\"></div>\n      <div id=\"arrow\" data-popper-arrow></div>\n    </div>\n  `;\n    let template = document.createElement(\"template\");\n    html = html.trim();\n    template.innerHTML = html;\n    return template.content.firstChild;\n  }\n  function footNoteEventHandler(event) {\n    inlineFootnotePopper?.destroy();\n    const tooltip = document.getElementById(\"footnote-tooltip\");\n\n    // reset state by hidding tooltip, it handles \"click outside\"\n    // allowing to hide the tooltip when you click anywhere else\n    tooltip?.removeAttribute(\"data-show\");\n\n    // if we didn't actually click a footnote button, exit early\n    if (!event.target.classList.contains(\"expand-footnote\")) {\n      return;\n    }\n    event.preventDefault();\n    event.stopPropagation();\n\n    // append footnote to tooltip body\n    const expandableFootnote = event.target;\n    const cooked = expandableFootnote.closest(\".cooked\");\n    const footnoteId = expandableFootnote.dataset.footnoteId;\n    const footnoteContent = tooltip.querySelector(\".footnote-tooltip-content\");\n    let newContent = cooked.querySelector(footnoteId);\n    footnoteContent.innerHTML = newContent.innerHTML;\n\n    // display tooltip\n    tooltip.dataset.show = \"\";\n\n    // setup popper\n    inlineFootnotePopper?.destroy();\n    inlineFootnotePopper = (0, _core.createPopper)(expandableFootnote, tooltip, {\n      modifiers: [{\n        name: \"arrow\",\n        options: {\n          element: tooltip.querySelector(\"#arrow\")\n        }\n      }, {\n        name: \"preventOverflow\",\n        options: {\n          altAxis: true,\n          padding: 5\n        }\n      }, {\n        name: \"offset\",\n        options: {\n          offset: [0, 12]\n        }\n      }]\n    });\n  }\n  var _default = _exports.default = {\n    name: \"inline-footnotes\",\n    initialize(container) {\n      if (!container.lookup(\"service:site-settings\").display_footnotes_inline) {\n        return;\n      }\n      document.documentElement.append(buildTooltip());\n      window.addEventListener(\"click\", footNoteEventHandler);\n      (0, _pluginApi.withPluginApi)(\"0.8.9\", api => {\n        api.decorateCookedElement(elem => applyInlineFootnotes(elem), {\n          onlyStream: true,\n          id: \"inline-footnotes\"\n        });\n        api.onPageChange(() => {\n          document.getElementById(\"footnote-tooltip\")?.removeAttribute(\"data-show\");\n        });\n      });\n    },\n    teardown() {\n      inlineFootnotePopper?.destroy();\n      window.removeEventListener(\"click\", footNoteEventHandler);\n      document.getElementById(\"footnote-tooltip\")?.remove();\n    }\n  };\n});","define(\"discourse/plugins/footnote/lib/discourse-markdown/footnotes\", [\"exports\"], function (_exports) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.setup = setup;\n  function setup(helper) {\n    helper.registerOptions((opts, siteSettings) => {\n      opts.features[\"footnotes\"] = window.markdownitFootnote && !!siteSettings.enable_markdown_footnotes;\n    });\n    helper.allowList([\"ol.footnotes-list\", \"hr.footnotes-sep\", \"li.footnote-item\", \"a.footnote-backref\", \"sup.footnote-ref\"]);\n    helper.allowList({\n      custom(tag, name, value) {\n        if ((tag === \"a\" || tag === \"li\") && name === \"id\") {\n          return !!value.match(/^fn(ref)?\\d+$/);\n        }\n      }\n    });\n    if (window.markdownitFootnote) {\n      helper.registerPlugin(window.markdownitFootnote);\n    }\n  }\n});"],"mappings":"AAAAA,OAAA,iKAAAC,EAAAC,EAAAC,EAAAC,GACA;AAMA,IAAAC;AAgCA,SAAAC,EAAAC,GACAF,GAAAG;AACA,MAAAC,EAAAC,SAAAC,eAAA;AAOA,GAHAF,GAAAG,gBAAA,cAGAL,EAAAM,OAAAC,UAAAC,SAAA,mBACA;AAEAR,EAAAS,iBACAT,EAAAU;AAGA,MAAAC,EAAAX,EAAAM,OACAM,EAAAD,EAAAE,QAAA,WACAC,EAAAH,EAAAI,QAAAD,WACAE,EAAAd,EAAAe,cAAA;AACA,IAAAC,EAAAN,EAAAK,cAAAH;AACAE,EAAAG,UAAAD,EAAAC,UAGAjB,EAAAa,QAAAK,KAAA,GAGAtB,GAAAG,UACAH,GAAA,EAAAH,EAAA0B,cAAAV,EAAAT,EAAA,CACAoB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