<commit_before>/**
 * Frontend related objects
 */
/* global FB, ga, _gaq, twttr, Image */
var jsFrontend = {
  debug: false,
  current: {},

  // init, something like a constructor
  init: function () {
    jsFrontend.current.language = jsFrontend.data.get('LANGUAGE')

    // init stuff
    jsFrontend.initAjax()

    jsFrontend.addModalEvents()

    jsFrontend.cookieBar.init()

    // init controls
    jsFrontend.controls.init()

    // init form
    jsFrontend.forms.init()

    // init gravatar
    jsFrontend.gravatar.init()

    // init statistics
    jsFrontend.statistics.init()

    // init twitter
    jsFrontend.twitter.init()
  },

  addModalEvents: function () {
    var $modals = $('[role=dialog].modal')

    if ($modals.length === 0) {
      return
    }

    $modals.on('shown.bs.modal', function () {
      $(this).attr('aria-hidden', 'false')
    })
    $modals.on('hide.bs.modal', function () {
      $(this).attr('aria-hidden', 'true')
    })
  },

  // init
  initAjax: function () {
    // set defaults for AJAX
    $.ajaxSetup({
      url: '/frontend/ajax',
      cache: false,
      type: 'POST',
      dataType: 'json',
      timeout: 10000,
      data: {fork: {module: null, action: null, language: jsFrontend.current.language}}
    })
  }
}

/**
 * Controls related javascript
 */
jsFrontend.controls = {
  // init, something like a constructor
  init: function () {
    jsFrontend.controls.bindTargetBlank()
  },

  // bind target blank
  bindTargetBlank: function () {
    $('a.targetBlank').attr('target', '_blank')
  }
}

/**
 * Handles the cookieBar
 */
jsFrontend.cookieBar = {
  init: function () {
    // if there is no cookiebar we shouldn't do anything
    if ($('#cookie-bar').length === 0) return

    var $cookieBar = $('#cookie-bar')

    // @remark: as you can see we use PHP-serialized values so we can use them in PHP too.
    // hide the cookieBar if needed
    if (utils.cookies.readCookie('cookie_bar_hide') === 'b%3A1%3B') {
      $cookieBar.hide()
    }

    $cookieBar.on('click', '[data-role="cookie-bar-button"]', function (e) {
      e.preventDefault()

      if ($(e.currentTarget).data('action') === 'agree') {
        utils.cookies.setCookie('cookie_bar_agree', 'Y')
        utils.cookies.setCookie('cookie_bar_hide', 'Y')
      } else {
        utils.cookies.setCookie('cookie_bar_agree', 'N')
        utils.cookies.setCookie('cookie_bar_hide', 'Y')
      }
      $cookieBar.hide()
    })
  }
}

/**
 * Data related methods
 */
jsFrontend.data = {
  initialized: false,
  data: {},

  init: function () {
    // check if var is available
    if (typeof jsData === 'undefined') throw new Error('jsData is not available')

    // populate
    jsFrontend.data.data = jsData
    jsFrontend.data.initialized = true
  },

  exists: function (key) {
    return (typeof jsFrontend.data.data[key] !== 'undefined')
  },

  get: function (key) {
    // init if needed
    if (!jsFrontend.data.initialized) jsFrontend.data.init()

    // return
    return jsFrontend.data.data[key]
  }
}

/**
 * Facebook related
 */
jsFrontend.facebook = {
  // will be called after Facebook is initialized
  afterInit: function () {
    // is GA available?
    if (typeof _gaq === 'object') {
      // subscribe and track like<commit_msg>Fix getting js data with from deep object<commit_after>/**
 * Frontend related objects
 */
/* global FB, ga, _gaq, twttr, Image */
var jsFrontend = {
  debug: false,
  current: {},

  // init, something like a constructor
  init: function () {
    jsFrontend.current.language = jsFrontend.data.get('LANGUAGE')

    // init stuff
    jsFrontend.initAjax()

    jsFrontend.addModalEvents()

    jsFrontend.cookieBar.init()

    // init controls
    jsFrontend.controls.init()

    // init form
    jsFrontend.forms.init()

    // init gravatar
    jsFrontend.gravatar.init()

    // init statistics
    jsFrontend.statistics.init()

    // init twitter
    jsFrontend.twitter.init()
  },

  addModalEvents: function () {
    var $modals = $('[role=dialog].modal')

    if ($modals.length === 0) {
      return
    }

    $modals.on('shown.bs.modal', function () {
      $(this).attr('aria-hidden', 'false')
    })
    $modals.on('hide.bs.modal', function () {
      $(this).attr('aria-hidden', 'true')
    })
  },

  // init
  initAjax: function () {
    // set defaults for AJAX
    $.ajaxSetup({
      url: '/frontend/ajax',
      cache: false,
      type: 'POST',
      dataType: 'json',
      timeout: 10000,
      data: {fork: {module: null, action: null, language: jsFrontend.current.language}}
    })
  }
}

/**
 * Controls related javascript
 */
jsFrontend.controls = {
  // init, something like a constructor
  init: function () {
    jsFrontend.controls.bindTargetBlank()
  },

  // bind target blank
  bindTargetBlank: function () {
    $('a.targetBlank').attr('target', '_blank')
  }
}

/**
 * Handles the cookieBar
 */
jsFrontend.cookieBar = {
  init: function () {
    // if there is no cookiebar we shouldn't do anything
    if ($('#cookie-bar').length === 0) return

    var $cookieBar = $('#cookie-bar')

    // @remark: as you can see we use PHP-serialized values so we can use them in PHP too.
    // hide the cookieBar if needed
    if (utils.cookies.readCookie('cookie_bar_hide') === 'b%3A1%3B') {
      $cookieBar.hide()
    }

    $cookieBar.on('click', '[data-role="cookie-bar-button"]', function (e) {
      e.preventDefault()

      if ($(e.currentTarget).data('action') === 'agree') {
        utils.cookies.setCookie('cookie_bar_agree', 'Y')
        utils.cookies.setCookie('cookie_bar_hide', 'Y')
      } else {
        utils.cookies.setCookie('cookie_bar_agree', 'N')
        utils.cookies.setCookie('cookie_bar_hide', 'Y')
      }
      $cookieBar.hide()
    })
  }
}

/**
 * Data related methods
 */
jsFrontend.data = {
  initialized: false,
  data: {},

  init: function () {
    // check if var is available
    if (typeof jsData === 'undefined') throw new Error('jsData is not available')

    // populate
    jsFrontend.data.data = jsData
    jsFrontend.data.initialized = true
  },

  exists: function (key) {
    return (typeof jsFrontend.data.data[key] !== 'undefined')
  },

  get: function (key) {
    // init if needed
    if (!jsFrontend.data.initialized) jsFrontend.data.init()

    var keys = key.split('.')
    var data = jsFrontend.data.data
    for (var i = 0; i < keys.length; i++) {
      data = data[keys[i]]
    }

    return data
  }
}

/**
 * Facebook related
 */
jsFrontend.facebook = {
  // will be called after Facebook is initialized
  afterInit: function () {
    // is GA available?
    if (typeof _gaq === 'object') {
      // subscribe and track like
{'fraction_non_alphanumeric': 0.157461457865589, 'fraction_numerical': 0.003143242029636282, 'mean_word_length': 2.623644251626898, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '5280378', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2148, 'n_words': 506}