mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 16:14:04 +02:00
Use Popper for tooltip and popover
This commit is contained in:
3
docs/assets/js/vendor/popper.min.js
vendored
Normal file
3
docs/assets/js/vendor/popper.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
docs/assets/js/vendor/tether.min.js
vendored
1
docs/assets/js/vendor/tether.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -118,8 +118,6 @@ const Popover = (($) => {
|
|||||||
this.setElementContent($tip.find(Selector.CONTENT), this._getContent())
|
this.setElementContent($tip.find(Selector.CONTENT), this._getContent())
|
||||||
|
|
||||||
$tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
|
$tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
|
||||||
|
|
||||||
this.cleanupTether()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* global Tether */
|
/* global Popper */
|
||||||
|
|
||||||
import Util from './util'
|
import Util from './util'
|
||||||
|
|
||||||
@@ -13,11 +13,11 @@ import Util from './util'
|
|||||||
const Tooltip = (($) => {
|
const Tooltip = (($) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for Tether dependency
|
* Check for Popper dependency
|
||||||
* Tether - http://tether.io/
|
* Tether - https://popper.js.org
|
||||||
*/
|
*/
|
||||||
if (typeof Tether === 'undefined') {
|
if (typeof Popper === 'undefined') {
|
||||||
throw new Error('Bootstrap tooltips require Tether (http://tether.io/)')
|
throw new Error('Bootstrap tooltips require Popper (https://popper.js.org)')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -33,8 +33,6 @@ const Tooltip = (($) => {
|
|||||||
const EVENT_KEY = `.${DATA_KEY}`
|
const EVENT_KEY = `.${DATA_KEY}`
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
const TRANSITION_DURATION = 150
|
const TRANSITION_DURATION = 150
|
||||||
const CLASS_PREFIX = 'bs-tether'
|
|
||||||
const TETHER_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
|
|
||||||
|
|
||||||
const Default = {
|
const Default = {
|
||||||
animation : true,
|
animation : true,
|
||||||
@@ -66,10 +64,10 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AttachmentMap = {
|
const AttachmentMap = {
|
||||||
TOP : 'bottom center',
|
TOP : 'top',
|
||||||
RIGHT : 'middle left',
|
RIGHT : 'right',
|
||||||
BOTTOM : 'top center',
|
BOTTOM : 'bottom',
|
||||||
LEFT : 'middle right'
|
LEFT : 'left'
|
||||||
}
|
}
|
||||||
|
|
||||||
const HoverState = {
|
const HoverState = {
|
||||||
@@ -100,11 +98,6 @@ const Tooltip = (($) => {
|
|||||||
TOOLTIP_INNER : '.tooltip-inner'
|
TOOLTIP_INNER : '.tooltip-inner'
|
||||||
}
|
}
|
||||||
|
|
||||||
const TetherClass = {
|
|
||||||
element : false,
|
|
||||||
enabled : false
|
|
||||||
}
|
|
||||||
|
|
||||||
const Trigger = {
|
const Trigger = {
|
||||||
HOVER : 'hover',
|
HOVER : 'hover',
|
||||||
FOCUS : 'focus',
|
FOCUS : 'focus',
|
||||||
@@ -128,7 +121,7 @@ const Tooltip = (($) => {
|
|||||||
this._timeout = 0
|
this._timeout = 0
|
||||||
this._hoverState = ''
|
this._hoverState = ''
|
||||||
this._activeTrigger = {}
|
this._activeTrigger = {}
|
||||||
this._tether = null
|
this._popper = null
|
||||||
|
|
||||||
// protected
|
// protected
|
||||||
this.element = element
|
this.element = element
|
||||||
@@ -220,8 +213,6 @@ const Tooltip = (($) => {
|
|||||||
dispose() {
|
dispose() {
|
||||||
clearTimeout(this._timeout)
|
clearTimeout(this._timeout)
|
||||||
|
|
||||||
this.cleanupTether()
|
|
||||||
|
|
||||||
$.removeData(this.element, this.constructor.DATA_KEY)
|
$.removeData(this.element, this.constructor.DATA_KEY)
|
||||||
|
|
||||||
$(this.element).off(this.constructor.EVENT_KEY)
|
$(this.element).off(this.constructor.EVENT_KEY)
|
||||||
@@ -235,7 +226,7 @@ const Tooltip = (($) => {
|
|||||||
this._timeout = null
|
this._timeout = null
|
||||||
this._hoverState = null
|
this._hoverState = null
|
||||||
this._activeTrigger = null
|
this._activeTrigger = null
|
||||||
this._tether = null
|
this._popper = null
|
||||||
|
|
||||||
this.element = null
|
this.element = null
|
||||||
this.config = null
|
this.config = null
|
||||||
@@ -288,19 +279,19 @@ const Tooltip = (($) => {
|
|||||||
|
|
||||||
$(this.element).trigger(this.constructor.Event.INSERTED)
|
$(this.element).trigger(this.constructor.Event.INSERTED)
|
||||||
|
|
||||||
this._tether = new Tether({
|
this._popper = new Popper(this.element, tip, {
|
||||||
attachment,
|
placement : attachment,
|
||||||
element : tip,
|
modifiers : {
|
||||||
target : this.element,
|
arrow : {
|
||||||
classes : TetherClass,
|
element : Selector.TOOLTIP
|
||||||
classPrefix : CLASS_PREFIX,
|
},
|
||||||
offset : this.config.offset,
|
offset : {
|
||||||
constraints : this.config.constraints,
|
offset : this.config.offset
|
||||||
addTargetClasses: false
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Util.reflow(tip)
|
Util.reflow(tip)
|
||||||
this._tether.position()
|
|
||||||
|
|
||||||
$(tip).addClass(ClassName.SHOW)
|
$(tip).addClass(ClassName.SHOW)
|
||||||
|
|
||||||
@@ -342,11 +333,9 @@ const Tooltip = (($) => {
|
|||||||
tip.parentNode.removeChild(tip)
|
tip.parentNode.removeChild(tip)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._cleanTipClass()
|
|
||||||
this.element.removeAttribute('aria-describedby')
|
this.element.removeAttribute('aria-describedby')
|
||||||
$(this.element).trigger(this.constructor.Event.HIDDEN)
|
$(this.element).trigger(this.constructor.Event.HIDDEN)
|
||||||
this.cleanupTether()
|
this._popper.destroy()
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
@@ -398,12 +387,8 @@ const Tooltip = (($) => {
|
|||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
const $tip = $(this.getTipElement())
|
const $tip = $(this.getTipElement())
|
||||||
|
|
||||||
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
|
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
|
||||||
|
|
||||||
$tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
|
$tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
|
||||||
|
|
||||||
this.cleanupTether()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setElementContent($element, content) {
|
setElementContent($element, content) {
|
||||||
@@ -434,12 +419,6 @@ const Tooltip = (($) => {
|
|||||||
return title
|
return title
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanupTether() {
|
|
||||||
if (this._tether) {
|
|
||||||
this._tether.destroy()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
|
||||||
@@ -447,14 +426,6 @@ const Tooltip = (($) => {
|
|||||||
return AttachmentMap[placement.toUpperCase()]
|
return AttachmentMap[placement.toUpperCase()]
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanTipClass() {
|
|
||||||
const $tip = $(this.getTipElement())
|
|
||||||
const tabClass = $tip.attr('class').match(TETHER_PREFIX_REGEX)
|
|
||||||
if (tabClass !== null && tabClass.length > 0) {
|
|
||||||
$tip.removeClass(tabClass.join(''))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_setListeners() {
|
_setListeners() {
|
||||||
const triggers = this.config.trigger.split(' ')
|
const triggers = this.config.trigger.split(' ')
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
|
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
|
||||||
<script src="../../../docs/assets/js/vendor/tether.min.js"></script>
|
<script src="../../../docs/assets/js/vendor/popper.min.js"></script>
|
||||||
<script src="../../dist/util.js"></script>
|
<script src="../../dist/util.js"></script>
|
||||||
<script src="../../dist/tooltip.js"></script>
|
<script src="../../dist/tooltip.js"></script>
|
||||||
<script src="../../dist/popover.js"></script>
|
<script src="../../dist/popover.js"></script>
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
|
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
|
||||||
<script src="../../../docs/assets/js/vendor/tether.min.js"></script>
|
<script src="../../../docs/assets/js/vendor/popper.min.js"></script>
|
||||||
<script src="../../dist/util.js"></script>
|
<script src="../../dist/util.js"></script>
|
||||||
<script src="../../dist/tooltip.js"></script>
|
<script src="../../dist/tooltip.js"></script>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user