<commit_before>#= depend_on_asset kuhsaft/cms/ck-config
#
#= require jquery
#= require jquery_ujs
#= require jquery.remotipart
#= require jquery-ui
#= require bootstrap
#= require bootstrap-modal-v2
#= require bootstrap-modalmanager
#= require ckeditor-jquery
#= require jquery.nestable
#= require_tree .
#
# Disable timestamp for ckeditor internal asset loading. This prevents issues with Asset Pipeline on production.
root = exports ? this
root.CKEDITOR.timestamp = null

# As @ryabrody & @k-graefenhain found out there is obviously a bug which causes the asset_path_helper to return paths always without digest:
# https://github.com/rails/sprockets-rails/issues/66
# That's why we need the environment switch here:
CKEDITOR.config.customConfig = "<%= asset_path('kuhsaft/cms/ck-config.js') %>"

loadTextEditor = ->
  CKEDITOR.replaceAll('ckeditor')

updateInputsForRedirectPage = (redirect_url, keywords, description) ->
  redirect_url.removeAttr('disabled')
  keywords.attr('disabled', 'disabled')
  description.attr('disabled', 'disabled')

clearInputsFromRedirectPage = (redirect_url, keywords, description) ->
  redirect_url.attr('disabled', 'disabled')
  keywords.removeAttr('disabled')
  description.removeAttr('disabled')

checkPageType = ->
  redirect_url = $('#page_redirect_url')
  keywords = $('#page_keywords')
  description = $('#page_description')
  if ($('#page_page_type option:selected').val() == 'redirect')
    updateInputsForRedirectPage(redirect_url, keywords, description)
  else
    clearInputsFromRedirectPage(redirect_url, keywords, description)

sortableBrick = ->
  $(".brick-list").each (idx, elem) ->
    $(elem).sortable(
      handle: '.brick-item-header',
      axis: "y",
      update: (event, ui) ->
        idList = $(this).find("> .brick-item")
          .each (idx, elem) ->
            $(this).find("input.position-field").val(idx+1)
          .map ->
            $(this).data('id')

        sortForm = $('#bricks-sort-form form')
        sortForm.find('input[name="bricks[ids]"]').val(idList.toArray().join(','))
        sortForm.trigger('submit')
      )

window.initSubmitLinks = (selector = null)->
  selector ||= $('body')

  selector.find('a.submit')
    .click (e)->
      $('textarea.ckeditor').each (index, elem) ->
        CKEDITOR.instances[elem.id].updateElement()

      form = $(this).closest('form')
      form.submit()
      e.preventDefault()

window.initSavePopover = (selector) ->
  link = selector.find('a.submit')
  link.popover(placement: 'top', trigger: 'manual')

  # initial delay
  setTimeout ->
    link.popover('show')
    # fade out delay
    setTimeout ->
      link.popover('hide')
    , 1500
  , 50

window.initCKEditor = (selector) ->
  CKEDITOR.replace(selector)

window.toggleCollapseBricksNav = (bool = false) ->
  if bool
    $('#collapse-bricks-nav').removeClass('hidden')
  else
    $('#collapse-bricks-nav').addClass('hidden')

# Stop propagation for display styles dropdown
window.stopPropagationOfDisplayStyles = (selector) ->
  selector.click (e) ->
    e.stopPropagation()

$(document).ajaxSuccess ->
  sortableBrick()

$(document).ready ->
  loadTextEditor()
  checkPageType()
  sortableBrick()
  initSubmitLinks()
  stopPropagationOfDisplayStyles($('#display-styles ul'))

  $('#page_page_type').change ->
    checkPageType()

  $('.dd').nestable(
    collapseBtnHTML: '<button data-action="collapse"><i class="icon-minus-sign"></i></button>'
    expandBtnHTML: '<button data-action="expand"><i class="icon-plus-sign"></i></button>'
  )

  $('.dd').on('change', ->
    pageTree = $('.dd').nestable('serialize')
    url = '/cms/pages/sort'
    $.post(url, { page_tree: pageTree }, "json")
  )

  # collapse / expand all
  $('#expand-all').click ->
    $('.brick-item-content').each (index, elem) ->
      $(elem).collapse('show')
    $('.resize-toggler').each (index, elem) ->
      $(elem).removeClass('collapsed')

  $('#collapse-all').click ->
    $('.brick-item-content').each (index, elem) ->
      $(elem).collapse('hide')
    $('.resize-toggler').each (index, elem) ->
      $(elem).addClass('collapsed')
