mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 16:44:17 +02:00
Add attachment classes
This commit is contained in:
@@ -22,6 +22,8 @@ const Popover = (($) => {
|
|||||||
const DATA_KEY = 'bs.popover'
|
const DATA_KEY = 'bs.popover'
|
||||||
const EVENT_KEY = `.${DATA_KEY}`
|
const EVENT_KEY = `.${DATA_KEY}`
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
|
const CLASS_PREFIX = 'bs-popover'
|
||||||
|
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
|
||||||
|
|
||||||
const Default = $.extend({}, Tooltip.Default, {
|
const Default = $.extend({}, Tooltip.Default, {
|
||||||
placement : 'right',
|
placement : 'right',
|
||||||
@@ -107,6 +109,10 @@ const Popover = (($) => {
|
|||||||
return this.getTitle() || this._getContent()
|
return this.getTitle() || this._getContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAttachmentClass(attachment) {
|
||||||
|
$(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
|
||||||
|
}
|
||||||
|
|
||||||
getTipElement() {
|
getTipElement() {
|
||||||
return this.tip = this.tip || $(this.config.template)[0]
|
return this.tip = this.tip || $(this.config.template)[0]
|
||||||
}
|
}
|
||||||
@@ -130,6 +136,14 @@ const Popover = (($) => {
|
|||||||
this.config.content)
|
this.config.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cleanTipClass() {
|
||||||
|
const $tip = $(this.getTipElement())
|
||||||
|
const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
|
||||||
|
if (tabClass !== null && tabClass.length > 0) {
|
||||||
|
$tip.removeClass(tabClass.join(''))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
|
@@ -33,6 +33,8 @@ 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-tooltip'
|
||||||
|
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
|
||||||
|
|
||||||
const Default = {
|
const Default = {
|
||||||
animation : true,
|
animation : true,
|
||||||
@@ -269,6 +271,7 @@ const Tooltip = (($) => {
|
|||||||
this.config.placement
|
this.config.placement
|
||||||
|
|
||||||
const attachment = this._getAttachment(placement)
|
const attachment = this._getAttachment(placement)
|
||||||
|
this.addAttachmentClass(attachment)
|
||||||
|
|
||||||
const container = this.config.container === false ? document.body : $(this.config.container)
|
const container = this.config.container === false ? document.body : $(this.config.container)
|
||||||
|
|
||||||
@@ -332,6 +335,7 @@ 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)
|
||||||
if (this._popper !== null) {
|
if (this._popper !== null) {
|
||||||
@@ -383,6 +387,10 @@ const Tooltip = (($) => {
|
|||||||
return Boolean(this.getTitle())
|
return Boolean(this.getTitle())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAttachmentClass(attachment) {
|
||||||
|
$(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
|
||||||
|
}
|
||||||
|
|
||||||
getTipElement() {
|
getTipElement() {
|
||||||
return this.tip = this.tip || $(this.config.template)[0]
|
return this.tip = this.tip || $(this.config.template)[0]
|
||||||
}
|
}
|
||||||
@@ -624,6 +632,14 @@ const Tooltip = (($) => {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cleanTipClass() {
|
||||||
|
const $tip = $(this.getTipElement())
|
||||||
|
const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
|
||||||
|
if (tabClass !== null && tabClass.length > 0) {
|
||||||
|
$tip.removeClass(tabClass.join(''))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<!-- jQuery -->
|
<!-- jQuery -->
|
||||||
<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>
|
||||||
|
|
||||||
<!-- QUnit -->
|
<!-- QUnit -->
|
||||||
<link rel="stylesheet" href="vendor/qunit.css" media="screen">
|
<link rel="stylesheet" href="vendor/qunit.css" media="screen">
|
||||||
|
@@ -111,7 +111,7 @@ $(function () {
|
|||||||
|
|
||||||
assert
|
assert
|
||||||
.ok($('.tooltip')
|
.ok($('.tooltip')
|
||||||
.is('.fade.bs-tether-element-attached-top.bs-tether-element-attached-center.show'), 'has correct classes applied')
|
.is('.fade.bs-tooltip-bottom.show'), 'has correct classes applied')
|
||||||
|
|
||||||
$tooltip.bootstrapTooltip('hide')
|
$tooltip.bootstrapTooltip('hide')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user