1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-26 06:44:35 +02:00

Add a template factory helper to handle all template cases (#34519)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
GeoSot
2021-11-25 19:14:02 +02:00
committed by GitHub
parent fa33e83f25
commit 94a596fbcb
10 changed files with 606 additions and 131 deletions

View File

@@ -144,11 +144,12 @@
clipboard.on('success', function (event) {
var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
var originalTitle = event.trigger.getAttribute('title')
event.trigger.setAttribute('data-bs-original-title', 'Copied!')
tooltipBtn.show()
event.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' })
event.trigger.addEventListener('hidden.bs.tooltip', function () {
tooltipBtn.setContent({ '.tooltip-inner': originalTitle })
}, { once: true })
event.clearSelection()
})
@@ -156,11 +157,12 @@
var modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
var originalTitle = event.trigger.getAttribute('title')
event.trigger.setAttribute('data-bs-original-title', fallbackMsg)
tooltipBtn.show()
event.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg })
event.trigger.addEventListener('hidden.bs.tooltip', function () {
tooltipBtn.setContent({ '.tooltip-inner': originalTitle })
}, { once: true })
})
anchors.options = {

View File

@@ -368,6 +368,21 @@ Removes the ability for an element's popover to be shown. The popover will only
myPopover.disable()
```
#### setContent
Gives a way to change the popover's content after its initialization.
```js
myPopover.setContent({
'.popover-header': 'another title',
'.popover-body': 'another content'
})
```
{{< callout info >}}
The `setContent` method accepts an `object` argument, where each property-key is a valid `string` selector within the popover template, and each related property-value can be `string` | `element` | `function` | `null`
{{< /callout >}}
#### toggleEnabled
Toggles the ability for an element's popover to be shown or hidden.

View File

@@ -392,6 +392,17 @@ Removes the ability for an element's tooltip to be shown. The tooltip will only
tooltip.disable()
```
#### setContent
Gives a way to change the tooltip's content after its initialization.
```js
tooltip.setContent({ '.tooltip-inner': 'another title' })
```
{{< callout info >}}
The `setContent` method accepts an `object` argument, where each property-key is a valid `string` selector within the popover template, and each related property-value can be `string` | `element` | `function` | `null`
{{< /callout >}}
#### toggleEnabled
Toggles the ability for an element's tooltip to be shown or hidden.