Skip to content

Instantly share code, notes, and snippets.

@paulcollett
Last active July 15, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcollett/556e5ff25880623a9cf6e2ea244d4222 to your computer and use it in GitHub Desktop.
Save paulcollett/556e5ff25880623a9cf6e2ea244d4222 to your computer and use it in GitHub Desktop.
javascript, dummy placeholder text & images (for HTML prototyping)
// Dummy.js Simple placeholder text
document.querySelectorAll('[data-dummy]').forEach(el => {
if(el.nodeName == 'IMG') return el.src = '//placehold.it/'
+ (el.getAttribute('data-dummy') || el.parentNode.offsetWidth);
let lib = `lorem ipsum dolor sit amet consectetur adipiscing elit nunc euismod vel
dolor nec viverra nullam at auctor enim id condimentum odio in laoreet libero
libero a tincidunt est sagittis id curabitur vitae`
.split(' ').sort(() => 0.5 - Math.random())
.slice(0, +el.getAttribute('data-dummy') || 10).join(' ');
el.innerHTML += lib.charAt(0).toUpperCase() + lib.slice(1);
});
<h3 data-dummy></h3> <!-- defaults to 10 words -->
<p data-dummy="150"></p> <!-- output 150 words -->
<p data-dummy="2">Some prefixed text: </p>
<img data-dummy="200x100" />
<img data-dummy /> <!-- will be the size of the parent element -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment