mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-17 09:52:29 +01:00
fix regression about using element for tooltip container option
This commit is contained in:
parent
1a171b80ab
commit
37f74c7070
@ -272,8 +272,7 @@ class Tooltip {
|
||||
const attachment = this._getAttachment(placement)
|
||||
this.addAttachmentClass(attachment)
|
||||
|
||||
const container = this.config.container === false ? document.body : $(document).find(this.config.container)
|
||||
|
||||
const container = this._getContainer()
|
||||
$(tip).data(this.constructor.DATA_KEY, this)
|
||||
|
||||
if (!$.contains(this.element.ownerDocument.documentElement, this.tip)) {
|
||||
@ -450,6 +449,18 @@ class Tooltip {
|
||||
|
||||
// Private
|
||||
|
||||
_getContainer() {
|
||||
if (this.config.container === false) {
|
||||
return document.body
|
||||
}
|
||||
|
||||
if (Util.isElement(this.config.container)) {
|
||||
return $(this.config.container)
|
||||
}
|
||||
|
||||
return $(document).find(this.config.container)
|
||||
}
|
||||
|
||||
_getAttachment(placement) {
|
||||
return AttachmentMap[placement.toUpperCase()]
|
||||
}
|
||||
|
@ -414,6 +414,52 @@ $(function () {
|
||||
.bootstrapTooltip('show')
|
||||
})
|
||||
|
||||
QUnit.test('should place tooltips inside a specific container when container is an element', function (assert) {
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
var $container = $('<div></div>').appendTo('#qunit-fixture')
|
||||
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
||||
.appendTo('#qunit-fixture')
|
||||
.bootstrapTooltip({
|
||||
container: $container[0]
|
||||
})
|
||||
|
||||
$tooltip
|
||||
.one('shown.bs.tooltip', function () {
|
||||
assert.strictEqual($container.find('.tooltip').length, 1)
|
||||
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
|
||||
$tooltip.bootstrapTooltip('hide')
|
||||
})
|
||||
.one('hidden.bs.tooltip', function () {
|
||||
assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom')
|
||||
done()
|
||||
})
|
||||
.bootstrapTooltip('show')
|
||||
})
|
||||
|
||||
QUnit.test('should place tooltips inside a specific container when container is a selector', function (assert) {
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
var $container = $('<div id="container"></div>').appendTo('#qunit-fixture')
|
||||
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
||||
.appendTo('#qunit-fixture')
|
||||
.bootstrapTooltip({
|
||||
container: '#container'
|
||||
})
|
||||
|
||||
$tooltip
|
||||
.one('shown.bs.tooltip', function () {
|
||||
assert.strictEqual($container.find('.tooltip').length, 1)
|
||||
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
|
||||
$tooltip.bootstrapTooltip('hide')
|
||||
})
|
||||
.one('hidden.bs.tooltip', function () {
|
||||
assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom')
|
||||
done()
|
||||
})
|
||||
.bootstrapTooltip('show')
|
||||
})
|
||||
|
||||
QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
|
||||
assert.expect(2)
|
||||
var done = assert.async()
|
||||
|
@ -51,8 +51,11 @@
|
||||
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with XSS" data-container="<img src=1 onerror=alert(123) />">
|
||||
Tooltip with XSS
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with container" data-container="#customContainer">
|
||||
Tooltip with container
|
||||
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with container (selector)" data-container="#customContainer">
|
||||
Tooltip with container (selector)
|
||||
</button>
|
||||
<button id="tooltipElement" type="button" class="btn btn-secondary" data-placement="left" title="Tooltip with container (element)">
|
||||
Tooltip with container (element)
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
|
||||
Tooltip with HTML
|
||||
@ -70,6 +73,9 @@
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
$('#tooltipElement').tooltip({
|
||||
container: $('#customContainer')[0]
|
||||
})
|
||||
$('#target').tooltip({
|
||||
placement : 'top',
|
||||
trigger : 'manual'
|
||||
|
Loading…
x
Reference in New Issue
Block a user