<commit_before>define [
  'jquery'
  'underscore'
  'cs!helpers/backbone/views/base'
  'bootstrapPopover'
], ($, _, BaseView) ->

  # Close popovers when clicking on the document
  $(document).click (e) ->
    $el = $(document.elementFromPoint(e.clientX, e.clientY))

    # Don't clear the popover if clicking in it
    if not $el.parents().hasClass('popover')
      Popover.hidePopovers()

  return class Popover extends BaseView
    @popovers: []

    initialize: (params) ->
      if typeof params isnt 'object' or not params.owner
        throw new Error('Tried to initialize Popover, but no \'owner\' was defined.')

      @events = params.events
      @$owner = params.owner

      @$owner.popover(params.options)
      @constructor.popovers.push(@$owner)

      # Stop propogation of 'click' events so popover doesn't get auto-closed
      @$owner.on 'click', (e) => e.stopPropagation()

      # Attach event handler to close open popovers on show
      @$owner.on 'show.bs.popover', (e) =>
        @constructor.hidePopovers() # Close open popovers

      @$owner.on 'shown.bs.popover', (e) =>
        @setElement @$owner.data('bs.popover').$tip

        # Adjust popover positioning
        if params.options?.placement is 'bottom'
          @$el.find('.arrow').css({top: '-7px', left: '100%'})
          @$el.css
            'left': 'auto'
            'right': document.body.clientWidth - (@$owner.offset().left + @$owner.outerWidth())

        # Attach custom event handlers to popover
        @delegateEvents(@events)

      # Detach event handlers from popover on hide
      @$owner.on 'hide.bs.popover', (e) =>
        @undelegateEvents()

      # Show the popover immediately if option 'show' is true
      if params.show then @show()

    render: () -> return @ # noop

    @hidePopovers: () ->
      _.each @popovers, ($owner) ->
        popover = $owner.data('bs.popover')
        if popover.hoverState is 'in'
          $owner.popover('hide')
          popover.$tip.detach() # HACK: Bootstrap is not properly detaching the popover dom element

    @removePopover: ($el) ->
      @popovers = _.reject @popovers, ($popover) ->
        return _.isEqual($el, $popover)

    close: () ->
      @constructor.removePopover(@$owner)
      @$owner.popover('destroy')
      super()<commit_msg>Only delegate popover events once<commit_after>define [
  'jquery'
  'underscore'
  'cs!helpers/backbone/views/base'
  'bootstrapPopover'
], ($, _, BaseView) ->

  # Close popovers when clicking on the document
  $(document).click (e) ->
    $el = $(document.elementFromPoint(e.clientX, e.clientY))

    # Don't clear the popover if clicking in it
    if not $el.parents().hasClass('popover')
      Popover.hidePopovers()

  return class Popover extends BaseView
    @popovers: []

    initialize: (params) ->
      if typeof params isnt 'object' or not params.owner
        throw new Error('Tried to initialize Popover, but no \'owner\' was defined.')

      @events = params.events
      @$owner = params.owner

      @$owner.popover(params.options)
      @constructor.popovers.push(@$owner)

      # Stop propogation of 'click' events so popover doesn't get auto-closed
      @$owner.click (e) => e.stopPropagation()

      # Attach event handler to close open popovers on show
      @$owner.on 'show.bs.popover', (e) =>
        @constructor.hidePopovers() # Close open popovers

      @$owner.one 'shown.bs.popover', (e) =>
        @setElement @$owner.data('bs.popover').$tip
        @delegateEvents(@events) # Attach custom event handlers to popover

      @$owner.on 'shown.bs.popover', (e) =>
        # Adjust popover positioning
        if params.options?.placement is 'bottom'
          @$el.find('.arrow').css({top: '-7px', left: '100%'})
          @$el.css
            'left': 'auto'
            'right': document.body.clientWidth - (@$owner.offset().left + @$owner.outerWidth())

    render: () -> return @ # noop

    @hidePopovers: () ->
      _.each @popovers, ($owner) ->
        popover = $owner.data('bs.popover')
        if popover.hoverState is 'in'
          $owner.popover('hide')
          popover.$tip.detach() # HACK: Bootstrap is not properly detaching the popover dom element

    @removePopover: ($el) ->
      @popovers = _.reject @popovers, ($popover) ->
        return _.isEqual($el, $popover)

    close: () ->
      @constructor.removePopover(@$owner)
      @$owner.popover('destroy')
      super()
{'fraction_non_alphanumeric': 0.1466606498194946, 'fraction_numerical': 0.0018050541516245488, 'mean_word_length': 2.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '359679', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1352, 'n_words': 351}