Created
May 10, 2019 23:03
-
-
Save pqnelson/ec47a00ee6b71eb71648177e2423620d to your computer and use it in GitHub Desktop.
The Javascript for 538 footnotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- https://fivethirtyeight.com/features/who-wants-to-be-a-senator-not-these-high-profile-democrats/ --> | |
<p>Remember that in 2016, <a href="http://crystalball.centerforpolitics.org/crystalball/articles/senate-observations-placing-2018-in-the-context-of-upper-chamber-elections-since-1913/">for the</a> <a href="https://fivethirtyeight.com/features/there-were-no-purple-states-on-tuesday/">first time</a>,<a class="espn-footnote-link espn-footnote-item-expanded" data-footnote-id="1" href="#fn-1" data-footnote-content="<p>Or at least since popular Senate elections began <a href="https://constitutioncenter.org/interactive-constitution/amendments/amendment-xvii">after the ratification</a> of the 17th Amendment in 1913.</p> | |
"><sup id="ss-1">x</sup></a><span class="espn-footnote-item espn-footnote-item-displayed espn-footnote-item-expanded"><span class="espn-footnote-item-inner"><span><p>Or at least since popular Senate elections began <a href="https://constitutioncenter.org/interactive-constitution/amendments/amendment-xvii" target="_blank" rel="noopener noreferrer">after the ratification</a> of the 17th Amendment in 1913.</p> | |
</span></span></span> <i>every</i> Senate race was won by the same party that won the presidential vote in that state. In a <a href="https://www.people-press.org/interactives/political-polarization-1994-2017/">polarized era</a> full of <a href="https://fivethirtyeight.com/features/split-ticket-voting-hit-a-new-low-in-2018-senate-and-governor-races/">straight-ticket voters</a>, this is no doubt a prime consideration when potential candidates are deciding whether to run. And as the table below shows, by our count, there’s at least one major Democratic player who has publicly said he or she won’t seek a Republican-held Senate seat in six states that President Trump won in 2016.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function n(e) { | |
var t,n,i,s,o,r,a=h(e), | |
l=parseInt(a.data("footnote-id"),10), | |
c=parseInt(a.find("sup").text(),10); | |
a.toggleClass("espn-footnote-item-expanded"), | |
c===l ? | |
(a.find("sup").text("x"), | |
(t=a.next(".espn-footnote-item")).length || ( | |
n=a.data("wrap"), | |
i=h("<span />", { | |
class:"espn-footnote-item "+(n?"footnote-wrap":"") | |
}), | |
s=h("<span />",{class:"espn-footnote-item-inner"}), | |
o=h("<span />",{html:a.attr("data-footnote-content")}), | |
s.append(o), | |
r=i.append(s), | |
a.after(r), | |
t=a.next(".espn-footnote-item")), | |
t.length && ( | |
t.addClass("espn-footnote-item-displayed"), | |
d.setTimeout(function() {t.addClass("espn-footnote-item-expanded")},50)), | |
espn && espn.track && espn.trackAndClear({ | |
link:"#"+l, | |
linkPos:d.s_omni.prop4, | |
linkId:"footnote:open:"+l, | |
site:"fivethirtyeight", | |
pageName:d.s_omni.pageName, | |
section:d.s_omni.channel})) : | |
(a.find("sup").text(l), | |
a.next(".espn-footnote-item").removeClass("espn-footnote-item-expanded"), | |
d.setTimeout(function() { | |
a.next(".espn-footnote-item").removeClass("espn-footnote-item-displayed")},300), | |
espn && espn.track && espn.trackAndClear({ | |
link:"#"+l, | |
linkPos:d.s_omni.prop4, | |
linkId:"footnote:close:"+l, | |
site:"fivethirtyeight", | |
pageName:d.s_omni.pageName, | |
section:d.s_omni.channel})) | |
} | |
function footnoteOnClickHandler(e) { | |
e.preventDefault(), e.altKey ? jQuery(".espn-footnote-link").each(function(e, t) { | |
n(t) | |
}) : n(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been wanting to incorporate this feature into an RMarkdown document for a while. Thank you for this! Now I just need to figure out how to call it in a markdown doc 👍