mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Add copy buttons to code snippets
This commit is contained in:
@ -8,7 +8,7 @@ for (var i = 0; i < btns.length; i++) {
|
||||
}
|
||||
|
||||
function showTooltip(elem, msg) {
|
||||
elem.setAttribute('class', 'btn tooltipped tooltipped-s');
|
||||
elem.setAttribute('class', elem.className.indexOf('clip') === -1 ? 'btn tooltipped tooltipped-s': 'btn clip tooltipped tooltipped-s');
|
||||
elem.setAttribute('aria-label', msg);
|
||||
}
|
||||
|
||||
|
17
assets/scripts/snippets.js
Normal file
17
assets/scripts/snippets.js
Normal file
@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var identifier = 0;
|
||||
var snippets = Array.prototype.slice.call(document.querySelectorAll('pre.snippet'));
|
||||
|
||||
snippets.forEach(function(snippet) {
|
||||
snippet.id = 'snip' + identifier;
|
||||
|
||||
var copyBtn = document.createElement('span');
|
||||
|
||||
copyBtn.className = 'btn clip';
|
||||
copyBtn.setAttribute('data-clipboard-target', '#snip' + identifier++);
|
||||
|
||||
snippet.parentElement.insertBefore(copyBtn, snippet);
|
||||
});
|
||||
})();
|
Reference in New Issue
Block a user