<commit_before>_ = require 'underscore'
sd = require('sharify').data
Backbone = require 'backbone'
Backbone.$ = $
mediator = require '../../../lib/mediator.coffee'
PathView = require '../../path/client/path_view.coffee'
LightboxRouter = require '../../lightbox/lightbox_router.coffee'

module.exports = class BodyView extends Backbone.View

  events:
    'click'                                       : 'bodyClick'
    'click a[data-disabled]'                      : 'disable'
    'click a[data-client]:not([data-disabled])'   : 'intercept'
    'click span[data-client]:not([data-disabled])': 'intercept'

  initialize: (options) ->
    current_path = sd.CURRENT_PATH?.replace sd.CLIENT_PATH, ""

    new LightboxRouter
    Backbone.history.start pushState: false, root: current_path

    if sd.CLIENT_PATH
      Backbone.history.navigate sd.CLIENT_PATH, trigger: true, replace: false

    mediator.on 'load:start', @startLoading, @
    mediator.on 'load:stop', @stopLoading, @

    new PathView el: @$('section.path--header')

  startLoading: -> $('body').addClass 'is-loading'

  stopLoading: -> $('body').removeClass 'is-loading'

  intercept: (e)->
    e.preventDefault()

    if $(e.currentTarget).data('client') is 'Block'
      Backbone.history.navigate "#{$(e.currentTarget).attr('href')}", trigger: true, replace: false
    else
      window.location = $(e.currentTarget).attr('href')

  disable: (e)->
    e.preventDefault()
    e.stopPropagation()

  bodyClick: (e) -> mediator.trigger 'body:click', e<commit_msg>tap scroll-top scrolls body to top<commit_after>_ = require 'underscore'
sd = require('sharify').data
Backbone = require 'backbone'
Backbone.$ = $
mediator = require '../../../lib/mediator.coffee'
PathView = require '../../path/client/path_view.coffee'
LightboxRouter = require '../../lightbox/lightbox_router.coffee'

module.exports = class BodyView extends Backbone.View

  events:
    'click'                                       : 'bodyClick'
    'click a[data-disabled]'                      : 'disable'
    'click a[data-client]:not([data-disabled])'   : 'intercept'
    'click span[data-client]:not([data-disabled])': 'intercept'
    'tap #scroll-top'                             : 'scrollToTop'


  initialize: (options) ->
    current_path = sd.CURRENT_PATH?.replace sd.CLIENT_PATH, ""

    new LightboxRouter
    Backbone.history.start pushState: false, root: current_path

    if sd.CLIENT_PATH
      Backbone.history.navigate sd.CLIENT_PATH, trigger: true, replace: false

    mediator.on 'load:start', @startLoading, @
    mediator.on 'load:stop', @stopLoading, @

    new PathView el: @$('section.path--header')

  startLoading: -> $('body').addClass 'is-loading'

  stopLoading: -> $('body').removeClass 'is-loading'

  intercept: (e)->
    e.preventDefault()

    if $(e.currentTarget).data('client') is 'Block'
      Backbone.history.navigate "#{$(e.currentTarget).attr('href')}", trigger: true, replace: false
    else
      window.location = $(e.currentTarget).attr('href')

  disable: (e)->
    e.preventDefault()
    e.stopPropagation()

  bodyClick: (e) -> mediator.trigger 'body:click', e

  scrollToTop: (e) ->
    e.preventDefault()
    e.stopPropagation()

    $("html, body").animate { scrollTop: 0 }, 300
{'fraction_non_alphanumeric': 0.16149831132944428, 'fraction_numerical': 0.0012281240405280934, 'mean_word_length': 3.0878293601003763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4021103', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1003, 'n_words': 208}