[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/js/core/ -> behavior-hovercard.js (source)

   1  /**
   2   * @provides javelin-behavior-phabricator-hovercards
   3   * @requires javelin-behavior
   4   *           javelin-behavior-device
   5   *           javelin-stratcom
   6   *           javelin-vector
   7   *           phabricator-hovercard
   8   * @javelin
   9   */
  10  
  11  JX.behavior('phabricator-hovercards', function() {
  12  
  13    // We listen for mousemove instead of mouseover to handle the case when user
  14    // scrolls with keyboard. We don't want to display hovercard if node gets
  15    // under the mouse cursor randomly placed somewhere on the screen. This
  16    // unfortunately doesn't work in Google Chrome which triggers both mousemove
  17    // and mouseover in this case but works in other browsers.
  18    JX.Stratcom.listen(
  19      'mousemove',
  20      'hovercard',
  21      function (e) {
  22        if (JX.Device.getDevice() != 'desktop') {
  23          return;
  24        }
  25  
  26        var data = e.getNodeData('hovercard');
  27  
  28        JX.Hovercard.show(
  29          e.getNode('hovercard'),
  30          data.hoverPHID);
  31      });
  32  
  33    JX.Stratcom.listen(
  34      'mousemove',
  35      null,
  36      function (e) {
  37        if (!JX.Hovercard.getCard()) {
  38          return;
  39        }
  40  
  41        var root = JX.Hovercard.getAnchor();
  42        var node = JX.Hovercard.getCard();
  43  
  44        // TODO: Add southern cases here, too
  45        var mouse = JX.$V(e);
  46        var node_pos = JX.$V(node);
  47        var node_dim = JX.Vector.getDim(node);
  48        var root_pos = JX.$V(root);
  49        var root_dim = JX.Vector.getDim(root);
  50  
  51        var margin = 20;
  52  
  53        // Cursor is above the node.
  54        if (mouse.y < node_pos.y - margin) {
  55          JX.Hovercard.hide();
  56        }
  57  
  58        // Cursor is below the root.
  59        if (mouse.y > root_pos.y + root_dim.y + margin) {
  60          JX.Hovercard.hide();
  61        }
  62  
  63        // Cursor is too far to the left.
  64        if (mouse.x < Math.min(root_pos.x, node_pos.x) - margin) {
  65          JX.Hovercard.hide();
  66        }
  67  
  68         // Cursor is too far to the right.
  69        if (mouse.x >
  70          Math.max(root_pos.x + root_dim.x, node_pos.x + node_dim.x) + margin) {
  71          JX.Hovercard.hide();
  72        }
  73      });
  74  
  75    // When we leave the page, hide any visible hovercards. If we don't do this,
  76    // clicking a link with a hovercard and then hitting "back" will give you a
  77    // phantom card. We also hide cards if the window resizes.
  78    JX.Stratcom.listen(
  79      ['unload', 'onresize'],
  80      null,
  81      function() {
  82        JX.Hovercard.hide();
  83      });
  84  
  85  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1