Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/_site
/node_modules
/.bundle
assets/vendor/clipboard/src
assets/vendor/clipboard/test
assets/vendor/hint.css/src
/vendor
/.sass-cache
Expand Down
1 change: 0 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exclude:
- vendor/bundle
- spec
- assets/vendor/selectivizr/tests
- assets/vendor/clipboard/test
- assets/vendor/*/README.*
- license-list-XML

Expand Down
1 change: 0 additions & 1 deletion _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
</div> <!-- /container -->

{% if page.collection == "licenses" or page.class == "license-types" %}
<script src="{{ 'assets/vendor/clipboard/dist/clipboard.min.js' | relative_url }}"></script>
<script>
window.annotations = {{ site.data.rules | jsonify }};
{% if page.collection == "licenses" %}
Expand Down
73 changes: 56 additions & 17 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,71 @@ class Choosealicense {
});
}

// Initializes Clipboard.js
// Initializes copy-to-clipboard behavior
initClipboard() {
const buttons = document.querySelectorAll('.js-clipboard-button');
buttons.forEach((button) => {
button.dataset.clipboardPrompt = button.textContent;
});
button.addEventListener('click', (event) => {
event.preventDefault();

const clip = new Clipboard('.js-clipboard-button');
clip.on('mouseout', (event) => this.clipboardMouseout(event));
clip.on('complete', (event) => this.clipboardComplete(event));
}
const targetSelector = button.getAttribute('data-clipboard-target');
if (!targetSelector) return;

// Callback to restore the clipboard button's original text
clipboardMouseout(event) {
const trigger = event && event.trigger;
if (trigger) {
trigger.textContent = trigger.dataset.clipboardPrompt || '';
}
const targetElement = document.querySelector(targetSelector);
if (!targetElement) return;

this.selectText(targetElement);

const textToCopy = targetElement.textContent || '';
if (!textToCopy) return;

this.copyText(textToCopy)
.then(() => {
button.textContent = 'Copied!';
})
.catch(() => {
// If copying fails, leave the prompt unchanged.
});
});

const restorePrompt = () => {
button.textContent = button.dataset.clipboardPrompt || '';
};

button.addEventListener('mouseleave', restorePrompt);
button.addEventListener('blur', restorePrompt);
});
}

// Post-copy user feedback callback
clipboardComplete(event) {
const trigger = event && event.trigger;
if (trigger) {
trigger.textContent = 'Copied!';
copyText(text) {
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(text);
}

return new Promise((resolve, reject) => {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.setAttribute('readonly', '');
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
document.body.appendChild(textarea);

textarea.select();
textarea.setSelectionRange(0, textarea.value.length);

try {
const successful = document.execCommand('copy');
if (!successful) {
throw new Error('Copy command was unsuccessful');
}
resolve();
} catch (error) {
reject(error);
} finally {
document.body.removeChild(textarea);
}
});
}

// Initializes the repository suggestion feature
Expand Down
31 changes: 0 additions & 31 deletions assets/vendor/clipboard/.bower.json

This file was deleted.

20 changes: 0 additions & 20 deletions assets/vendor/clipboard/bower.json

This file was deleted.

28 changes: 0 additions & 28 deletions assets/vendor/clipboard/contributing.md

This file was deleted.

Loading
Loading