popover.js 2.99 KB
Newer Older
1
/* ========================================================================
2
 * Bootstrap: popover.js v3.0.3
3
 * http://getbootstrap.com/javascript/#popovers
4
 * ========================================================================
Zlatan Vasović's avatar
Zlatan Vasović committed
5
 * Copyright 2013 Twitter, Inc.
6
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7
 * ======================================================================== */
Jacob Thornton's avatar
Jacob Thornton committed
8
9


XhmikosR's avatar
XhmikosR committed
10
+function ($) { 'use strict';
Jacob Thornton's avatar
Jacob Thornton committed
11

fat's avatar
fat committed
12
13
  // POPOVER PUBLIC CLASS DEFINITION
  // ===============================
14

Jacob Thornton's avatar
Jacob Thornton committed
15
  var Popover = function (element, options) {
16
    this.init('popover', element, options)
Jacob Thornton's avatar
Jacob Thornton committed
17
18
  }

fat's avatar
fat committed
19
20
  if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')

Zlatan Vasović's avatar
Zlatan Vasović committed
21
22
23
24
25
  Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
    placement: 'right',
    trigger: 'click',
    content: '',
    template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
fat's avatar
fat committed
26
  })
27

Jacob Thornton's avatar
Jacob Thornton committed
28

fat's avatar
fat committed
29
30
  // NOTE: POPOVER EXTENDS tooltip.js
  // ================================
Jacob Thornton's avatar
Jacob Thornton committed
31

fat's avatar
fat committed
32
  Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
33

fat's avatar
fat committed
34
  Popover.prototype.constructor = Popover
35

fat's avatar
fat committed
36
37
38
  Popover.prototype.getDefaults = function () {
    return Popover.DEFAULTS
  }
39

fat's avatar
fat committed
40
41
42
43
  Popover.prototype.setContent = function () {
    var $tip    = this.tip()
    var title   = this.getTitle()
    var content = this.getContent()
Jacob Thornton's avatar
Jacob Thornton committed
44

fat's avatar
fat committed
45
46
    $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
    $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
47

fat's avatar
fat committed
48
    $tip.removeClass('fade top bottom left right in')
49

50
51
    // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
    // this manually by checking the contents.
Jacob Thornton's avatar
Jacob Thornton committed
52
    if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
fat's avatar
fat committed
53
  }
Jacob Thornton's avatar
Jacob Thornton committed
54

fat's avatar
fat committed
55
56
57
  Popover.prototype.hasContent = function () {
    return this.getTitle() || this.getContent()
  }
58

fat's avatar
fat committed
59
  Popover.prototype.getContent = function () {
fat's avatar
fat committed
60
61
    var $e = this.$element
    var o  = this.options
Jacob Thornton's avatar
Jacob Thornton committed
62

fat's avatar
fat committed
63
64
65
66
    return $e.attr('data-content')
      || (typeof o.content == 'function' ?
            o.content.call($e[0]) :
            o.content)
fat's avatar
fat committed
67
  }
Jacob Thornton's avatar
Jacob Thornton committed
68

Braden Whitten's avatar
Braden Whitten committed
69
  Popover.prototype.arrow = function () {
fat's avatar
fat committed
70
71
72
    return this.$arrow = this.$arrow || this.tip().find('.arrow')
  }

fat's avatar
fat committed
73
74
75
76
  Popover.prototype.tip = function () {
    if (!this.$tip) this.$tip = $(this.options.template)
    return this.$tip
  }
77

78

fat's avatar
fat committed
79
80
  // POPOVER PLUGIN DEFINITION
  // =========================
Jacob Thornton's avatar
Jacob Thornton committed
81

82
83
  var old = $.fn.popover

84
  $.fn.popover = function (option) {
85
    return this.each(function () {
fat's avatar
fat committed
86
      var $this   = $(this)
87
      var data    = $this.data('bs.popover')
88
      if (!data && option === 'destroy') return
fat's avatar
fat committed
89
90
      var options = typeof option == 'object' && option

91
      if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
92
93
      if (typeof option == 'string') data[option]()
    })
Jacob Thornton's avatar
Jacob Thornton committed
94
95
  }

96
  $.fn.popover.Constructor = Popover
97

98

fat's avatar
fat committed
99
100
  // POPOVER NO CONFLICT
  // ===================
101
102
103
104
105
106

  $.fn.popover.noConflict = function () {
    $.fn.popover = old
    return this
  }

107
}(jQuery);