<commit_before>'use strict'

app.directive 'tooltip', [
  '$window', '$timeout',
  (window, $timeout) ->
    restrict: 'E'
    scope: false
    require: '^tooltips',
    templateUrl: 'site/tooltip.html'
    link: ($scope, $element) ->
      tooltip = $scope.tooltip
      $scope.classes = [tooltip.cls]
      $scope.style = {}

      $timeout ->
        doc = window.document.documentElement
        box = tooltip.target.getBoundingClientRect()

        ww = doc.clientWidth
        wx = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0)
        center = box.left + box.width/2
        if 2*center > ww
          $scope.style.right = (ww - center - wx - 32) + 'px'
          $scope.classes.push('tooltip-left')
        else
          $scope.style.left = (center + wx - 32) + 'px'
          $scope.classes.push('tooltip-right')

        wh = doc.clientHeight
        wy = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0)
        if box.top + box.bottom > wh
          $scope.style.bottom = (wh - box.top - wy + 8) + 'px'
          $scope.classes.push('tooltip-top')
        else
          $scope.style.top = (box.bottom + wy + 8) + 'px'
          $scope.classes.push('tooltip-bottom')

        $scope.classes.push('tooltip-visible')
        return
]
<commit_msg>Safety check on tooltip target timeout<commit_after>'use strict'

app.directive 'tooltip', [
  '$window', '$timeout',
  (window, $timeout) ->
    restrict: 'E'
    scope: false
    require: '^tooltips',
    templateUrl: 'site/tooltip.html'
    link: ($scope, $element) ->
      tooltip = $scope.tooltip
      $scope.classes = [tooltip.cls]
      $scope.style = {}

      $timeout ->
        return unless tooltip.target
        doc = window.document.documentElement
        box = tooltip.target.getBoundingClientRect()

        ww = doc.clientWidth
        wx = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0)
        center = box.left + box.width/2
        if 2*center > ww
          $scope.style.right = (ww - center - wx - 32) + 'px'
          $scope.classes.push('tooltip-left')
        else
          $scope.style.left = (center + wx - 32) + 'px'
          $scope.classes.push('tooltip-right')

        wh = doc.clientHeight
        wy = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0)
        if box.top + box.bottom > wh
          $scope.style.bottom = (wh - box.top - wy + 8) + 'px'
          $scope.classes.push('tooltip-top')
        else
          $scope.style.top = (box.bottom + wy + 8) + 'px'
          $scope.classes.push('tooltip-bottom')

        $scope.classes.push('tooltip-visible')
        return
]

{'fraction_non_alphanumeric': 0.15299924069855733, 'fraction_numerical': 0.007593014426727411, 'mean_word_length': 2.0427251732101617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '336912', 'n_tokens_mistral': 859, 'n_tokens_neox': 827, 'n_words': 174}