/src/honeynet_web/honeywall/static/twitter-bootstrap/docs/assets/js/bootstrap-popover.js
JavaScript | 95 lines | 50 code | 23 blank | 22 comment | 11 complexity | c768a4aa3248f3af9fe33d8b2960485f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
1/* ===========================================================
2 * bootstrap-popover.js v2.0.0
3 * http://twitter.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( $ ) {
22
23 "use strict"
24
25 var Popover = function ( element, options ) {
26 this.init('popover', element, options)
27 }
28
29 /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
30 ========================================== */
31
32 Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
33
34 constructor: Popover
35
36 , setContent: function () {
37 var $tip = this.tip()
38 , title = this.getTitle()
39 , content = this.getContent()
40
41 $tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)
42 $tip.find('.popover-content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content)
43
44 $tip.removeClass('fade top bottom left right in')
45 }
46
47 , hasContent: function () {
48 return this.getTitle() || this.getContent()
49 }
50
51 , getContent: function () {
52 var content
53 , $e = this.$element
54 , o = this.options
55
56 content = $e.attr('data-content')
57 || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
58
59 content = content.toString().replace(/(^\s*|\s*$)/, "")
60
61 return content
62 }
63
64 , tip: function() {
65 if (!this.$tip) {
66 this.$tip = $(this.options.template)
67 }
68 return this.$tip
69 }
70
71 })
72
73
74 /* POPOVER PLUGIN DEFINITION
75 * ======================= */
76
77 $.fn.popover = function ( option ) {
78 return this.each(function () {
79 var $this = $(this)
80 , data = $this.data('popover')
81 , options = typeof option == 'object' && option
82 if (!data) $this.data('popover', (data = new Popover(this, options)))
83 if (typeof option == 'string') data[option]()
84 })
85 }
86
87 $.fn.popover.Constructor = Popover
88
89 $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
90 placement: 'right'
91 , content: ''
92 , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
93 })
94
95}( window.jQuery )