anchor.diff:        , 1
   
   # Event helpers
  +
   eventIsSignificant = (event) ->
     not (
       event.defaultPrevented or
  
positive.code:       summary.setAttribute("aria-expanded", true)
  
  polyfillFocusAndARIA = ->
    summaries = document.querySelectorAll("summary")
    for summary in summaries
      addAttributesForSummary(summary)
    if MutationObserver?
      observer = new MutationObserver (mutations) ->
        for {addedNodes} in mutations
          for target in addedNodes
            if target.tagName is "DETAILS"
              summary = target.querySelector("summary")
              addAttributesForSummary(summary, target) if summary
      observer.observe(document.documentElement, subtree: true, childList: true)
    else
      document.addEventListener("DOMNodeInserted", (event) ->
        if event.target.tagName is "SUMMARY"
          addAttributesForSummary event.target
      )
  
  addAttributesForSummary = (summary, details) ->
    details = findClosestElementWithTagName(summary, "DETAILS") unless details
    summary.setAttribute("tabindex", "0") unless summary.hasAttribute("tabindex")
    summary.setAttribute("aria-expanded", details.hasAttribute("open"))
    summary.setAttribute("role", "button")
  
  polyfillToggleEvent = ->
    if MutationObserver?
  
negative.code:   )
  
  onTogglingTrigger = (callback) ->
    addEventListener "click", (event) ->
      if eventIsSignificant(event) and event.which <= 1
        if element = findClosestElementWithTagName(event.target, "SUMMARY")
          if element.parentElement?.tagName is "DETAILS"
            callback(element.parentElement)
    , false
  
    addEventListener "keydown", (event) ->
      if eventIsSignificant(event) and event.keyCode in [13, 32]
        if element = findClosestElementWithTagName(event.target, "SUMMARY")
          if element.parentElement?.tagName is "DETAILS"
            callback(element.parentElement)
            # Prevent pagedown from space key
            event.preventDefault()
    , false
  
  findClosestElementWithTagName = do ->
    if typeof Element::closest is "function"
  