diff options
| author | GeoSot <[email protected]> | 2021-11-25 19:14:02 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-25 19:14:02 +0200 |
| commit | 94a596fbcb1011ba990da2078ba7e20b39dba2d9 (patch) | |
| tree | 26af41580d5cae017e32e29cfef96178e897afa6 /site | |
| parent | fa33e83f25faf8c378b99126fbd69977e667ad9a (diff) | |
| download | bootstrap-94a596fbcb1011ba990da2078ba7e20b39dba2d9.tar.xz bootstrap-94a596fbcb1011ba990da2078ba7e20b39dba2d9.zip | |
Add a template factory helper to handle all template cases (#34519)
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'site')
| -rw-r--r-- | site/assets/js/application.js | 18 | ||||
| -rw-r--r-- | site/content/docs/5.1/components/popovers.md | 15 | ||||
| -rw-r--r-- | site/content/docs/5.1/components/tooltips.md | 11 |
3 files changed, 36 insertions, 8 deletions
diff --git a/site/assets/js/application.js b/site/assets/js/application.js index acf859764..2c57906c9 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -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 = { diff --git a/site/content/docs/5.1/components/popovers.md b/site/content/docs/5.1/components/popovers.md index dc1c985d3..0acc76a0a 100644 --- a/site/content/docs/5.1/components/popovers.md +++ b/site/content/docs/5.1/components/popovers.md @@ -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. diff --git a/site/content/docs/5.1/components/tooltips.md b/site/content/docs/5.1/components/tooltips.md index caa2a2d0c..16501a3c9 100644 --- a/site/content/docs/5.1/components/tooltips.md +++ b/site/content/docs/5.1/components/tooltips.md @@ -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. |
