[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/js/application/aphlict/ -> behavior-aphlict-dropdown.js (source)

   1  /**
   2   * @provides javelin-behavior-aphlict-dropdown
   3   * @requires javelin-behavior
   4   *           javelin-request
   5   *           javelin-stratcom
   6   *           javelin-vector
   7   *           javelin-dom
   8   *           javelin-uri
   9   *           javelin-behavior-device
  10   *           phabricator-title
  11   */
  12  
  13  JX.behavior('aphlict-dropdown', function(config, statics) {
  14    // Track the current globally visible menu.
  15    statics.visible = statics.visible || null;
  16  
  17    var dropdown = JX.$(config.dropdownID);
  18    var bubble = JX.$(config.bubbleID);
  19  
  20    var count;
  21    if (config.countID) {
  22      count = JX.$(config.countID);
  23    }
  24  
  25    var request = null;
  26    var dirty = config.local ? false : true;
  27  
  28    JX.Title.setCount(config.countType, config.countNumber);
  29  
  30    function refresh() {
  31      if (dirty) {
  32        JX.DOM.setContent(dropdown, config.loadingText);
  33        JX.DOM.alterClass(
  34          dropdown,
  35          'phabricator-notification-menu-loading',
  36          true);
  37      }
  38  
  39      if (request) { //already fetching
  40        return;
  41      }
  42  
  43      request = new JX.Request(config.uri, function(response) {
  44        JX.Title.setCount(config.countType, response.number);
  45  
  46        var display = (response.number > 999) ? '\u221E' : response.number;
  47  
  48        JX.DOM.setContent(count, display);
  49        if (response.number === 0) {
  50          JX.DOM.alterClass(bubble, 'alert-unread', false);
  51        } else {
  52          JX.DOM.alterClass(bubble, 'alert-unread', true);
  53        }
  54        dirty = false;
  55        JX.DOM.alterClass(
  56          dropdown,
  57          'phabricator-notification-menu-loading',
  58          false);
  59        JX.DOM.setContent(dropdown, JX.$H(response.content));
  60        request = null;
  61      });
  62      request.send();
  63    }
  64  
  65    JX.Stratcom.listen(
  66      'click',
  67      null,
  68      function(e) {
  69        if (!e.getNode('phabricator-notification-menu')) {
  70          // Click outside the dropdown; hide it.
  71          JX.DOM.hide(dropdown);
  72          statics.visible = null;
  73          return;
  74        }
  75  
  76        if (e.getNode('tag:a')) {
  77          // User clicked a link, just follow the link.
  78          return;
  79        }
  80  
  81        if (!e.getNode('notification')) {
  82          // User clicked somewhere in the dead area of the menu, like the header
  83          // or footer.
  84          return;
  85        }
  86  
  87        // If the user clicked a notification (but missed a link) and it has a
  88        // primary URI, go there.
  89        var href = e.getNodeData('notification').href;
  90        if (href) {
  91          JX.$U(href).go();
  92          e.kill();
  93        }
  94      });
  95  
  96  
  97    JX.DOM.listen(
  98      bubble,
  99      'click',
 100      null,
 101      function(e) {
 102        if (!e.isNormalClick()) {
 103          return;
 104        }
 105  
 106        if (config.desktop && JX.Device.getDevice() != 'desktop') {
 107          return;
 108        }
 109  
 110        e.kill();
 111  
 112        // If a menu is currently open, close it.
 113        if (statics.visible) {
 114          var previously_visible = statics.visible;
 115          JX.DOM.hide(statics.visible);
 116          statics.visible = null;
 117  
 118          // If the menu we just closed was the menu attached to the clicked
 119          // icon, we're all done -- clicking the icon for an open menu just
 120          // closes it. Otherwise, we closed some other menu and still need to
 121          // open the one the user just clicked.
 122          if (previously_visible === dropdown) {
 123            return;
 124          }
 125        }
 126  
 127        if (dirty) {
 128          refresh();
 129        }
 130  
 131        var p = JX.$V(bubble);
 132        JX.DOM.show(dropdown);
 133  
 134        p.y = null;
 135        if (config.right) {
 136          p.x -= (JX.Vector.getDim(dropdown).x - JX.Vector.getDim(bubble).x);
 137        } else {
 138          p.x -= 6;
 139        }
 140        p.setPos(dropdown);
 141  
 142        statics.visible = dropdown;
 143      }
 144    );
 145  
 146    JX.Stratcom.listen('notification-panel-update', null, function() {
 147      if (config.local) {
 148        return;
 149      }
 150      dirty = true;
 151      refresh();
 152    });
 153  });


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