<commit_before>window.clonePagination = ->
  $('.pagination:first').clone().appendTo($('.batch_actions'))

window.initPopover = ->
  $('.popover').hide()
  $('a[rel=popover]').popover({trigger: 'hover', html: true})

window.initAcFileds = ->
  for el in $('.ac_field')
    $el = $(el)
    params = $.extend({class: $el.data('class')}, $el.data('params') || {})
    $(el).oautocomplete
      serviceUrl: '/admin/autocomplete'
      params: params
      minChars: 2
      maxHeight: 400
      width: 220

window.initTooltip = ->
  $('.do_tooltip').tooltip
    animation: false
    placement: 'right'

window.initEditor = ->
  return if gon.test
  $('form .do_wysihtml5').each ->
    $el = $(this)
    return if $el.hasClass('wysihtml5_done')
    editor = $el.wysihtml5({html: true, locale: 'ru'}).data('wysihtml5').editor
    resizeIframe = -> editor.composer.iframe.style.height = editor.composer.element.scrollHeight + "px"
    editor.on "load", ->
      if editor.composer
        editor.composer.element.addEventListener "keyup", resizeIframe, false
        editor.composer.element.addEventListener "blur", resizeIframe, false
        editor.composer.element.addEventListener "focus", resizeIframe, false
    $el.addClass('wysihtml5_done')

window.inputSetToggle = ->
  $('.label.do_toggle').click ->
    $(this).siblings().toggle()

window.flash = (message, type='notice') ->
  $("<div class='alert alert-#{type}'><a class='close' data-dismiss='alert'>×</a>#{message}</div>").insertBefore $('#container')

window.focusInput = (scope=null) ->
  scope ||= $('form.simple_form:first')
  $('input[type="text"],input[type="string"],select:visible,textarea:visible', scope).not('.fancy_select,.datepicker').get(0)?.focus()

window.templateStorage = {}
window.fetchTemplate = (tmpl_id) ->
  window.templateStorage[tmpl_id] ||= Handlebars.compile($(tmpl_id).html())

window.initFancySelect = ->
  return if gon.test
  defaults =
    formatNoMatches: ->
      I18n.t('admin_js.no_results')
    placeholder: ' '
    allowClear: true
    minimumResultsForSearch: 10

  $('form .fancy_select, form input.token, .without_form.fancy_select').each ->
    $el = $(this)
    return if $el.data('select2')
    options = _.defaults({}, defaults)
    options.multiple = $el.data('multi') unless _.isUndefined($el.data('multi'))
    options.width = $el[0].style.width || 'resolve'
    if $el.data('tags')
      options.tokenSeparators = [","]
      options.tags = $el.data('tags')
    else if $el.data('class')
      if $el.data('image')
        options.formatResult = (item) ->
          html = '<div class="fancy_select-result">'
          html += "<img src='#{item.image}' alt='#{item.text}'>" if item.image
          html += "<span>#{item.text}</span></div>"
        options.formatSelection = (item) ->
          html = '<div class="fancy_select-selection">'
          html += "<img src='#{item.image}' alt='#{item.text}'>" if item.image
          html += "<span>#{item.text}</span></div>"
      if $el.data('result')
        options.formatResult = (item) -> fetchTemplate($el.data('result'))(item)
      if $el.data('selection')
        options.formatSelection = (item) -> fetchTemplate($el.data('selection'))(item)

      if $el.data('image') || $el.data('result') || $el.data('selection')
        options.escapeMarkup = (m) -> m

      options.initSelection = (el, callback) ->
        data = $el.data('pre')
        if $el.data('multi')<commit_msg>remove required from select2 input<commit_after>window.clonePagination = ->
  $('.pagination:first').clone().appendTo($('.batch_actions'))

window.initPopover = ->
  $('.popover').hide()
  $('a[rel=popover]').popover({trigger: 'hover', html: true})

window.initAcFileds = ->
  for el in $('.ac_field')
    $el = $(el)
    params = $.extend({class: $el.data('class')}, $el.data('params') || {})
    $(el).oautocomplete
      serviceUrl: '/admin/autocomplete'
      params: params
      minChars: 2
      maxHeight: 400
      width: 220

window.initTooltip = ->
  $('.do_tooltip').tooltip
    animation: false
    placement: 'right'

window.initEditor = ->
  return if gon.test
  $('form .do_wysihtml5').each ->
    $el = $(this)
    return if $el.hasClass('wysihtml5_done')
    editor = $el.wysihtml5({html: true, locale: 'ru'}).data('wysihtml5').editor
    resizeIframe = -> editor.composer.iframe.style.height = editor.composer.element.scrollHeight + "px"
    editor.on "load", ->
      if editor.composer
        editor.composer.element.addEventListener "keyup", resizeIframe, false
        editor.composer.element.addEventListener "blur", resizeIframe, false
        editor.composer.element.addEventListener "focus", resizeIframe, false
    $el.addClass('wysihtml5_done')

window.inputSetToggle = ->
  $('.label.do_toggle').click ->
    $(this).siblings().toggle()

window.flash = (message, type='notice') ->
  $("<div class='alert alert-#{type}'><a class='close' data-dismiss='alert'>×</a>#{message}</div>").insertBefore $('#container')

window.focusInput = (scope=null) ->
  scope ||= $('form.simple_form:first')
  $('input[type="text"],input[type="string"],select:visible,textarea:visible', scope).not('.fancy_select,.datepicker').get(0)?.focus()

window.templateStorage = {}
window.fetchTemplate = (tmpl_id) ->
  window.templateStorage[tmpl_id] ||= Handlebars.compile($(tmpl_id).html())

window.initFancySelect = ->
  return if gon.test
  defaults =
    formatNoMatches: ->
      I18n.t('admin_js.no_results')
    placeholder: ' '
    allowClear: true
    minimumResultsForSearch: 10

  $('form .fancy_select, form input.token, .without_form.fancy_select').each ->
    $el = $(this)
    return if $el.data('select2')
    $el.prop('required', null)
    options = _.defaults({}, defaults)
    options.multiple = $el.data('multi') unless _.isUndefined($el.data('multi'))
    options.width = $el[0].style.width || 'resolve'
    if $el.data('tags')
      options.tokenSeparators = [","]
      options.tags = $el.data('tags')
    else if $el.data('class')
      if $el.data('image')
        options.formatResult = (item) ->
          html = '<div class="fancy_select-result">'
          html += "<img src='#{item.image}' alt='#{item.text}'>" if item.image
          html += "<span>#{item.text}</span></div>"
        options.formatSelection = (item) ->
          html = '<div class="fancy_select-selection">'
          html += "<img src='#{item.image}' alt='#{item.text}'>" if item.image
          html += "<span>#{item.text}</span></div>"
      if $el.data('result')
        options.formatResult = (item) -> fetchTemplate($el.data('result'))(item)
      if $el.data('selection')
        options.formatSelection = (item) -> fetchTemplate($el.data('selection'))(item)

      if $el.data('image') || $el.data('result') || $el.data('selection')
        options.escapeMarkup = (m) -> m

      options.initSelection = (el, callback) ->
        data = $el.data('pre')
        if $el.data('multi')
{'fraction_non_alphanumeric': 0.19616050808314087, 'fraction_numerical': 0.005629330254041571, 'mean_word_length': 3.5110677083333335, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 75, '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': '7245730', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2250, 'n_words': 381}