Skip to content

Commit

Permalink
ESLintify Part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Jul 11, 2018
1 parent ae3fd90 commit ed4f2c1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions website/static/js/code-blocks-buttons.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
/* global ClipboardJS */

window.addEventListener('load', () => {
// Turn off ESLint for this file because it's sent down to users as-is.
/* eslint-disable */
window.addEventListener('load', function() {
function button(label, ariaLabel, icon, className) {
const btn = document.createElement('button');
btn.classList.add('btnIcon', className);
btn.setAttribute('type', 'button');
btn.setAttribute('aria-label', ariaLabel);
btn.innerHTML =
`<div class="btnIcon__body">${icon}<strong class="btnIcon__label">${label}</strong>` +
`</div>`;
'<div class="btnIcon__body">' +
icon +
'<strong class="btnIcon__label">' +
label +
'</strong>' +
'</div>';
return btn;
}

function addButtons(codeBlockSelector, btn) {
document.querySelectorAll(codeBlockSelector).forEach(code => {
document.querySelectorAll(codeBlockSelector).forEach(function(code) {
code.parentNode.appendChild(btn.cloneNode(true));
});
}
Expand All @@ -27,18 +31,16 @@ window.addEventListener('load', () => {
);

const clipboard = new ClipboardJS('.btnClipboard', {
// Not gonna use the shorthand as this file is sent down to browsers without transpiling.
/* eslint-disable object-shorthand */
target: function(trigger) {
return trigger.parentNode.querySelector('code');
},
});

clipboard.on('success', event => {
clipboard.on('success', function(event) {
event.clearSelection();
const textEl = event.trigger.querySelector('.btnIcon__label');
textEl.textContent = 'Copied';
setTimeout(() => {
setTimeout(function() {
textEl.textContent = 'Copy';
}, 2000);
});
Expand Down

0 comments on commit ed4f2c1

Please sign in to comment.