bootstrap-popover.js 2.62 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
/* ===========================================================
2
 * bootstrap-popover.js v2.0.0
Jacob Thornton's avatar
Jacob Thornton committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * http://twitter.github.com/bootstrap/javascript.html#popover
 * ===========================================================
 * Copyright 2011 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.
 * =========================================================== */
Jacob Thornton's avatar
Jacob Thornton committed
19
20


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

23
24
 "use strict"

Jacob Thornton's avatar
Jacob Thornton committed
25
26
27
28
  var Popover = function ( element, options ) {
    this.$element = $(element)
    this.options = options
    this.enabled = true
29
    this.fixTitle()
Jacob Thornton's avatar
Jacob Thornton committed
30
31
  }

Jacob Thornton's avatar
Jacob Thornton committed
32
33
34
  /* NOTE: POPOVER EXTENDS BOOTSTRAP-TWIPSY.js
     ========================================= */

Jacob Thornton's avatar
Jacob Thornton committed
35
36
37
38
  Popover.prototype = $.extend({}, $.fn.twipsy.Twipsy.prototype, {

    setContent: function () {
      var $tip = this.tip()
39
40
      $tip.find('.title')['html'](this.getTitle())
      $tip.find('.content > *')['html'](this.getContent())
Jacob Thornton's avatar
Jacob Thornton committed
41
42
43
      $tip[0].className = 'popover'
    }

44
45
46
47
  , hasContent: function () {
      return this.getTitle() || this.getContent()
    }

48
  , getContent: function () {
49
      var content
50
51
       , $e = this.$element
       , o = this.options
Jacob Thornton's avatar
Jacob Thornton committed
52
53

      if (typeof this.options.content == 'string') {
54
        content = $e.attr(this.options.content)
Jacob Thornton's avatar
Jacob Thornton committed
55
56
57
      } else if (typeof this.options.content == 'function') {
        content = this.options.content.call(this.$element[0])
      }
58

Jacob Thornton's avatar
Jacob Thornton committed
59
60
61
62
63
64
      return content
    }

  , tip: function() {
      if (!this.$tip) {
        this.$tip = $('<div class="popover" />')
65
          .html(this.options.template)
Jacob Thornton's avatar
Jacob Thornton committed
66
67
68
69
70
71
      }
      return this.$tip
    }

  })

72

Jacob Thornton's avatar
Jacob Thornton committed
73
74
75
76
77
 /* POPOVER PLUGIN DEFINITION
  * ======================= */

  $.fn.popover = function (options) {
    if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options)
78
    $.fn.twipsy.initWith.call(this, options, Popover, 'popover')
Jacob Thornton's avatar
Jacob Thornton committed
79
    return this
Jacob Thornton's avatar
Jacob Thornton committed
80
81
  }

82
83
84
85
86
87
88
  $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, {
    placement: 'right'
  , content: 'data-content'
  , template: '<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>'
  })

  $.fn.twipsy.rejectAttrOptions.push( 'content' )
Jacob Thornton's avatar
Jacob Thornton committed
89

90
}( window.jQuery || window.ender );