/* Copyright 2017-2021 Sean Williams This file is part of Modern Footnotes. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ function modern_footnotes_hide_footnotes(o){if(window.modernFootnotesOpenedFootnoteViaHover=!1,null!=o){o.data("unopenedContent")&&o.html(o.data("unopenedContent"));let t='.modern-footnotes-footnote__note[data-mfn="'+o.parent().attr("data-mfn")+'"]',e=o.parent().nextAll(t).eq(0);e.hide().css({left:"",top:""}),e.next(".modern-footnotes-footnote__connector").remove(),o.removeClass("modern-footnotes-footnote--selected"),o.attr("aria-pressed","false"),o.focus()}else jQuery(".modern-footnotes-footnote a").each(function(){var o=jQuery(this);o.data("unopenedContent")&&o.html(o.data("unopenedContent"))}),jQuery(".modern-footnotes-footnote > a").attr("aria-pressed","false"),jQuery(".modern-footnotes-footnote__note").hide().css({left:"",top:""}),jQuery(".modern-footnotes-footnote__connector").remove(),jQuery(".modern-footnotes-footnote--selected").removeClass("modern-footnotes-footnote--selected")}function modern_footnotes_show_tooltip_footnote(o,t){modern_footnotes_hide_footnotes(),o.toggleClass("modern-footnotes-footnote--selected");let e='.modern-footnotes-footnote__note[data-mfn="'+o.attr("data-mfn")+'"]';var n=o.nextAll(e).eq(0);n.show().addClass("modern-footnotes-footnote__note--tooltip").removeClass("modern-footnotes-footnote__note--expandable"),t||n.focus(),n.unbind("keydown").bind("keydown",function(t){"Escape"==t.key&&modern_footnotes_hide_footnotes(o.children("a"))});var s=o.position(),r=Math.floor(1.5*parseInt(o.parent().css("font-size").replace(/px/,""))),d=n.outerWidth(),f=(jQuery(window).width(),s.left-d/2);f<0&&(f=8),f+d>jQuery(window).width()&&(f=jQuery(window).width()-d);var i=parseInt(s.top)+parseInt(r);n.css({top:i+"px",left:f+"px"}),n.after('
');var a=o.position(),m=o.outerHeight(),l=o.outerWidth(),h=i-a.top-m;jQuery(".modern-footnotes-footnote__connector").css({top:a.top+m+"px",height:h,left:a.left+l/2+"px"})}jQuery(function(o){o(document).on("mouseenter",".modern-footnotes-footnote.modern-footnotes-footnote--hover-on-desktop a",null,function(t){o(window).width()>=768&&(window.modernFootnotesActivelyHovering=!0,window.modernFootnotesOpenedFootnoteViaHover=!0,modern_footnotes_show_tooltip_footnote(o(this).parent(),!0))}),o(document).on("mouseenter",".modern-footnotes-footnote__connector,.modern-footnotes-footnote__note",null,function(o){window.modernFootnotesActivelyHovering=!0}),o(document).on("mouseleave",".modern-footnotes-footnote.modern-footnotes-footnote--hover-on-desktop,.modern-footnotes-footnote.modern-footnotes-footnote--hover-on-desktop .modern-footnotes-footnote__connector,.modern-footnotes-footnote.modern-footnotes-footnote--hover-on-desktop .modern-footnotes-footnote__note",null,function(o){window.modernFootnotesActivelyHovering=!1,null!=window.modernFootnotesHoverCloseTimeout&&clearTimeout(window.modernFootnotesHoverCloseTimeout),window.modernFootnotesHoverCloseTimeout=setTimeout(function(){window.modernFootnotesHoverCloseTimeout=null,window.modernFootnotesActivelyHovering||modern_footnotes_hide_footnotes()},600)}),o(document).on("click",".modern-footnotes-footnote a",null,function(t){t.preventDefault(),t.stopPropagation(),next='.modern-footnotes-footnote__note[data-mfn="'+o(this).parent().attr("data-mfn")+'"]';var e=o(this).parent().nextAll(next).eq(0);e.is(":hidden")?o(window).width()>=768&&o(this).parent().is(":not(.modern-footnotes-footnote--expands-on-desktop)")?(modern_footnotes_show_tooltip_footnote(o(this).parent()),o(this).attr("aria-pressed","true")):(o(window).width()<768||o(this).parent().is(":not(.modern-footnotes-footnote--hover-on-desktop)"))&&(o(this).attr("aria-pressed","true"),e.removeClass("modern-footnotes-footnote__note--tooltip").addClass("modern-footnotes-footnote__note--expandable").css("display","block"),o(this).data("unopenedContent",o(this).html()),o(this).html("x")):modern_footnotes_hide_footnotes(o(this))}).on("click",".modern-footnotes-footnote__note",null,function(o){o.stopPropagation()}).on("click",function(){o(window).width()>=768&&0==o(".modern-footnotes-footnote--expands-on-desktop").length&&modern_footnotes_hide_footnotes()}),o(window).resize(function(){modern_footnotes_hide_footnotes()});var t=o("body .modern-footnotes-footnote a"),e={};t.length>1&&t.each(function(){var t=o(this).parent().attr("data-mfn-post-scope");if(void 0===e[t]&&(e[t]=[0]),o(this).is("a[data-mfn-reset]")&&(e[t]=[0]),o(this).is("a[refnum]")){var n=o(this).attr("refnum");o(this).html()!=n&&o(this).html(n),!isNaN(parseFloat(n))&&isFinite(n)&&e[t].push(n)}else{var s=Math.max.apply(null,e[t])+1;o(this).html()!=s&&o(this).html(s),e[t].push(s)}})});