<commit_before>Backbone    = require 'backbone'
Backbone.$  = $
HeaderView  = require './header/view.coffee'
FooterView  = require './footer/view.coffee'
sd          = require('sharify').data
analytics   = require '../../lib/analytics.coffee'

module.exports = ->
  setupJquery()
  addGlobalErrorHandler()
  syncAuth()
  setupViews()
  setupAnalytics()

syncAuth = module.exports.syncAuth = ->
  # Log in to Force if you're logged in to Gravity
  if sd.AUTO_GRAVITY_LOGIN and not sd.CURRENT_USER
    $.ajax
      type: "POST"
      url: "#{sd.ARTSY_URL}/api/v1/me/trust_token"
      success: (response) ->
        $.ajax
          type: "POST"
          url: "/force/users/sign_in_trust_token?" +
               "token=#{response.trust_token}&redirect-to=#{window.location.pathname}"
          success: (response) ->
            window.location.reload()
  # Log out of Force if you're not logged in to Gravity
  if sd.CURRENT_USER
    $.ajax
      url: "#{sd.ARTSY_URL}/api/v1/me"
      error: -> window.location = '/force/users/sign_out'

setupAnalytics = ->
  # Initialize analytics & track page view if we included mixpanel
  # (not included in test environment).
  unless typeof mixpanel is 'undefined'
    analytics(mixpanel: mixpanel, ga: ga)
    analytics.trackPageview()

setupViews = ->
  unless $('body').hasClass 'is-microsite'
    new HeaderView el: $('#main-layout-header'), $window: $(window), $body: $('body')
    new FooterView el: $('#main-layout-footer')

setupJquery = ->
  require '../../node_modules/typeahead.js/dist/typeahead.min.js'
  require('jquery.transition')($, document)
  require 'jquery.fillwidth'
  require 'jquery.dotdotdot'
  require 'jquery.poplockit'
  require '../../lib/jquery/infinitescroll.coffee'
  require '../../lib/jquery/hidehover.coffee'
  $.ajaxSettings.headers =
    'X-XAPP-TOKEN'  : sd.ARTSY_XAPP_TOKEN
    'X-ACCESS-TOKEN': sd.CURRENT_USER?.accessToken

# Add global error handler that sends javascript errors to an
# endpoint for New Relic to track.
addGlobalErrorHandler = ->
  window.onerror = (msg, url, lineno, linecol, err) ->
    $.ajax
      url: '/force/javascripterr'
      type: 'POST'<commit_msg>still initialize the footer on microsite pages<commit_after>Backbone    = require 'backbone'
Backbone.$  = $
HeaderView  = require './header/view.coffee'
FooterView  = require './footer/view.coffee'
sd          = require('sharify').data
analytics   = require '../../lib/analytics.coffee'

module.exports = ->
  setupJquery()
  addGlobalErrorHandler()
  syncAuth()
  setupViews()
  setupAnalytics()

syncAuth = module.exports.syncAuth = ->
  # Log in to Force if you're logged in to Gravity
  if sd.AUTO_GRAVITY_LOGIN and not sd.CURRENT_USER
    $.ajax
      type: "POST"
      url: "#{sd.ARTSY_URL}/api/v1/me/trust_token"
      success: (response) ->
        $.ajax
          type: "POST"
          url: "/force/users/sign_in_trust_token?" +
               "token=#{response.trust_token}&redirect-to=#{window.location.pathname}"
          success: (response) ->
            window.location.reload()
  # Log out of Force if you're not logged in to Gravity
  if sd.CURRENT_USER
    $.ajax
      url: "#{sd.ARTSY_URL}/api/v1/me"
      error: -> window.location = '/force/users/sign_out'

setupAnalytics = ->
  # Initialize analytics & track page view if we included mixpanel
  # (not included in test environment).
  unless typeof mixpanel is 'undefined'
    analytics(mixpanel: mixpanel, ga: ga)
    analytics.trackPageview()

setupViews = ->
  unless $('body').hasClass 'is-microsite'
    new HeaderView el: $('#main-layout-header'), $window: $(window), $body: $('body')
  new FooterView el: $('#main-layout-footer')

setupJquery = ->
  require '../../node_modules/typeahead.js/dist/typeahead.min.js'
  require('jquery.transition')($, document)
  require 'jquery.fillwidth'
  require 'jquery.dotdotdot'
  require 'jquery.poplockit'
  require '../../lib/jquery/infinitescroll.coffee'
  require '../../lib/jquery/hidehover.coffee'
  $.ajaxSettings.headers =
    'X-XAPP-TOKEN'  : sd.ARTSY_XAPP_TOKEN
    'X-ACCESS-TOKEN': sd.CURRENT_USER?.accessToken

# Add global error handler that sends javascript errors to an
# endpoint for New Relic to track.
addGlobalErrorHandler = ->
  window.onerror = (msg, url, lineno, linecol, err) ->
    $.ajax
      url: '/force/javascripterr'
      type: 'POST'
{'fraction_non_alphanumeric': 0.143415306826017, 'fraction_numerical': 0.0009193288899103654, 'mean_word_length': 3.14081826831589, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3294280', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1403, 'n_words': 329}