<commit_before>dDraggableList = ($q) ->

  class DraggableList

    constructor: () ->
      @items = []
      @callbacks =
        change: []

    clear: () ->
      while @items.length
        @items.pop()

    on: (evt, fn) ->
      can_add = (angular.isFunction fn) and (angular.isArray @callbacks[evt])
      @callbacks[evt].push fn if can_add
      true

    addReference: (drag_item) ->
      @items.push drag_item

    finish: (moved_element, final_position) ->
      deferred = $q.defer()
      swap_index = -1
      moved_index = -1

      for item, index in @items
        if item == moved_element
          moved_index = index
          continue

        bounding = item[0].getBoundingClientRect()
        is_below = final_position.top > bounding.top
        is_above = final_position.top < bounding.bottom

        if is_above and is_below
          swap_index = index

      fn moved_index, swap_index for fn in @callbacks['change']

      deferred.resolve true

      deferred.promise

  lfDraggableList =<commit_msg>[LFTUI-77] allowing users to drag above the first list item and below the last in order to trigger swap index<commit_after>dDraggableList = ($q) ->

  class DraggableList

    constructor: () ->
      @items = []
      @callbacks =
        change: []

    clear: () ->
      while @items.length
        @items.pop()

    on: (evt, fn) ->
      can_add = (angular.isFunction fn) and (angular.isArray @callbacks[evt])
      @callbacks[evt].push fn if can_add
      true

    addReference: (drag_item) ->
      @items.push drag_item

    finish: (moved_element, final_position) ->
      deferred = $q.defer()
      swap_index = -1
      moved_index = -1

      for item, index in @items
        if item == moved_element
          moved_index = index
          continue

        bounding = item[0].getBoundingClientRect()
        is_below = final_position.top > bounding.top
        is_above = final_position.top < bounding.bottom

        if is_above and is_below
          swap_index = index

        if index == 0 and is_above
          swap_index = 0

        if index == (@items.length - 1) and is_below
          swap_index = index

      fn moved_index, swap_index for fn in @callbacks['change']

      deferred.resolve true

      deferred.promise

  lfDraggableList =
{'fraction_non_alphanumeric': 0.09722222222222222, 'fraction_numerical': 0.004774305555555556, 'mean_word_length': 2.1190798376184032, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3303025', 'n_tokens_mistral': 734, 'n_tokens_neox': 696, 'n_words': 184}