2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-05-21 13:24:08 +03:00

Redesign clipboard-js to use icons

Co-Authored-By: GeoSot <geo.sotis@gmail.com>
This commit is contained in:
Mark Otto
2022-02-10 16:32:28 -08:00
parent b20bec5601
commit 0a87bd0e95
+11 -1
View File
@@ -134,7 +134,7 @@
// Insert copy to clipboard button before .highlight
var btnTitle = 'Copy to clipboard'
var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" ><svg class="bi" width="1em" height="1em" fill="currentColor" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg></button></div>'
var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard"><svg class="bi" width="1em" height="1em" fill="currentColor" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg></button></div>'
document.querySelectorAll('div.highlight')
.forEach(function (element) {
@@ -160,13 +160,23 @@
})
clipboard.on('success', function (event) {
var iconFirstChild = event.trigger.querySelector('.bi').firstChild
var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
var namespace = 'http://www.w3.org/1999/xlink'
var originalXhref = iconFirstChild.getAttributeNS(namespace, 'href')
var originalTitle = event.trigger.title
tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' })
event.trigger.addEventListener('hidden.bs.tooltip', function () {
tooltipBtn.setContent({ '.tooltip-inner': btnTitle })
}, { once: true })
event.clearSelection()
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2'))
setTimeout(function () {
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref)
event.trigger.title = originalTitle
}, 2000)
})
clipboard.on('error', function (event) {