popover.js 3.1 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
    $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
46
47
48
    $tip.find('.popover-content')[ // we use append for html objects to maintain js events
      this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
    ](content)
49

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

52
53
    // 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
54
    if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
fat's avatar
fat committed
55
  }
Jacob Thornton's avatar
Jacob Thornton committed
56

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

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

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

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

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

80

fat's avatar
fat committed
81
82
  // POPOVER PLUGIN DEFINITION
  // =========================
Jacob Thornton's avatar
Jacob Thornton committed
83

84
85
  var old = $.fn.popover

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

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

98
  $.fn.popover.Constructor = Popover
99

100

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

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

109
}(jQuery);