Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * --------------------------------------------------------------------------
1441 ariadna 3
 * Bootstrap popover.js
1 efrain 4
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
 * --------------------------------------------------------------------------
6
 */
7
 
8
import Tooltip from './tooltip'
1441 ariadna 9
import { defineJQueryPlugin } from './util/index'
1 efrain 10
 
11
/**
12
 * Constants
13
 */
14
 
15
const NAME = 'popover'
16
 
17
const SELECTOR_TITLE = '.popover-header'
18
const SELECTOR_CONTENT = '.popover-body'
19
 
20
const Default = {
21
  ...Tooltip.Default,
1441 ariadna 22
  content: '',
23
  offset: [0, 8],
1 efrain 24
  placement: 'right',
25
  template: '<div class="popover" role="tooltip">' +
1441 ariadna 26
    '<div class="popover-arrow"></div>' +
27
    '<h3 class="popover-header"></h3>' +
28
    '<div class="popover-body"></div>' +
29
    '</div>',
30
  trigger: 'click'
1 efrain 31
}
32
 
33
const DefaultType = {
34
  ...Tooltip.DefaultType,
1441 ariadna 35
  content: '(null|string|element|function)'
1 efrain 36
}
37
 
38
/**
39
 * Class definition
40
 */
41
 
42
class Popover extends Tooltip {
43
  // Getters
44
  static get Default() {
45
    return Default
46
  }
47
 
48
  static get DefaultType() {
49
    return DefaultType
50
  }
51
 
1441 ariadna 52
  static get NAME() {
53
    return NAME
1 efrain 54
  }
55
 
1441 ariadna 56
  // Overrides
57
  _isWithContent() {
58
    return this._getTitle() || this._getContent()
1 efrain 59
  }
60
 
1441 ariadna 61
  // Private
62
  _getContentForTemplate() {
63
    return {
64
      [SELECTOR_TITLE]: this._getTitle(),
65
      [SELECTOR_CONTENT]: this._getContent()
1 efrain 66
    }
67
  }
68
 
69
  _getContent() {
1441 ariadna 70
    return this._resolvePossibleFunction(this._config.content)
1 efrain 71
  }
72
 
73
  // Static
1441 ariadna 74
  static jQueryInterface(config) {
1 efrain 75
    return this.each(function () {
1441 ariadna 76
      const data = Popover.getOrCreateInstance(this, config)
1 efrain 77
 
1441 ariadna 78
      if (typeof config !== 'string') {
1 efrain 79
        return
80
      }
81
 
1441 ariadna 82
      if (typeof data[config] === 'undefined') {
83
        throw new TypeError(`No method named "${config}"`)
1 efrain 84
      }
85
 
1441 ariadna 86
      data[config]()
1 efrain 87
    })
88
  }
89
}
90
 
91
/**
92
 * jQuery
93
 */
94
 
1441 ariadna 95
defineJQueryPlugin(Popover)
1 efrain 96
 
97
export default Popover