<commit_before>'use strict';

var $ = require('jquery');
var _ = require('underscore');
var Marionette = require('backbone.marionette');

module.exports = Marionette.Behavior.extend({
  onShow: function () {
    // Module hover brief info
    $("a[href^='/modules/'").qtip({
      content: {
        text: function(event, api) {
          var NUSMods = require('../../nusmods');
          var ModuleModel = require('../models/ModuleModel');
          
          var reqModuleCode = $(this).text();
          var reqModule = NUSMods.getMod(reqModuleCode).then(function(data) {
            var reqModuleModel = new ModuleModel(data);

            var title = reqModuleModel.get('ModuleTitle') + '\n'
            api.set('content.title', '<strong>' + title + '</strong>');

            var semesters = reqModuleModel.get('semesterNames');
            var offeredIn = _.reduce(semesters, function(a, b) {
              return a + ', ' + b;
            });
            api.set('content.text', 'Offered in: ' + offeredIn);
          });

          return 'Loading...';
        }
      },
      position: {
        effect: 'false',
        my: 'bottom center',
        at: 'top center'
      },
      show: {
        effect: function() {
          $(this).fadeTo(200, 0.85);
        }
      },
      events: {
        show: function(event, api) {
          // Prevents qtip from appearing when hovering over main module link
          if ($(event.originalEvent.currentTarget).parent().is('h2')) {
            event.preventDefault();
          }
        }
      }
    });
  }
});

<commit_msg>Clean up code for ModuleHoverBehavior<commit_after>'use strict';

var $ = require('jquery');
var _ = require('underscore');
var Marionette = require('backbone.marionette');

module.exports = Marionette.Behavior.extend({
  events: {
    "mouseenter a[href^='/modules/']" : 'showDetails'
  },

  showDetails: function(event) {
    var curr = event.currentTarget;

    var NUSMods = require('../../nusmods');
    var ModuleModel = require('../models/ModuleModel');

    var reqModuleCode = $(curr).text();

    $(curr).qtip({
      content: function(event, api) {
        var reqModule = NUSMods.getMod(reqModuleCode)
          .then(function(data) {
            var reqModuleModel = new ModuleModel(data);

            var title = reqModuleModel.get('ModuleTitle');
            var semesters = reqModuleModel.get('semesterNames');
            var offeredIn = _.reduce(semesters, function(a, b) {
              return a + ', ' + b;
            });

            api.set('content.title', '<strong>' + title + '</strong>');
            api.set('content.text', 'Offered in: ' + offeredIn);
          });
        return 'Loading...';
      },
      show: {
        event: event.type,
        ready: true
      },
      position: {
        effect: 'false',
        my: 'bottom center',
        at: 'top center'
      },
      events: {
        show: function(event, api) {
          // Prevents qtip from loading if main module link is selected
          if ($(curr).parent().is('h2')) {
            event.preventDefault();
          }
        }
      }
    }, event);
  }
});


{'fraction_non_alphanumeric': 0.15726062143310082, 'fraction_numerical': 0.0025364616360177552, 'mean_word_length': 1.9708097928436912, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2007590', 'n_tokens_mistral': 930, 'n_tokens_neox': 900, 'n_words': 195}