Skip to content

Instantly share code, notes, and snippets.

@danfoust
danfoust / copyToClipboard.js
Created February 28, 2019 19:12
Simple Vanilla js approach for copying text of data attribute on click
document.querySelectorAll('.copy-text').forEach(function(elem) {
elem.addEventListener('click', function() {
var copyText = this.getAttribute('data-copyText');
copyToClipboard(copyText);
});
});
function copyToClipboard(text) {
var selected = false;
@danfoust
danfoust / jquery-passive-listener.js
Created December 20, 2018 22:01
Improves scroll performance by making jQuery events passive. Run directly after jQuery script is loaded. Read more: https://stackoverflow.com/questions/46094912/added-non-passive-event-listener-to-a-scroll-blocking-touchstart-event
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
this.addEventListener("touchstart", handle, { passive: false });
} else {
this.addEventListener("touchstart", handle, { passive: true });
}
}
};
@danfoust
danfoust / style.css
Created December 18, 2018 19:58
If you're lazy loading images, this will prevent the flash of alt text that appears before the images are loaded.
img:not([src]) {
visibility: hidden;
}
/* IE/Edge */
img[data-src]:not([src]),
img[data-srcset]:not([src]) {
display: block;
min-height: 1px;
}
@danfoust
danfoust / parse.html
Last active November 16, 2018 19:10
Parse XML File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Parse XML</title>
<script>
function getXML(fileUrl)
{