<commit_before>(function(Factlink, $, _, easyXDM, window, undefined) {

Factlink.Fact = function() {
  var elements;
  // This is to scare Mark:
  var timeout;
  var highlight_timeout;

  // The balloon which corresponds to this Fact
  var balloon;

  var _obj;
  // For use inside other function scopes
  var self = this;
  // Internal object which will hold all bound event handlers
  var _bound_events = {};
  // If you want to support more events add them to this variable:
  var _events = ["focus", "blur", "click", "update"];

  function initialize(id, elems, opinions) {
    elements = elems;

    _obj = {
      "id": id,
      "opinions": opinions
    };

    createEventHandlers(_events);

    highlight();

    balloon = new Factlink.Balloon(id, self);

    // Bind the own events
    $(elements)
      .bind('mouseenter', self.focus)
      .bind('mouseleave', self.blur)
      .bind('click', self.click);

    bindFocus();

    bindClick(id);

    stopHighlighting(1500);
  }

  // This may look like some magic, but here we expose the Fact.blur/focus/click
  // methods
  function createEventHandlers(events) {
    for ( var i = 0; i < events.length; i++ ) {
      _bound_events[events[i]] = [];

      self[events[i]] = (function(i) {
        var e = events[i];

        return function() {
          var args = [e].concat(Array.prototype.slice.call(arguments));

          if ( $.isFunction( args[1] ) ) {
            bind.apply(this, args);
          } else {
            trigger.apply(this, args);
          }
        };
      })(i);
    }
  }

  function bind(type, fn) {
    _bound_events[type].push(fn);
  }

  function trigger(type) {
    var args = Array.prototype.slice.call(arguments);

    args.shift();

    for (var i = 0; i < _bound_events[type].length; i++) {
      _bound_events[type][i].apply(this, args);
    }
  }

  function highlight() {
    clearTimeout(highlight_timeout);

    $( elements ).addClass('fl-active');
  }

  function stopHighlighting(timer) {
    clearTimeout(highlight_timeout);

    if ( timer ) {
      highlight_timeout = setTimeout(function() {
        $( elements ).removeClass('fl-active');
      }, timer);
    } else {
      $( elements ).removeClass('fl-active');
    }
  }

  function bindFocus() {
    self.focus(function(e) {
      clearTimeout(timeout);

      highlight();

      if ( ! balloon.isVisible() ) {
        // Need to call a direct .hide() here to make sure not two popups are
        // open at a time
        Factlink.el.find('div.fl-popup').hide();
        balloon.show($(e.target)[0].offsetTop, e.pageX, e.show_fast);
      }
    });

    self.blur(function(e) {
      clearTimeout(timeout);

      stopHighlighting();

      timeout = setTimeout(function(){
        balloon.hide();
      }, 300);
    });
  }

  function bindClick(id) {
    self.click(function(e) {
      var self = this;
      // A custom switch-like module
      var modusHandler = (function() {
        return {
          "default": function() {
            Factlink.showInfo(id);
          },
          addToFact: function() {
            Factlink.prepare.show(e.pageX, e.pageY);
            Factlink.prepare.setFactId(id);
          }<commit_msg>Revert "use native offsetTop since .offset() does not work together with margin's"<commit_after>(function(Factlink, $, _, easyXDM, window, undefined) {

Factlink.Fact = function() {
  var elements;
  // This is to scare Mark:
  var timeout;
  var highlight_timeout;

  // The balloon which corresponds to this Fact
  var balloon;

  var _obj;
  // For use inside other function scopes
  var self = this;
  // Internal object which will hold all bound event handlers
  var _bound_events = {};
  // If you want to support more events add them to this variable:
  var _events = ["focus", "blur", "click", "update"];

  function initialize(id, elems, opinions) {
    elements = elems;

    _obj = {
      "id": id,
      "opinions": opinions
    };

    createEventHandlers(_events);

    highlight();

    balloon = new Factlink.Balloon(id, self);

    // Bind the own events
    $(elements)
      .bind('mouseenter', self.focus)
      .bind('mouseleave', self.blur)
      .bind('click', self.click);

    bindFocus();

    bindClick(id);

    stopHighlighting(1500);
  }

  // This may look like some magic, but here we expose the Fact.blur/focus/click
  // methods
  function createEventHandlers(events) {
    for ( var i = 0; i < events.length; i++ ) {
      _bound_events[events[i]] = [];

      self[events[i]] = (function(i) {
        var e = events[i];

        return function() {
          var args = [e].concat(Array.prototype.slice.call(arguments));

          if ( $.isFunction( args[1] ) ) {
            bind.apply(this, args);
          } else {
            trigger.apply(this, args);
          }
        };
      })(i);
    }
  }

  function bind(type, fn) {
    _bound_events[type].push(fn);
  }

  function trigger(type) {
    var args = Array.prototype.slice.call(arguments);

    args.shift();

    for (var i = 0; i < _bound_events[type].length; i++) {
      _bound_events[type][i].apply(this, args);
    }
  }

  function highlight() {
    clearTimeout(highlight_timeout);

    $( elements ).addClass('fl-active');
  }

  function stopHighlighting(timer) {
    clearTimeout(highlight_timeout);

    if ( timer ) {
      highlight_timeout = setTimeout(function() {
        $( elements ).removeClass('fl-active');
      }, timer);
    } else {
      $( elements ).removeClass('fl-active');
    }
  }

  function bindFocus() {
    self.focus(function(e) {
      clearTimeout(timeout);

      highlight();

      if ( ! balloon.isVisible() ) {
        // Need to call a direct .hide() here to make sure not two popups are
        // open at a time
        Factlink.el.find('div.fl-popup').hide();
        balloon.show($(e.target).offset().top, e.pageX, e.show_fast);
      }
    });

    self.blur(function(e) {
      clearTimeout(timeout);

      stopHighlighting();

      timeout = setTimeout(function(){
        balloon.hide();
      }, 300);
    });
  }

  function bindClick(id) {
    self.click(function(e) {
      var self = this;
      // A custom switch-like module
      var modusHandler = (function() {
        return {
          "default": function() {
            Factlink.showInfo(id);
          },
          addToFact: function() {
            Factlink.prepare.show(e.pageX, e.pageY);
            Factlink.prepare.setFactId(id);
          }
{'fraction_non_alphanumeric': 0.14140009272137227, 'fraction_numerical': 0.003245248029670839, 'mean_word_length': 2.2986748216106014, 'pattern_counts': {'":': 6, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6624026', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1949, 'n_words': 479}