diff --git a/site/assets/js/application.js b/site/assets/js/application.js index ff1ad3136682..55e8969802c3 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -10,7 +10,7 @@ * For details, see https://creativecommons.org/licenses/by/3.0/. */ -/* global ClipboardJS: false, bootstrap: false */ +/* global bootstrap: false */ (() => { 'use strict' @@ -131,73 +131,4 @@ modalBodyInput.value = recipient }) } - - // Insert copy to clipboard button before .highlight - const btnTitle = 'Copy to clipboard' - const btnEdit = 'Edit on StackBlitz' - const btnHtml = '
' - - document.querySelectorAll('.bd-masthead .highlight, .bd-content > .highlight') - .forEach(element => { - element.insertAdjacentHTML('beforebegin', btnHtml) - }) - - /** - * - * @param {string} selector - * @param {string} title - */ - function snippetButtonTooltip(selector, title) { - document.querySelectorAll(selector).forEach(btn => { - const tooltipBtn = new bootstrap.Tooltip(btn, { title }) - - btn.addEventListener('mouseleave', () => { - // Explicitly hide tooltip, since after clicking it remains - // focused (as it's a button), so tooltip would otherwise - // remain visible until focus is moved away - tooltipBtn.hide() - }) - }) - } - - snippetButtonTooltip('.btn-clipboard', btnTitle) - snippetButtonTooltip('.btn-edit', btnEdit) - - const clipboard = new ClipboardJS('.btn-clipboard', { - target(trigger) { - const snippet = trigger.parentNode.classList.contains('bd-clipboard') ? trigger.parentNode.nextElementSibling : trigger.closest('.bd-example-snippet').querySelector('.highlight') - return snippet - } - }) - - 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 }) - }) })() diff --git a/site/assets/js/code-examples.js b/site/assets/js/code-examples.js new file mode 100644 index 000000000000..4a61fa09b720 --- /dev/null +++ b/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 = [ + '