popover.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* ========================================================================
  2. * Bootstrap: popover.js v3.3.7
  3. * http://getbootstrap.com/javascript/#popovers
  4. * ========================================================================
  5. * Copyright 2011-2016 Twitter, Inc.
  6. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  7. * ======================================================================== */
  8. +function ($) {
  9. 'use strict';
  10. // POPOVER PUBLIC CLASS DEFINITION
  11. // ===============================
  12. var Popover = function (element, options) {
  13. this.init('popover', element, options)
  14. }
  15. if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
  16. Popover.VERSION = '3.3.7'
  17. Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
  18. placement: 'right',
  19. trigger: 'click',
  20. content: '',
  21. template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
  22. })
  23. // NOTE: POPOVER EXTENDS tooltip.js
  24. // ================================
  25. Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
  26. Popover.prototype.constructor = Popover
  27. Popover.prototype.getDefaults = function () {
  28. return Popover.DEFAULTS
  29. }
  30. Popover.prototype.setContent = function () {
  31. var $tip = this.tip()
  32. var title = this.getTitle()
  33. var content = this.getContent()
  34. $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
  35. $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
  36. this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
  37. ](content)
  38. $tip.removeClass('fade top bottom left right in')
  39. // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
  40. // this manually by checking the contents.
  41. if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
  42. }
  43. Popover.prototype.hasContent = function () {
  44. return this.getTitle() || this.getContent()
  45. }
  46. Popover.prototype.getContent = function () {
  47. var $e = this.$element
  48. var o = this.options
  49. return $e.attr('data-content')
  50. || (typeof o.content == 'function' ?
  51. o.content.call($e[0]) :
  52. o.content)
  53. }
  54. Popover.prototype.arrow = function () {
  55. return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
  56. }
  57. // POPOVER PLUGIN DEFINITION
  58. // =========================
  59. function Plugin(option) {
  60. return this.each(function () {
  61. var $this = $(this)
  62. var data = $this.data('bs.popover')
  63. var options = typeof option == 'object' && option
  64. if (!data && /destroy|hide/.test(option)) return
  65. if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
  66. if (typeof option == 'string') data[option]()
  67. })
  68. }
  69. var old = $.fn.popover
  70. $.fn.popover = Plugin
  71. $.fn.popover.Constructor = Popover
  72. // POPOVER NO CONFLICT
  73. // ===================
  74. $.fn.popover.noConflict = function () {
  75. $.fn.popover = old
  76. return this
  77. }
  78. }(jQuery);