bootstrap-popover.js 2.91 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
/* ===========================================================
Mark Otto's avatar
Mark Otto committed
2
 * bootstrap-popover.js v2.2.2
Jacob Thornton's avatar
Jacob Thornton committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * http://twitter.github.com/bootstrap/javascript.html#popovers
 * ===========================================================
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================================================== */


21
!function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
22

23
24
25
26
27
  "use strict"; // jshint ;_;


 /* POPOVER PUBLIC CLASS DEFINITION
  * =============================== */
Jacob Thornton's avatar
Jacob Thornton committed
28

Jacob Thornton's avatar
Jacob Thornton committed
29
  var Popover = function (element, options) {
Jacob Thornton's avatar
Jacob Thornton committed
30
31
32
    this.init('popover', element, options)
  }

33

Jacob Thornton's avatar
Jacob Thornton committed
34
35
36
37
38
39
40
41
42
43
44
45
  /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
     ========================================== */

  Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {

    constructor: Popover

  , setContent: function () {
      var $tip = this.tip()
        , title = this.getTitle()
        , content = this.getContent()

46
      $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
Mark Otto's avatar
Mark Otto committed
47
      $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
Jacob Thornton's avatar
Jacob Thornton committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

      $tip.removeClass('fade top bottom left right in')
    }

  , hasContent: function () {
      return this.getTitle() || this.getContent()
    }

  , getContent: function () {
      var content
        , $e = this.$element
        , o = this.options

      content = $e.attr('data-content')
        || (typeof o.content == 'function' ? o.content.call($e[0]) :  o.content)

      return content
    }

67
  , tip: function () {
Jacob Thornton's avatar
Jacob Thornton committed
68
69
70
71
72
73
      if (!this.$tip) {
        this.$tip = $(this.options.template)
      }
      return this.$tip
    }

Mark Otto's avatar
Mark Otto committed
74
  , destroy: function () {
Jacob Thornton's avatar
Jacob Thornton committed
75
      this.hide().$element.off('.' + this.type).removeData(this.type)
Mark Otto's avatar
Mark Otto committed
76
77
    }

Jacob Thornton's avatar
Jacob Thornton committed
78
79
80
81
82
83
  })


 /* POPOVER PLUGIN DEFINITION
  * ======================= */

84
  $.fn.popover = function (option) {
Jacob Thornton's avatar
Jacob Thornton committed
85
86
87
88
89
90
91
92
93
94
95
96
97
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('popover')
        , options = typeof option == 'object' && option
      if (!data) $this.data('popover', (data = new Popover(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }

  $.fn.popover.Constructor = Popover

  $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
    placement: 'right'
98
  , trigger: 'click'
Jacob Thornton's avatar
Jacob Thornton committed
99
  , content: ''
Mark Otto's avatar
Mark Otto committed
100
  , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"></div></div></div>'
Jacob Thornton's avatar
Jacob Thornton committed
101
102
  })

Mark Otto's avatar
Mark Otto committed
103
}(window.jQuery);