unignore bower_components
[bootswatch] / bower_components / bootstrap / js / popover.js
1 /* ========================================================================
2  * Bootstrap: popover.js v3.0.0
3  * http://twbs.github.com/bootstrap/javascript.html#popovers
4  * ========================================================================
5  * Copyright 2012 Twitter, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ======================================================================== */
19
20
21 +function ($) { "use strict";
22
23   // POPOVER PUBLIC CLASS DEFINITION
24   // ===============================
25
26   var Popover = function (element, options) {
27     this.init('popover', element, options)
28   }
29
30   if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
31
32   Popover.DEFAULTS = $.extend({} , $.fn.tooltip.Constructor.DEFAULTS, {
33     placement: 'right'
34   , trigger: 'click'
35   , content: ''
36   , template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
37   })
38
39
40   // NOTE: POPOVER EXTENDS tooltip.js
41   // ================================
42
43   Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
44
45   Popover.prototype.constructor = Popover
46
47   Popover.prototype.getDefaults = function () {
48     return Popover.DEFAULTS
49   }
50
51   Popover.prototype.setContent = function () {
52     var $tip    = this.tip()
53     var title   = this.getTitle()
54     var content = this.getContent()
55
56     $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
57     $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
58
59     $tip.removeClass('fade top bottom left right in')
60
61     $tip.find('.popover-title:empty').hide()
62   }
63
64   Popover.prototype.hasContent = function () {
65     return this.getTitle() || this.getContent()
66   }
67
68   Popover.prototype.getContent = function () {
69     var $e = this.$element
70     var o  = this.options
71
72     return $e.attr('data-content')
73       || (typeof o.content == 'function' ?
74             o.content.call($e[0]) :
75             o.content)
76   }
77
78   Popover.prototype.tip = function () {
79     if (!this.$tip) this.$tip = $(this.options.template)
80     return this.$tip
81   }
82
83   Popover.prototype.destroy = function () {
84     this.hide().$element.off('.' + this.type).removeData(this.type)
85   }
86
87
88   // POPOVER PLUGIN DEFINITION
89   // =========================
90
91   var old = $.fn.popover
92
93   $.fn.popover = function (option) {
94     return this.each(function () {
95       var $this   = $(this)
96       var data    = $this.data('bs.popover')
97       var options = typeof option == 'object' && option
98
99       if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
100       if (typeof option == 'string') data[option]()
101     })
102   }
103
104   $.fn.popover.Constructor = Popover
105
106
107   // POPOVER NO CONFLICT
108   // ===================
109
110   $.fn.popover.noConflict = function () {
111     $.fn.popover = old
112     return this
113   }
114
115 }(window.jQuery);