<commit_before>@initialized = false

initialize = (method) ->
  if @initialized == true && !@method == "jquery"
    console.log "already initialized"
    return false

  @initialized = true
  @method = method
  console.log "proceeding with initialization via #{method}"
  delay = (ms, func) -> setTimeout func, ms

  submit_form = ->
    console.log "submitted that damned form"
    $('.search-bar form').submit()

  localize_datetimes = ->
    dates = $(".articles time")
    for date in dates
      old_time = $(date).attr('datetime')
      new_time = moment(old_time).format('MMM Do YYYY')
      $(date).html(new_time)

  timeout = null

  $('#search').on 'keyup', ->
    clearTimeout(timeout) if timeout
    timeout = delay 400, -> submit_form()

  $('html').on 'keydown','#article_content', (evt)->
    if evt.keyCode == 9
      $('textarea#article_content').insertAtCaret('  ')
      evt.preventDefault()

  $('#article_tag_tokens').tokenInput '/tags.json',
    theme: "facebook"
    prePopulate: $('#article_tag_tokens').data('load')

  localize_datetimes()

  date_inputs = $("#article_created_at, #article_updated_at")
  date_inputs?.datepicker({ dateFormat: 'M dd yy' })
  for date in date_inputs
    old_time = $(date).val()
    new_time = moment(old_time).format('MMM Do YYYY')
    $(date).val(new_time)


initialize_via_turbolinks = ->
  console.log "attempting to initialize via turbolinks"
  $(window).on "page:change", ->
    initialize("turbolinks")

initialize_via_jquery = ->
  console.log "attempting to initialize via jQuery"
  $ ->
    initialize("jquery")

initialize_via_turbolinks()
initialize_via_jquery()<commit_msg>Default datepickers to set date.<commit_after>@initialized = false

initialize = (method) ->
  if @initialized == true && !@method == "jquery"
    console.log "already initialized"
    return false

  @initialized = true
  @method = method
  console.log "proceeding with initialization via #{method}"
  delay = (ms, func) -> setTimeout func, ms

  submit_form = ->
    console.log "submitted that damned form"
    $('.search-bar form').submit()

  localize_datetimes = ->
    dates = $(".articles time")
    for date in dates
      old_time = $(date).attr('datetime')
      new_time = moment(old_time).format('MMM Do YYYY')
      $(date).html(new_time)

  timeout = null

  $('#search').on 'keyup', ->
    clearTimeout(timeout) if timeout
    timeout = delay 400, -> submit_form()

  $('html').on 'keydown','#article_content', (evt)->
    if evt.keyCode == 9
      $('textarea#article_content').insertAtCaret('  ')
      evt.preventDefault()

  $('#article_tag_tokens').tokenInput '/tags.json',
    theme: "facebook"
    prePopulate: $('#article_tag_tokens').data('load')

  localize_datetimes()

  date_inputs = $("#article_created_at, #article_updated_at")
  for date in date_inputs
    date = $(date)
    default_date = $.datepicker.parseDate("yy-mm-dd", date.val())
    date.datepicker({ defaultDate: default_date, dateFormat: 'M dd yy' })
    old_time = date.val()
    new_time = moment(old_time).format('MMM Do YYYY')
    date.val(new_time)


initialize_via_turbolinks = ->
  console.log "attempting to initialize via turbolinks"
  $(window).on "page:change", ->
    initialize("turbolinks")

initialize_via_jquery = ->
  console.log "attempting to initialize via jQuery"
  $ ->
    initialize("jquery")

initialize_via_turbolinks()
initialize_via_jquery()
{'fraction_non_alphanumeric': 0.15095447870778267, 'fraction_numerical': 0.0023494860499265785, 'mean_word_length': 3.8657142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2966194', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1078, 'n_words': 246}