<commit_before>#= require ./module

class TaoApplication extends TaoModule

  _init: ->
    @_initGon()
    @_initI18n()
    @_initUjs()
    @_initTurbolinks()

  _initGon: ->
    return unless window.gon
    $.extend @, window.gon
    window.gon = null

  _initUjs: ->
    $(document).on "ajax:before", 'a[data-remote]', ->
      $link = $ @
      return false if $link.hasClass('disabled')
      $link.addClass 'disabled'
    .on "ajax:complete", 'a[data-remote]', ->
      $(@).removeClass 'disabled'

  _initI18n: ->
    I18n.locale = @locale if I18n && @locale

  _initIcons: ($page) ->
    $icons = $page.siblings('#tao-icons')
    unless $icons.length > 0
      $page[0].insertAdjacentHTML('beforebegin', Tao.iconsHtml || '')

  _initPage: ($page) ->
    window.currentPage = @currentPage = $page[0]

  _initTurbolinks: ->
    $(document).on 'turbolinks:before-visit', (e) =>
      if @currentPage?.trigger('before-leave') == false
        e.preventDefault()
        return

      @trigger 'before-page-visit', [e.originalEvent?.data.url]

    .on 'turbolinks:request-start', (e) =>
      @trigger 'page-request-start', [e.originalEvent?.data.xhr]

    .on 'turbolinks:visit', (e) =>
      @trigger 'page-visit', [e.originalEvent?.data.url]

    .on 'turbolinks:before-cache', (e) =>
      @trigger 'before-page-cache', [@currentPage]
      @currentPage?.prepareCache?()<commit_msg>FIX: I18n Uncaught ReferenceError Error<commit_after>#= require ./module

class TaoApplication extends TaoModule

  _init: ->
    @_initGon()
    @_initI18n()
    @_initUjs()
    @_initTurbolinks()

  _initGon: ->
    return unless window.gon
    $.extend @, window.gon
    window.gon = null

  _initUjs: ->
    $(document).on "ajax:before", 'a[data-remote]', ->
      $link = $ @
      return false if $link.hasClass('disabled')
      $link.addClass 'disabled'
    .on "ajax:complete", 'a[data-remote]', ->
      $(@).removeClass 'disabled'

  _initI18n: ->
    I18n.locale = @locale if window.I18n && @locale

  _initIcons: ($page) ->
    $icons = $page.siblings('#tao-icons')
    unless $icons.length > 0
      $page[0].insertAdjacentHTML('beforebegin', Tao.iconsHtml || '')

  _initPage: ($page) ->
    window.currentPage = @currentPage = $page[0]

  _initTurbolinks: ->
    $(document).on 'turbolinks:before-visit', (e) =>
      if @currentPage?.trigger('before-leave') == false
        e.preventDefault()
        return

      @trigger 'before-page-visit', [e.originalEvent?.data.url]

    .on 'turbolinks:request-start', (e) =>
      @trigger 'page-request-start', [e.originalEvent?.data.xhr]

    .on 'turbolinks:visit', (e) =>
      @trigger 'page-visit', [e.originalEvent?.data.url]

    .on 'turbolinks:before-cache', (e) =>
      @trigger 'before-page-cache', [@currentPage]
      @currentPage?.prepareCache?()
{'fraction_non_alphanumeric': 0.17787264318747775, 'fraction_numerical': 0.008537886872998933, 'mean_word_length': 3.0402298850574714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '5704951', 'n_tokens_mistral': 1012, 'n_tokens_neox': 978, 'n_words': 177}