Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

popover.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * --------------------------------------------------------------------------
  3. * Bootstrap (v4.3.1): popover.js
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  5. * --------------------------------------------------------------------------
  6. */
  7. import $ from 'jquery'
  8. import Tooltip from './tooltip'
  9. /**
  10. * ------------------------------------------------------------------------
  11. * Constants
  12. * ------------------------------------------------------------------------
  13. */
  14. const NAME = 'popover'
  15. const VERSION = '4.3.1'
  16. const DATA_KEY = 'bs.popover'
  17. const EVENT_KEY = `.${DATA_KEY}`
  18. const JQUERY_NO_CONFLICT = $.fn[NAME]
  19. const CLASS_PREFIX = 'bs-popover'
  20. const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
  21. const Default = {
  22. ...Tooltip.Default,
  23. placement : 'right',
  24. trigger : 'click',
  25. content : '',
  26. template : '<div class="popover" role="tooltip">' +
  27. '<div class="arrow"></div>' +
  28. '<h3 class="popover-header"></h3>' +
  29. '<div class="popover-body"></div></div>'
  30. }
  31. const DefaultType = {
  32. ...Tooltip.DefaultType,
  33. content : '(string|element|function)'
  34. }
  35. const ClassName = {
  36. FADE : 'fade',
  37. SHOW : 'show'
  38. }
  39. const Selector = {
  40. TITLE : '.popover-header',
  41. CONTENT : '.popover-body'
  42. }
  43. const Event = {
  44. HIDE : `hide${EVENT_KEY}`,
  45. HIDDEN : `hidden${EVENT_KEY}`,
  46. SHOW : `show${EVENT_KEY}`,
  47. SHOWN : `shown${EVENT_KEY}`,
  48. INSERTED : `inserted${EVENT_KEY}`,
  49. CLICK : `click${EVENT_KEY}`,
  50. FOCUSIN : `focusin${EVENT_KEY}`,
  51. FOCUSOUT : `focusout${EVENT_KEY}`,
  52. MOUSEENTER : `mouseenter${EVENT_KEY}`,
  53. MOUSELEAVE : `mouseleave${EVENT_KEY}`
  54. }
  55. /**
  56. * ------------------------------------------------------------------------
  57. * Class Definition
  58. * ------------------------------------------------------------------------
  59. */
  60. class Popover extends Tooltip {
  61. // Getters
  62. static get VERSION() {
  63. return VERSION
  64. }
  65. static get Default() {
  66. return Default
  67. }
  68. static get NAME() {
  69. return NAME
  70. }
  71. static get DATA_KEY() {
  72. return DATA_KEY
  73. }
  74. static get Event() {
  75. return Event
  76. }
  77. static get EVENT_KEY() {
  78. return EVENT_KEY
  79. }
  80. static get DefaultType() {
  81. return DefaultType
  82. }
  83. // Overrides
  84. isWithContent() {
  85. return this.getTitle() || this._getContent()
  86. }
  87. addAttachmentClass(attachment) {
  88. $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
  89. }
  90. getTipElement() {
  91. this.tip = this.tip || $(this.config.template)[0]
  92. return this.tip
  93. }
  94. setContent() {
  95. const $tip = $(this.getTipElement())
  96. // We use append for html objects to maintain js events
  97. this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
  98. let content = this._getContent()
  99. if (typeof content === 'function') {
  100. content = content.call(this.element)
  101. }
  102. this.setElementContent($tip.find(Selector.CONTENT), content)
  103. $tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
  104. }
  105. // Private
  106. _getContent() {
  107. return this.element.getAttribute('data-content') ||
  108. this.config.content
  109. }
  110. _cleanTipClass() {
  111. const $tip = $(this.getTipElement())
  112. const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
  113. if (tabClass !== null && tabClass.length > 0) {
  114. $tip.removeClass(tabClass.join(''))
  115. }
  116. }
  117. // Static
  118. static _jQueryInterface(config) {
  119. return this.each(function () {
  120. let data = $(this).data(DATA_KEY)
  121. const _config = typeof config === 'object' ? config : null
  122. if (!data && /dispose|hide/.test(config)) {
  123. return
  124. }
  125. if (!data) {
  126. data = new Popover(this, _config)
  127. $(this).data(DATA_KEY, data)
  128. }
  129. if (typeof config === 'string') {
  130. if (typeof data[config] === 'undefined') {
  131. throw new TypeError(`No method named "${config}"`)
  132. }
  133. data[config]()
  134. }
  135. })
  136. }
  137. }
  138. /**
  139. * ------------------------------------------------------------------------
  140. * jQuery
  141. * ------------------------------------------------------------------------
  142. */
  143. $.fn[NAME] = Popover._jQueryInterface
  144. $.fn[NAME].Constructor = Popover
  145. $.fn[NAME].noConflict = () => {
  146. $.fn[NAME] = JQUERY_NO_CONFLICT
  147. return Popover._jQueryInterface
  148. }
  149. export default Popover