talos

Форк
0
172 строки · 3.7 Кб
1
/**
2
 * --------------------------------------------------------------------------
3
 * Bootstrap (v4.6.1): popover.js
4
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
 * --------------------------------------------------------------------------
6
 */
7

8
import $ from 'jquery'
9
import Tooltip from './tooltip'
10

11
/**
12
 * Constants
13
 */
14

15
const NAME = 'popover'
16
const VERSION = '4.6.1'
17
const DATA_KEY = 'bs.popover'
18
const EVENT_KEY = `.${DATA_KEY}`
19
const JQUERY_NO_CONFLICT = $.fn[NAME]
20
const CLASS_PREFIX = 'bs-popover'
21
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
22

23
const CLASS_NAME_FADE = 'fade'
24
const CLASS_NAME_SHOW = 'show'
25

26
const SELECTOR_TITLE = '.popover-header'
27
const SELECTOR_CONTENT = '.popover-body'
28

29
const Default = {
30
  ...Tooltip.Default,
31
  placement: 'right',
32
  trigger: 'click',
33
  content: '',
34
  template: '<div class="popover" role="tooltip">' +
35
              '<div class="arrow"></div>' +
36
              '<h3 class="popover-header"></h3>' +
37
              '<div class="popover-body"></div></div>'
38
}
39

40
const DefaultType = {
41
  ...Tooltip.DefaultType,
42
  content: '(string|element|function)'
43
}
44

45
const Event = {
46
  HIDE: `hide${EVENT_KEY}`,
47
  HIDDEN: `hidden${EVENT_KEY}`,
48
  SHOW: `show${EVENT_KEY}`,
49
  SHOWN: `shown${EVENT_KEY}`,
50
  INSERTED: `inserted${EVENT_KEY}`,
51
  CLICK: `click${EVENT_KEY}`,
52
  FOCUSIN: `focusin${EVENT_KEY}`,
53
  FOCUSOUT: `focusout${EVENT_KEY}`,
54
  MOUSEENTER: `mouseenter${EVENT_KEY}`,
55
  MOUSELEAVE: `mouseleave${EVENT_KEY}`
56
}
57

58
/**
59
 * Class definition
60
 */
61

62
class Popover extends Tooltip {
63
  // Getters
64
  static get VERSION() {
65
    return VERSION
66
  }
67

68
  static get Default() {
69
    return Default
70
  }
71

72
  static get NAME() {
73
    return NAME
74
  }
75

76
  static get DATA_KEY() {
77
    return DATA_KEY
78
  }
79

80
  static get Event() {
81
    return Event
82
  }
83

84
  static get EVENT_KEY() {
85
    return EVENT_KEY
86
  }
87

88
  static get DefaultType() {
89
    return DefaultType
90
  }
91

92
  // Overrides
93
  isWithContent() {
94
    return this.getTitle() || this._getContent()
95
  }
96

97
  addAttachmentClass(attachment) {
98
    $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
99
  }
100

101
  getTipElement() {
102
    this.tip = this.tip || $(this.config.template)[0]
103
    return this.tip
104
  }
105

106
  setContent() {
107
    const $tip = $(this.getTipElement())
108

109
    // We use append for html objects to maintain js events
110
    this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle())
111
    let content = this._getContent()
112
    if (typeof content === 'function') {
113
      content = content.call(this.element)
114
    }
115

116
    this.setElementContent($tip.find(SELECTOR_CONTENT), content)
117

118
    $tip.removeClass(`${CLASS_NAME_FADE} ${CLASS_NAME_SHOW}`)
119
  }
120

121
  // Private
122
  _getContent() {
123
    return this.element.getAttribute('data-content') ||
124
      this.config.content
125
  }
126

127
  _cleanTipClass() {
128
    const $tip = $(this.getTipElement())
129
    const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
130
    if (tabClass !== null && tabClass.length > 0) {
131
      $tip.removeClass(tabClass.join(''))
132
    }
133
  }
134

135
  // Static
136
  static _jQueryInterface(config) {
137
    return this.each(function () {
138
      let data = $(this).data(DATA_KEY)
139
      const _config = typeof config === 'object' ? config : null
140

141
      if (!data && /dispose|hide/.test(config)) {
142
        return
143
      }
144

145
      if (!data) {
146
        data = new Popover(this, _config)
147
        $(this).data(DATA_KEY, data)
148
      }
149

150
      if (typeof config === 'string') {
151
        if (typeof data[config] === 'undefined') {
152
          throw new TypeError(`No method named "${config}"`)
153
        }
154

155
        data[config]()
156
      }
157
    })
158
  }
159
}
160

161
/**
162
 * jQuery
163
 */
164

165
$.fn[NAME] = Popover._jQueryInterface
166
$.fn[NAME].Constructor = Popover
167
$.fn[NAME].noConflict = () => {
168
  $.fn[NAME] = JQUERY_NO_CONFLICT
169
  return Popover._jQueryInterface
170
}
171

172
export default Popover
173

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.