<commit_before>define (require) ->
  $ = require('jquery')
  Backbone = require('backbone')
  settings = require('settings')
  session = require('cs!session')
  analytics = require('cs!helpers/handlers/analytics')
  router = require('cs!router')
  require('cs!helpers/backbone/history') # Extend Backbone.history to support query strings
  require('less!../styles/main')

  # The root URI prefixed on all non-external AJAX and Backbone URIs
  root = settings.root

  # Patch `Backbone.ajax` so unauthorized responses are redirected to `/login`
  Backbone_ajax = Backbone.ajax
  Backbone.ajax = () ->
    promise = Backbone_ajax.apply(@, arguments)
    promise.fail (jqXHR) ->
      switch jqXHR.status
        when 403 # HACK: this should be 401
          window.location.href = '/login'
        else
          console.error(arguments)

    return promise


  init = (options = {}) ->
    # Append /test to the root if the app is in test mode
    if options.test
      root += 'test/'

    external = new RegExp('^((f|ht)tps?:)?\/\/')
    resources = new RegExp('\/(resources|exports)\/')

    # Catch internal application links and let Backbone handle the routing
    $(document).on 'click', 'a[href]:not([data-bypass]):not([href^="#"])', (e) ->
      $this = $(this)
      href = $this.attr('href')

      # Only handle links intended to be processed by Backbone
      if e.isDefaultPrevented() or href.charAt(0) is '#' or /^mailto:.+/.test(href) then return
<commit_msg>Redirect for everything except session lookup<commit_after>define (require) ->
  $ = require('jquery')
  Backbone = require('backbone')
  settings = require('settings')
  session = require('cs!session')
  analytics = require('cs!helpers/handlers/analytics')
  router = require('cs!router')
  require('cs!helpers/backbone/history') # Extend Backbone.history to support query strings
  require('less!../styles/main')

  # The root URI prefixed on all non-external AJAX and Backbone URIs
  root = settings.root

  # Patch `Backbone.sync` so unauthorized responses are redirected to `/login`
  Backbone_sync = Backbone.sync
  Backbone.sync = (method, model, options) ->
    promise = Backbone_sync.call(@, method, model, options)

    # Do not redirect when trying to determine the login state
    # But redirect otherwise
    if model isnt session
      promise.fail (jqXHR) ->
        switch jqXHR.status
          when 403 # HACK: this should be 401
            window.location.href = '/login'
          else
            console.error(arguments)

    return promise


  init = (options = {}) ->
    # Append /test to the root if the app is in test mode
    if options.test
      root += 'test/'

    external = new RegExp('^((f|ht)tps?:)?\/\/')
    resources = new RegExp('\/(resources|exports)\/')

    # Catch internal application links and let Backbone handle the routing
    $(document).on 'click', 'a[href]:not([data-bypass]):not([href^="#"])', (e) ->
      $this = $(this)
      href = $this.attr('href')

      # Only handle links intended to be processed by Backbone
      if e.isDefaultPrevented() or href.charAt(0) is '#' or /^mailto:.+/.test(href) then return

{'fraction_non_alphanumeric': 0.13744829780464524, 'fraction_numerical': 0.004454342984409799, 'mean_word_length': 3.1587301587301586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6169223', 'n_tokens_mistral': 969, 'n_tokens_neox': 939, 'n_words': 279}