<commit_before>'use strict';


//
// Cache user profiles for 5 minutes
//

var CACHE     = {};
var CACHE_TTL = 5 * 60 * 1000; // time in ms

//
// Time in milliseconds before showing a popover
//

var POPOVER_INTENT = 500;


//
// Cross-browser Date.now()
//

function now() {
  return (new Date()).getTime();
}


//
// Returns user info card from cache.
// Request from server if it's not yet cahed or cache outdated.
//

function getUserInfo(id, callback) {
  if (CACHE[id] && CACHE_TTL > (CACHE[id].ts - now())) {
    callback(CACHE[id]);
    return;
  }

  nodeca.io.apiTree('users.usercard_popover', { id: id }, function (err, resp) {
    callback(CACHE[id] = {
      ts:   now(),
      user: (err ? null : (resp.data || {}).user)
    });
  });
}


////////////////////////////////////////////////////////////////////////////////


$.fn.powerTip.smartPlacementLists.usercard = [ 'nw-sw', 'sw-nw', 'ne-se', 'se-ne' ];


////////////////////////////////////////////////////////////////////////////////


module.exports = function active_profiles() {
  $('body').on('mouseenter.nodeca.data-api', 'a.usercard-popover', function (event) {
    var $this = $(this),
        id    = $this.data('user-id'),
        card  = $this.data('usercard');

    if (!id) {
      return;
    }

    getUserInfo(id, function (data) {
      if (!data.user) {
        // no user -- do not do anything
        return;
      }

      if (card !== data.ts) {
        $this.data('usercard', data.ts);
        $this.data('powertip', nodeca.client.common.render('common.widgets.usercard_popover', data.user));
      }

      if (!card) {
        $this.powerTip({
          placement:          'usercard',
          smartPlacement:     true,
          mouseOnToPopup:     true,
          intentPollInterval: POPOVER_INTENT
        });

        setTimeout(function () {
          $.powerTip.showTip($this);
        }, POPOVER_INTENT);
      }
    });
  });
};
<commit_msg>Fix popover delays<commit_after>'use strict';


//
// Cache user profiles for 5 minutes
//

var CACHE     = {};
var CACHE_TTL = 5 * 60 * 1000; // time in ms

//
// Time in milliseconds before showing an info card
//

var DELAY   = 750;
var TIMEOUT = null; // timout id


//
// Cross-browser Date.now()
//

function now() {
  return (new Date()).getTime();
}


//
// Returns user info card from cache.
// Request from server if it's not yet cahed or cache outdated.
//

function getUserInfo(id, callback) {
  if (CACHE[id] && CACHE_TTL > (CACHE[id].ts - now())) {
    callback(CACHE[id]);
    return;
  }

  nodeca.io.apiTree('users.usercard_popover', { id: id }, function (err, resp) {
    callback(CACHE[id] = {
      ts:   now(),
      user: (err ? null : (resp.data || {}).user)
    });
  });
}


////////////////////////////////////////////////////////////////////////////////


$.fn.powerTip.smartPlacementLists.usercard = [ 'nw-sw', 'sw-nw', 'ne-se', 'se-ne' ];


////////////////////////////////////////////////////////////////////////////////


module.exports = function active_profiles() {
  $('body').on('hover.nodeca.data-api', 'a.usercard-popover', function (event) {
    var $this = $(this),
        id    = $this.data('user-id'),
        card  = $this.data('usercard');

    clearTimeout(TIMEOUT);

    if (!id || 'mouseleave' === event.type) {
      return;
    }

    TIMEOUT = setTimeout(function () {
      getUserInfo(id, function (data) {
        if (!data.user) {
          // no user -- do not do anything
          return;
        }

        if (card !== data.ts) {
          $this.data('usercard', data.ts);
          $this.data('powertip', nodeca.client.common.render('common.widgets.usercard_popover', data.user));
        }

        if (!card) {
          $this.powerTip({
            placement:      'usercard',
            smartPlacement: true,
            mouseOnToPopup: true
          });

          $.powerTip.showTip($this);
        }
      });
    }, DELAY);
  });
};

{'fraction_non_alphanumeric': 0.24107368954165612, 'fraction_numerical': 0.005571030640668524, 'mean_word_length': 1.6761517615176151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '656813', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1231, 'n_words': 274}