Bez popisu

popover.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* ========================================================================
  2. * Bootstrap: popover.js v3.4.1
  3. * https://getbootstrap.com/docs/3.4/javascript/#popovers
  4. * ========================================================================
  5. * Copyright 2011-2019 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.4.1'
  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. if (this.options.html) {
  35. var typeContent = typeof content
  36. if (this.options.sanitize) {
  37. title = this.sanitizeHtml(title)
  38. if (typeContent === 'string') {
  39. content = this.sanitizeHtml(content)
  40. }
  41. }
  42. $tip.find('.popover-title').html(title)
  43. $tip.find('.popover-content').children().detach().end()[
  44. typeContent === 'string' ? 'html' : 'append'
  45. ](content)
  46. } else {
  47. $tip.find('.popover-title').text(title)
  48. $tip.find('.popover-content').children().detach().end().text(content)
  49. }
  50. $tip.removeClass('fade top bottom left right in')
  51. // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
  52. // this manually by checking the contents.
  53. if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
  54. }
  55. Popover.prototype.hasContent = function () {
  56. return this.getTitle() || this.getContent()
  57. }
  58. Popover.prototype.getContent = function () {
  59. var $e = this.$element
  60. var o = this.options
  61. return $e.attr('data-content')
  62. || (typeof o.content == 'function' ?
  63. o.content.call($e[0]) :
  64. o.content)
  65. }
  66. Popover.prototype.arrow = function () {
  67. return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
  68. }
  69. // POPOVER PLUGIN DEFINITION
  70. // =========================
  71. function Plugin(option) {
  72. return this.each(function () {
  73. var $this = $(this)
  74. var data = $this.data('bs.popover')
  75. var options = typeof option == 'object' && option
  76. if (!data && /destroy|hide/.test(option)) return
  77. if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
  78. if (typeof option == 'string') data[option]()
  79. })
  80. }
  81. var old = $.fn.popover
  82. $.fn.popover = Plugin
  83. $.fn.popover.Constructor = Popover
  84. // POPOVER NO CONFLICT
  85. // ===================
  86. $.fn.popover.noConflict = function () {
  87. $.fn.popover = old
  88. return this
  89. }
  90. }(jQuery);