<commit_before>#= require jquery.hoverIntent

#BUG/KNOWN LIMITATION: hoverIntent supports only one handler
#per event.  This means that you certainly cannot support
#more than 1 tooltip per element, but perhaps also not more
#than one per owner.  The workaround is likely to not use
#hoverIntent (sigh), if we ever need this.


Backbone.Factlink ||= {}
defaults =
  closingtimeout: 500
  #$el: owner
  #selector: what to hover over
  #makeTooltip: $el, $target -> $tooltip
  #removeTooltip: $el, $target, $tooltip ->

ttCounter = 0

#returns an object with a close method which when called
#removes all open tooltips
Backbone.Factlink.TooltipJQ = (cfg) ->
  uid = ttCounter++
  uidStr = 'tooltipUid-' + uid
  instCounter = 0
  instances = {}

  $el = cfg.$el
  _.defaults cfg, defaults

  openInstance = ($target) ->
    instId = 'tt' + instCounter++
    inTooltip = false
    inTarget = true

    $tooltip = cfg.makeTooltip $el, $target
    $tooltip.hoverIntent
      timeout: cfg.closingtimeout
      over: -> inTooltip = true; check()
      out: -> inTooltip = false; check()

    check = -> remove() if !(inTarget || inTooltip)
    remove = ->
      delete instances[instId]
      cfg.removeTooltip $el, $target, $tooltip
      $target.removeData(uidStr)

    instances[instId] =
      remove: remove
      setTargetHover: (state) -> inTarget = state; check()

    $target.data(uidStr, instId)

  hoverTarget = (inTarget) -> (e) ->
    $target = $(e.currentTarget)
    ttActions = instances[$target.data(uidStr)]
    if ttActions
      ttActions.setTargetHover inTarget
    else if inTarget
      openInstance $target

  $el.hoverIntent
    timeout: cfg.closingtimeout
    selector: cfg.selector
    over: hoverTarget true
    out: hoverTarget false

  close: -> for id, ttActions of instances
    ttActions.remove()
<commit_msg>Cleanup: rename cfg -> options.<commit_after>#= require jquery.hoverIntent

#BUG/KNOWN LIMITATION: hoverIntent supports only one handler
#per event.  This means that you certainly cannot support
#more than 1 tooltip per element, but perhaps also not more
#than one per owner.  The workaround is likely to not use
#hoverIntent (sigh), if we ever need this.


Backbone.Factlink ||= {}
defaults =
  closingtimeout: 500
  #$el: owner
  #selector: what to hover over
  #makeTooltip: $el, $target -> $tooltip
  #removeTooltip: $el, $target, $tooltip ->

ttCounter = 0

#returns an object with a close method which when called
#removes all open tooltips
Backbone.Factlink.TooltipJQ = (options) ->
  uid = ttCounter++
  uidStr = 'tooltipUid-' + uid
  instCounter = 0
  instances = {}

  $el = options.$el
  _.defaults options, defaults

  openInstance = ($target) ->
    instId = 'tt' + instCounter++
    inTooltip = false
    inTarget = true

    $tooltip = options.makeTooltip $el, $target
    $tooltip.hoverIntent
      timeout: options.closingtimeout
      over: -> inTooltip = true; check()
      out: -> inTooltip = false; check()

    check = -> remove() if !(inTarget || inTooltip)
    remove = ->
      delete instances[instId]
      options.removeTooltip $el, $target, $tooltip
      $target.removeData(uidStr)

    instances[instId] =
      remove: remove
      setTargetHover: (state) -> inTarget = state; check()

    $target.data(uidStr, instId)

  hoverTarget = (inTarget) -> (e) ->
    $target = $(e.currentTarget)
    ttActions = instances[$target.data(uidStr)]
    if ttActions
      ttActions.setTargetHover inTarget
    else if inTarget
      openInstance $target

  $el.hoverIntent
    timeout: options.closingtimeout
    selector: options.selector
    over: hoverTarget true
    out: hoverTarget false

  close: -> for id, ttActions of instances
    ttActions.remove()

{'fraction_non_alphanumeric': 0.10764262648008611, 'fraction_numerical': 0.0032292787944025836, 'mean_word_length': 3.2577319587628866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923688', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1122, 'n_words': 363}