<commit_before>###
jQuery Gridly
Copyright 2013 <NAME>
###

"use strict"

$ = jQuery

class Animation
  @transitions:
    "webkitTransition": "webkitTransitionEnd"
    "mozTransition": "mozTransitionEnd"
    "msTransition": "msTransitionEnd"
    "oTransition": "oTransitionEnd"
    "transition": "transitionend"

  @transition: ($el) ->
    el = $el[0]
    return result for type, result of @transitions when el.style[type]?

  @execute: ($el, callback) ->
    transition = @transition($el)
    if transition? then $el.one(transition, callback) else callback()

class Gridly

  @settings:
    base: 60
    gutter: 20
    columns: 12
    draggable: true

  @gridly: ($el, options = {}) ->
    @existing ?= {}
    @existing[$el[0]] ?= new Gridly($el, options)
    return @existing[$el[0]]

  constructor: ($el, settings = {}) ->
    @$el = $el
    @settings = $.extend {}, Gridly.settings, settings
    @ordinalize(@$('> *'))
    @draggable() if @settings.draggable

  ordinalize: ($elements) =>
    for i in [0 .. $elements.length]
      $element = $($elements[i])
      $element.data('position', i)

  $: (selector) =>
    @$el.find(selector)

  compare: (d, s) =>
    return +1 if d.y > s.y + s.h
    return -1 if s.y > d.y + d.h
    return +1 if (d.x + (d.w / 2)) > (s.x + (s.w / 2))
    return -1 if (s.x + (s.w / 2)) > (d.x + (d.w / 2))
    return 0

  draggable: =>
    @$('> *').draggable
      zIndex: 800
      drag: @drag
      start: @start
      stop: @stop

  start: (event, ui) =>
    $dragging = $(event.target)
    @ordinalize(@$sorted())
    setTimeout @layout, 0

  stop: (event, ui) =>
    $dragging = $(event.target)
    @ordinalize(@$sorted())
    setTimeout @layout, 0
    @settings?.callbacks?.reordered(@)

  $sorted: ($elements) =>
    ($elements || @$('> *')).sort (a,b) ->
      aVal = parseInt($(a).data('position'))
      bVal = parseInt($(b).data('position'))
      return -1 if aVal < bVal
      return +1 if aVal > bVal
      return 0

  drag: (event, ui) =>
    delta = 0.5
    $dragging = $(event.target)
    $elements = @$sorted()
    positions = @structure($elements).positions
    index = $dragging.data('position')
    original = index

    coordinate = 
      x: $dragging.position().left
      y: $dragging.position().top
      w: $dragging.data('width')  || $dragging.width()
      h: $dragging.data('height') || $dragging.height()
    
    for i in [0 ... $elements.length]
      $element = $($elements[i])
      continue if $element.is($dragging)

      position = positions[i]
      if @compare(coordinate, position) < 0
        index = i
        break

    unless index is original
      $dragging.data('position', index + delta)
      @layout(@$sorted())

  position: ($element, columns) =><commit_msg>fixing some sortability<commit_after>###
jQuery Gridly
Copyright 2013 <NAME>
###

"use strict"

$ = jQuery

class Animation
  @transitions:
    "webkitTransition": "webkitTransitionEnd"
    "mozTransition": "mozTransitionEnd"
    "msTransition": "msTransitionEnd"
    "oTransition": "oTransitionEnd"
    "transition": "transitionend"

  @transition: ($el) ->
    el = $el[0]
    return result for type, result of @transitions when el.style[type]?

  @execute: ($el, callback) ->
    transition = @transition($el)
    if transition? then $el.one(transition, callback) else callback()

class Gridly

  @settings:
    base: 60
    gutter: 20
    columns: 12
    draggable: true

  @gridly: ($el, options = {}) ->
    @existing ?= {}
    @existing[$el[0]] ?= new Gridly($el, options)
    return @existing[$el[0]]

  constructor: ($el, settings = {}) ->
    @$el = $el
    @settings = $.extend {}, Gridly.settings, settings
    @ordinalize(@$('> *'))

  ordinalize: ($elements) =>
    for i in [0 .. $elements.length]
      $element = $($elements[i])
      $element.data('position', i)

  $: (selector) =>
    @$el.find(selector)

  compare: (d, s) =>
    return +1 if d.y > s.y + s.h
    return -1 if s.y > d.y + d.h
    return +1 if (d.x + (d.w / 2)) > (s.x + (s.w / 2))
    return -1 if (s.x + (s.w / 2)) > (d.x + (d.w / 2))
    return 0

  draggable: =>
    @$('> *').draggable
      zIndex: 800
      drag: @drag
      start: @start
      stop: @stop

  stationary: =>
    @$('> *').draggable('destroy')

  start: (event, ui) =>
    $dragging = $(event.target)
    @ordinalize(@$sorted())
    setTimeout @layout, 0

  stop: (event, ui) =>
    $dragging = $(event.target)
    @ordinalize(@$sorted())
    setTimeout @layout, 0
    @settings?.callbacks?.reordered(@)

  $sorted: ($elements) =>
    ($elements || @$('> *')).sort (a,b) ->
      $a = $(a)
      $b = $(b)
      aPosition = $a.data('position')
      bPosition = $b.data('position')
      aPositionInt = parseInt(aPosition)
      bPositionInt = parseInt(bPosition)
      return -1 if aPosition? and not bPosition?
      return +1 if bPosition? and not aPosition?
      return -1 if not aPosition and not bPosition and $a.index() < $b.index()
      return +1 if not bPosition and not aPosition and $b.index() < $a.index()
      return -1 if aPositionInt < bPositionInt
      return +1 if bPositionInt < aPositionInt
      return 0

  drag: (event, ui) =>
    delta = 0.5
    $dragging = $(event.target)
    $elements = @$sorted()
    positions = @structure($elements).positions
    index = $dragging.data('position')
    original = index

    coordinate = 
      x: $dragging.position().left
      y: $dragging.position().top
      w: $dragging.data('width')  || $dragging.width()
      h: $dragging.data('height') || $dragging.height()
    
    for i in [0 ... $elements.length]
      $element = $($elements[i])
      continue if $element.is($dragging)

      position = positions[i]
      if @compare(coordinate, position) < 0
        index = i
        break

    unless index is original
      $dragging.data('position', index + delta)
      @layout(@$sorted())

  position: ($element, columns) =>
{'fraction_non_alphanumeric': 0.17561388653683319, 'fraction_numerical': 0.012531752751905165, 'mean_word_length': 2.6797507788161994, 'pattern_counts': {'":': 10, '<': 12, '<?xml version=': 0, '>': 50, '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': '3288488', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2006, 'n_words': 515}