<commit_msg>custom page can have keyword/description<commit_after>#= depend_on_asset kuhsaft/cms/ck-config
#
#= require jquery
#= require jquery_ujs
#= require jquery.remotipart
#= require jquery-ui
#= require bootstrap
#= require bootstrap-modal-v2
#= require bootstrap-modalmanager
#= require ckeditor-jquery
#= require jquery.nestable
#= require_tree .
#
# Disable timestamp for ckeditor internal asset loading. This prevents issues with Asset Pipeline on production.
root = exports ? this
root.CKEDITOR.timestamp = null

# As @ryabrody & @k-graefenhain found out there is obviously a bug which causes the asset_path_helper to return paths always without digest:
# https://github.com/rails/sprockets-rails/issues/66
# That's why we need the environment switch here:
CKEDITOR.config.customConfig = "<%= asset_path('kuhsaft/cms/ck-config.js') %>"

loadTextEditor = ->
  CKEDITOR.replaceAll('ckeditor')

pageType = ->
  $('#page_page_type option:selected').val()

checkPageType = ->
  redirect_url = $('#page_redirect_url')
  keywords = $('#page_keywords')
  description = $('#page_description')
  if (pageType() == 'redirect')
    redirect_url.removeAttr('disabled')
    keywords.attr('disabled', 'disabled')
    description.attr('disabled', 'disabled')
  else if (pageType() == 'custom')
    redirect_url.removeAttr('disabled')
    keywords.removeAttr('disabled')
    description.removeAttr('disabled')
  else
    redirect_url.attr('disabled', 'disabled')
    keywords.removeAttr('disabled')
    description.removeAttr('disabled')


sortableBrick = ->
  $(".brick-list").each (idx, elem) ->
    $(elem).sortable(
      handle: '.brick-item-header',
      axis: "y",
      update: (event, ui) ->
        idList = $(this).find("> .brick-item")
          .each (idx, elem) ->
            $(this).find("input.position-field").val(idx+1)
          .map ->
            $(this).data('id')

        sortForm = $('#bricks-sort-form form')
        sortForm.find('input[name="bricks[ids]"]').val(idList.toArray().join(','))
        sortForm.trigger('submit')
      )

window.initSubmitLinks = (selector = null)->
  selector ||= $('body')

  selector.find('a.submit')
    .click (e)->
      $('textarea.ckeditor').each (index, elem) ->
        CKEDITOR.instances[elem.id].updateElement()

      form = $(this).closest('form')
      form.submit()
      e.preventDefault()

window.initSavePopover = (selector) ->
  link = selector.find('a.submit')
  link.popover(placement: 'top', trigger: 'manual')

  # initial delay
  setTimeout ->
    link.popover('show')
    # fade out delay
    setTimeout ->
      link.popover('hide')
    , 1500
  , 50

window.initCKEditor = (selector) ->
  CKEDITOR.replace(selector)

window.toggleCollapseBricksNav = (bool = false) ->
  if bool
    $('#collapse-bricks-nav').removeClass('hidden')
  else
    $('#collapse-bricks-nav').addClass('hidden')

# Stop propagation for display styles dropdown
window.stopPropagationOfDisplayStyles = (selector) ->
  selector.click (e) ->
    e.stopPropagation()

$(document).ajaxSuccess ->
  sortableBrick()

$(document).ready ->
  loadTextEditor()
  checkPageType()
  sortableBrick()
  initSubmitLinks()
  stopPropagationOfDisplayStyles($('#display-styles ul'))

  $('#page_page_type').change ->
    checkPageType()

  $('.dd').nestable(
    collapseBtnHTML: '<button data-action="collapse"><i class="icon-minus-sign"></i></button>'
    expandBtnHTML: '<button data-action="expand"><i class="icon-plus-sign"></i></button>'
  )

  $('.dd').on('change', ->
    pageTree = $('.dd').nestable('serialize')
    url = '/cms/pages/sort'
    $.post(url, { page_tree: pageTree }, "json")
  )

  # collapse / expand all
  $('#expand-all').click ->
    $('.brick-item-content').each (index, elem) ->
      $(elem).collapse('show')
    $('.resize-toggler').each (index, elem) ->
      $(elem).removeClass('collapsed')

  $('#collapse-all').click ->
    $('.brick-item-content').each (index, elem) ->
      $(elem).collapse('hide')
    $('.resize-toggler').each (index, elem) ->
      $(elem).addClass('collapsed')

{'fraction_non_alphanumeric': 0.17643452672878862, 'fraction_numerical': 0.0024521824423737125, 'mean_word_length': 3.7869718309859155, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 80, 'https://': 2, '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': '7485624', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2555, 'n_words': 485}