{"version":3,"file":"footnote.js","names":["define","_exports","_core","_iconLibrary","_pluginApi","inlineFootnotePopper","footnoteEventHandler","event","tooltip","document","getElementById","displayedFootnoteId","dataset","footnoteId","expandableFootnote","target","destroy","removeAttribute","classList","contains","preventDefault","stopPropagation","footnoteContent","querySelector","cooked","closest","refPostId","newContent","innerHTML","show","createPopper","modifiers","name","options","element","altAxis","padding","offset","Object","defineProperty","value","default","initialize","container","lookup","display_footnotes_inline","body","append","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/icon-library\", \"discourse/lib/plugin-api\"], function (_exports, _core, _iconLibrary, _pluginApi) {\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\");\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    const template = document.createElement(\"template\");\n    template.innerHTML = `\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  `.trim();\n    return template.content.firstChild;\n  }\n  function footnoteEventHandler(event) {\n    const tooltip = document.getElementById(\"footnote-tooltip\");\n    const displayedFootnoteId = tooltip?.dataset.footnoteId;\n    const expandableFootnote = event.target;\n    const footnoteId = expandableFootnote.dataset.footnoteId;\n    inlineFootnotePopper?.destroy();\n    tooltip?.removeAttribute(\"data-show\");\n    tooltip?.removeAttribute(\"data-footnote-id\");\n    if (!event.target.classList.contains(\"expand-footnote\")) {\n      // dismissing the tooltip by clicking outside\n      return;\n    }\n    event.preventDefault();\n    event.stopPropagation();\n    if (displayedFootnoteId === footnoteId) {\n      // dismissing the tooltip by clicking the footnote button\n      return;\n    }\n\n    // append footnote to tooltip body\n    const footnoteContent = tooltip.querySelector(\".footnote-tooltip-content\");\n    let cooked = expandableFootnote.closest(\".cooked\");\n    if (cooked.dataset.refPostId != null) {\n      // For full screen tables, redirect\n      cooked = document.querySelector(`article[data-post-id=\"${cooked.dataset.refPostId}\"] .cooked`);\n    }\n    const newContent = cooked.querySelector(footnoteId);\n    footnoteContent.innerHTML = newContent.innerHTML;\n\n    // display tooltip\n    tooltip.dataset.show = \"\";\n    tooltip.dataset.footnoteId = footnoteId;\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.body.append(buildTooltip());\n      window.addEventListener(\"click\", footnoteEventHandler, true);\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          inlineFootnotePopper?.destroy();\n          const tooltip = document.getElementById(\"footnote-tooltip\");\n          tooltip?.removeAttribute(\"data-show\");\n          tooltip?.removeAttribute(\"data-footnote-id\");\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,0JAAAC,EAAAC,EAAAC,EAAAC,GACA;AAMA,IAAAC;AA8BA,SAAAC,EAAAC,GACA,MAAAC,EAAAC,SAAAC,eAAA,oBACAC,EAAAH,GAAAI,QAAAC,WACAC,EAAAP,EAAAQ,OACAF,EAAAC,EAAAF,QAAAC;AAIA,GAHAR,GAAAW,UACAR,GAAAS,gBAAA,a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