bootstrap-source/bootstrap-3.0.3/js/popover.js
author Reimar Bauer <rb.proj AT googlemail DOT com>
Fri, 17 Jan 2014 11:59:43 +0100
branchlanding-page-2014
changeset 78 b28d5c14c5c2
parent 54 0ded9d7748b7
permissions -rwxr-xr-x
merged heads
     1 /* ========================================================================
     2  * Bootstrap: popover.js v3.0.3
     3  * http://getbootstrap.com/javascript/#popovers
     4  * ========================================================================
     5  * Copyright 2013 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     // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
    62     // this manually by checking the contents.
    63     if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
    64   }
    65 
    66   Popover.prototype.hasContent = function () {
    67     return this.getTitle() || this.getContent()
    68   }
    69 
    70   Popover.prototype.getContent = function () {
    71     var $e = this.$element
    72     var o  = this.options
    73 
    74     return $e.attr('data-content')
    75       || (typeof o.content == 'function' ?
    76             o.content.call($e[0]) :
    77             o.content)
    78   }
    79 
    80   Popover.prototype.arrow = function () {
    81     return this.$arrow = this.$arrow || this.tip().find('.arrow')
    82   }
    83 
    84   Popover.prototype.tip = function () {
    85     if (!this.$tip) this.$tip = $(this.options.template)
    86     return this.$tip
    87   }
    88 
    89 
    90   // POPOVER PLUGIN DEFINITION
    91   // =========================
    92 
    93   var old = $.fn.popover
    94 
    95   $.fn.popover = function (option) {
    96     return this.each(function () {
    97       var $this   = $(this)
    98       var data    = $this.data('bs.popover')
    99       var options = typeof option == 'object' && option
   100 
   101       if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
   102       if (typeof option == 'string') data[option]()
   103     })
   104   }
   105 
   106   $.fn.popover.Constructor = Popover
   107 
   108 
   109   // POPOVER NO CONFLICT
   110   // ===================
   111 
   112   $.fn.popover.noConflict = function () {
   113     $.fn.popover = old
   114     return this
   115   }
   116 
   117 }(jQuery);
Impressum Datenschutzerklärung