diff options
author | Mario <mario@mariovavti.com> | 2022-10-10 18:05:26 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2022-10-10 18:05:26 +0000 |
commit | ef2448e17e742e7dcef458993bce1e0a29756aa7 (patch) | |
tree | d23c62753abbb42e7bb742f2d44d09321b6f2eee /vendor/twbs/bootstrap/site/assets/js/code-examples.js | |
parent | 6ab65519a0fc3e55ad5f32ce1641190ef609a4e2 (diff) | |
parent | 99a5cf1ad4660a31af6c03e5a1abc3d374f82c78 (diff) | |
download | volse-hubzilla-7.8.tar.gz volse-hubzilla-7.8.tar.bz2 volse-hubzilla-7.8.zip |
Merge branch '7.8RC'7.8
Diffstat (limited to 'vendor/twbs/bootstrap/site/assets/js/code-examples.js')
-rw-r--r-- | vendor/twbs/bootstrap/site/assets/js/code-examples.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/twbs/bootstrap/site/assets/js/code-examples.js b/vendor/twbs/bootstrap/site/assets/js/code-examples.js new file mode 100644 index 000000000..25486c2fe --- /dev/null +++ b/vendor/twbs/bootstrap/site/assets/js/code-examples.js @@ -0,0 +1,88 @@ +// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT +// IT'S ALL JUST JUNK FOR OUR DOCS! +// ++++++++++++++++++++++++++++++++++++++++++ + +/*! + * JavaScript for Bootstrap's docs (https://getbootstrap.com/) + * Copyright 2011-2022 The Bootstrap Authors + * Copyright 2011-2022 Twitter, Inc. + * Licensed under the Creative Commons Attribution 3.0 Unported License. + * For details, see https://creativecommons.org/licenses/by/3.0/. + */ + +/* global ClipboardJS: false, bootstrap: false */ + +(() => { + 'use strict' + // Insert copy to clipboard button before .highlight + const btnTitle = 'Copy to clipboard' + const btnEdit = 'Edit on StackBlitz' + + const btnHtml = [ + '<div class="bd-code-snippet">', + ' <div class="bd-clipboard">', + ' <button type="button" class="btn-clipboard">', + ' <svg class="bi" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg>', + ' </button>', + ' </div>', + '</div>' + ].join('') + + // wrap programmatically code blocks and add copy btn. + document.querySelectorAll('.highlight') + .forEach(element => { + if (!element.closest('.bd-example-snippet')) { // Ignore examples made be shortcode + element.insertAdjacentHTML('beforebegin', btnHtml) + element.previousElementSibling.append(element) + } + }) + + /** + * + * @param {string} selector + * @param {string} title + */ + function snippetButtonTooltip(selector, title) { + document.querySelectorAll(selector).forEach(btn => { + bootstrap.Tooltip.getOrCreateInstance(btn, { title }) + }) + } + + snippetButtonTooltip('.btn-clipboard', btnTitle) + snippetButtonTooltip('.btn-edit', btnEdit) + + const clipboard = new ClipboardJS('.btn-clipboard', { + target: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight') + }) + + clipboard.on('success', event => { + const iconFirstChild = event.trigger.querySelector('.bi').firstChild + const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) + const namespace = 'http://www.w3.org/1999/xlink' + const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href') + const originalTitle = event.trigger.title + + tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' }) + event.trigger.addEventListener('hidden.bs.tooltip', () => { + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) + }, { once: true }) + event.clearSelection() + iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2')) + + setTimeout(() => { + iconFirstChild.setAttributeNS(namespace, 'href', originalXhref) + event.trigger.title = originalTitle + }, 2000) + }) + + clipboard.on('error', event => { + const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-' + const fallbackMsg = `Press ${modifierKey}C to copy` + const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger) + + tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg }) + event.trigger.addEventListener('hidden.bs.tooltip', () => { + tooltipBtn.setContent({ '.tooltip-inner': btnTitle }) + }, { once: true }) + }) +})() |