<commit_before>#= require jquery.wysiwyg
#= require file-input-drop-zone

$ ->
  # Insert handler for nested_form's add-nested-fields
  window.nestedFormEvents.insertFields = (content, assoc, link) ->
    $ul = $(link).closest('div').prevAll('ul')
    $(content).appendTo($ul)

  # Drag'n'drop and preview update for the poster
  $('.poster').fileInputDropZone()
  # Hide preview if remove poster is checked
  $('.poster :checkbox').change ->
    $('.poster img').toggle()
  # Unchecks remove and shows preview if image is changed
  $('.poster :file').change ->
    $('.poster :checkbox').prop('checked', false)
    $('.poster img').show()

  # Stamps preview
  stamps = <%= Hash[ Stamp.all.map { |s| [ s.id, s ] } ].to_json %>
  updateStamp = ->
    $s = $(@)
    $img = $s.closest('.remark').find('.picto img')
    stamp = stamps[ $s.val() ]
    $img.prop('src', '<%= Rails.application.config.assets.prefix %>/'+stamp.name + '.png')
    $img.prop('alt', stamp.title)
    $img.data('longdesc', stamp.description)
  $('.remark select').each   updateStamp
  $('.remark select').change updateStamp

  # Summary RTE init
  $('.summary textarea').each ->
    $t = $(@)
    defaultValue = '<p>'+$t.prop('placeholder')+'</p>'
    $t.wysiwyg
      rmUnusedControls: true
      brIE: false
      rmUnwantedBr: true
      initialContent: defaultValue<commit_msg>Fixed stamps preview for JS-added stamps<commit_after>#= require jquery.wysiwyg
#= require file-input-drop-zone

$ ->
  # Insert handler for nested_form's add-nested-fields
  window.nestedFormEvents.insertFields = (content, assoc, link) ->
    $ul = $(link).closest('div').prevAll('ul')
    $(content).appendTo($ul)

  # Drag'n'drop and preview update for the poster
  $('.poster').fileInputDropZone()
  # Hide preview if remove poster is checked
  $('.poster :checkbox').change ->
    $('.poster img').toggle()
  # Unchecks remove and shows preview if image is changed
  $('.poster :file').change ->
    $('.poster :checkbox').prop('checked', false)
    $('.poster img').show()

  # Stamps preview
  stamps = <%= Hash[ Stamp.all.map { |s| [ s.id, s ] } ].to_json %>
  updateStamp = ->
    $s = $(@)
    $img = $s.closest('.remark').find('.picto img')
    stamp = stamps[ $s.val() ]
    $img.prop('src', '<%= Rails.application.config.assets.prefix %>/'+stamp.name + '.png')
    $img.prop('alt', stamp.title)
    $img.data('longdesc', stamp.description)
  makeStampsPreviewable = ->
    $('.remark select').each ->
      $select = $(this)
      unless $select.data('previewable')
        updateStamp.call this
        $select.change updateStamp
      # jQuery doesn't provide reliable way to check if an eventListener has been added, so we shall tag it by ourselves
      $select.data('previewable', true)
  makeStampsPreviewable()
  $(document).on 'nested:fieldAdded', makeStampsPreviewable

  # Summary RTE init
  $('.summary textarea').each ->
    $t = $(this)
    defaultValue = '<p>'+$t.prop('placeholder')+'</p>'
    $t.wysiwyg
      rmUnusedControls: true
      brIE: false
      rmUnwantedBr: true
      initialContent: defaultValue
{'fraction_non_alphanumeric': 0.17852522639068563, 'fraction_numerical': 0.0, 'mean_word_length': 3.3686440677966103, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6534595', 'n_tokens_mistral': 1031, 'n_tokens_neox': 1003, 'n_words': 236}