<commit_before>// when document loads
$(document).ready(function () {

  // function for updating search results
  var getCourseData = function () {
    var query = {
      $text: {
        $search: $('#searchbox').val()
      },
      semester: $('#semester').val()
    }

    $.post('/api/courses',
    {
      query: JSON.stringify(query),
      sort: $('#sort').val()
    }, function (courses, status) {
      // Basic error handling
      if (status !== 'success') {
        window.alert('An error occured and your search could not be completed.')
      }

      // clear results
      $('#results').html('')

      /* SEB'S EXAMPLE

      // Insert the course results into the area
      for (var courseIndex in courses) {
        var thisCourse = courses[courseIndex]
        $('#results').append('<div class="course"><span style="font-weight:bold">' + thisCourse.department + ' ' + thisCourse.catalogNumber + '</span> ' + thisCourse.title + '</div>')
        $('#results').children().last()[0].course = thisCourse

      */

      for (var courseIndex in courses) {
        var thisCourse = courses[courseIndex]

        // string for course listings
        var listings = thisCourse.department + ' ' + thisCourse.catalogNumber
        for (var listing in thisCourse.crosslistings) {
          listings += '/' + thisCourse.crosslistings[listing].department
                    + ' ' + thisCourse.crosslistings[listing].catalogNumber
        }

        $('#results').append('<a class="list-group-item search-result"><div>' +
                             listings +
                             (thisCourse.distribution == undefined ? '' : ' <span class="label label-info">' + thisCourse.distribution + '</span>') +
                             '</div><div>' + thisCourse.title + '</div></a>')

        // attach object to DOM element
        $('#results').children().last()[0].course = thisCourse
      }
    })
  }

  // function for displaying course details
  var dispCourseData = function() {
    $(".search-result").removeClass("active");
    $(this).addClass("active")

    $('#disp-title').html('')
    $('#disp-profs').html('')
    $('#disp-desc').html('')
    $('#disp-body').html('')

    var thisCourse = this.course

    // string for course listings
    var listings = thisCourse.department + ' ' + thisCourse.catalogNumber
    for (var listing in thisCourse.crosslistings) {
      listings += '/' + thisCourse.crosslistings[listing].department
                + ' ' + thisCourse.crosslistings[listing].catalogNumber

    }

    $('#disp-title').append(listings + ' <small>' + thisCourse.title
                            + (thisCourse.distribution == undefined ? '' : ' <span class="label label-info">' + thisCourse.distribution + '</span>')
                            + '</small>')

    $('#disp-desc').append(thisCourse.description)

    $('#disp-body').append('<p>' + thisCourse.description + '</p><p>' + thisCourse.description + '</p><p>' +
                           thisCourse.description + '</p><p>' + thisCourse.description + '</p><p>' +
                           thisCourse.description + '</p><p>' +thisCourse.description + '</p>')
  }

  // Every time a key is pressed inside the #searchbox, call the getCourseData function
  $('#searchbox').keyup(getCourseData)
  $('#semester').change(getCourseData)<commit_msg>sort added<commit_after>// when document loads
$(document).ready(function () {

  // function for updating search results
  var getCourseData = function () {
    var query = {
      $text: {
        $search: $('#searchbox').val()
      },
      semester: $('#semester').val()
    }

    $.post('/api/courses',
    {
      query: JSON.stringify(query),
      sort: $('#sort').val()
    }, function (courses, status) {
      // Basic error handling
      if (status !== 'success') {
        window.alert('An error occured and your search could not be completed.')
      }

      // clear results
      $('#results').html('')

      /* SEB'S EXAMPLE

      // Insert the course results into the area
      for (var courseIndex in courses) {
        var thisCourse = courses[courseIndex]
        $('#results').append('<div class="course"><span style="font-weight:bold">' + thisCourse.department + ' ' + thisCourse.catalogNumber + '</span> ' + thisCourse.title + '</div>')
        $('#results').children().last()[0].course = thisCourse

      */

      for (var courseIndex in courses) {
        var thisCourse = courses[courseIndex]

        // string for course listings
        var listings = thisCourse.department + ' ' + thisCourse.catalogNumber
        for (var listing in thisCourse.crosslistings) {
          listings += '/' + thisCourse.crosslistings[listing].department
                    + ' ' + thisCourse.crosslistings[listing].catalogNumber
        }

        $('#results').append('<a class="list-group-item search-result"><div>' +
                             listings +
                             (thisCourse.distribution == undefined ? '' : ' <span class="label label-info">' + thisCourse.distribution + '</span>') +
                             '</div><div>' + thisCourse.title + '</div></a>')

        // attach object to DOM element
        $('#results').children().last()[0].course = thisCourse
      }
    })
  }

  // function for displaying course details
  var dispCourseData = function() {
    $(".search-result").removeClass("active");
    $(this).addClass("active")

    $('#disp-title').html('')
    $('#disp-profs').html('')
    $('#disp-desc').html('')
    $('#disp-body').html('')

    var thisCourse = this.course

    // string for course listings
    var listings = thisCourse.department + ' ' + thisCourse.catalogNumber
    for (var listing in thisCourse.crosslistings) {
      listings += '/' + thisCourse.crosslistings[listing].department
                + ' ' + thisCourse.crosslistings[listing].catalogNumber

    }

    $('#disp-title').append(listings + ' <small>' + thisCourse.title
                            + (thisCourse.distribution == undefined ? '' : ' <span class="label label-info">' + thisCourse.distribution + '</span>')
                            + '</small>')

    $('#disp-desc').append(thisCourse.description)

    $('#disp-body').append('<p>' + thisCourse.description + '</p><p>' + thisCourse.description + '</p><p>' +
                           thisCourse.description + '</p><p>' + thisCourse.description + '</p><p>' +
                           thisCourse.description + '</p><p>' +thisCourse.description + '</p>')
  }

  // Every time a key is pressed inside the #searchbox, call the getCourseData function
  $('#searchbox').keyup(getCourseData)
  $('#semester, #sort').change(getCourseData)
{'fraction_non_alphanumeric': 0.17109584950731563, 'fraction_numerical': 0.0005971931919976113, 'mean_word_length': 2.4022346368715084, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, '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': '1849349', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1793, 'n_words': 385}