JAVASCRIPT   52
bootstrap popover
Guest on 3rd May 2022 02:35:43 AM


  1. /* ===========================================================
  2.  * bootstrap-popover.js v2.3.1
  3.  * http://twitter.github.com/bootstrap/javascript.html#popovers
  4.  * ===========================================================
  5.  * Copyright  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"; // jshint ;_;
  24.  
  25.  
  26.  /* POPOVER PUBLIC CLASS DEFINITION
  27.   * =============================== */
  28.  
  29.   var Popover = function (element, options) {
  30.     this.init('popover', element, options)
  31.   }
  32.  
  33.  
  34.   /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
  35.      ========================================== */
  36.  
  37.   Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  38.  
  39.     constructor: Popover
  40.  
  41.   , setContent: function () {
  42.       var $tip = this.tip()
  43.         , title = this.getTitle()
  44.         , content = this.getContent()
  45.  
  46.       $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
  47.       $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
  48.  
  49.       $tip.removeClass('fade top bottom left right in')
  50.     }
  51.  
  52.   , hasContent: function () {
  53.       return this.getTitle() || this.getContent()
  54.     }
  55.  
  56.   , getContent: function () {
  57.       var content
  58.         , $e = this.$element
  59.         , o = this.options
  60.  
  61.       content = (typeof o.content == 'function' ? o.content.call($e[0]) :  o.content)
  62.         || $e.attr('data-content')
  63.  
  64.       return content
  65.     }
  66.  
  67.   , tip: function () {
  68.       if (!this.$tip) {
  69.         this.$tip = $(this.options.template)
  70.       }
  71.       return this.$tip
  72.     }
  73.  
  74.   , destroy: function () {
  75.       this.hide().$element.off('.' + this.type).removeData(this.type)
  76.     }
  77.  
  78.   })
  79.  
  80.  
  81.  /* POPOVER PLUGIN DEFINITION
  82.   * ======================= */
  83.  
  84.   var old = $.fn.popover
  85.  
  86.   $.fn.popover = function (option) {
  87.     return this.each(function () {
  88.       var $this = $(this)
  89.         , data = $this.data('popover')
  90.         , options = typeof option == 'object' && option
  91.       if (!data) $this.data('popover', (data = new Popover(this, options)))
  92.       if (typeof option == 'string') data[option]()
  93.     })
  94.   }
  95.  
  96.   $.fn.popover.Constructor = Popover
  97.  
  98.   $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
  99.     placement: 'right'
  100.   , trigger: 'click'
  101.   , content: ''
  102.   , template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
  103.   })
  104.  
  105.  
  106.  /* POPOVER NO CONFLICT
  107.   * =================== */
  108.  
  109.   $.fn.popover.noConflict = function () {
  110.     $.fn.popover = old
  111.     return this
  112.   }
  113.  
  114. }(window.jQuery);

Raw Paste

Login or Register to edit or fork this paste. It's free.