aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/common/popup.js
blob: a3d15c1bbb82eb3aac1920e8a2cacaf1626378d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define(function () {

  var $ = jQuery;

  return Marionette.ItemView.extend({
    className: 'bubble-popup',

    onRender: function () {
      this.$el.detach().appendTo($('body'));
      if (this.options.bottom) {
        this.$el.addClass('bubble-popup-bottom');
        this.$el.css({
          top: this.options.triggerEl.offset().top + this.options.triggerEl.outerHeight(),
          left: this.options.triggerEl.offset().left
        });
      } else if (this.options.bottomRight) {
        this.$el.addClass('bubble-popup-bottom-right');
        this.$el.css({
          top: this.options.triggerEl.offset().top + this.options.triggerEl.outerHeight(),
          right: $(window).width() - this.options.triggerEl.offset().left - this.options.triggerEl.outerWidth()
        });
      } else {
        this.$el.css({
          top: this.options.triggerEl.offset().top,
          left: this.options.triggerEl.offset().left + this.options.triggerEl.outerWidth()
        });
      }
      this.attachCloseEvents();
    },

    attachCloseEvents: function () {
      var that = this;
      key('escape', function () {
        that.destroy();
      });
      $('body').on('click.bubble-popup', function () {
        $('body').off('click.bubble-popup');
        that.destroy();
      });
      this.options.triggerEl.on('click.bubble-popup', function (e) {
        that.options.triggerEl.off('click.bubble-popup');
        e.stopPropagation();
        that.destroy();
      });
    },

    onDestroy: function () {
      $('body').off('click.bubble-popup');
      this.options.triggerEl.off('click.bubble-popup');
    }
  });

});