• Stars
    star
    518
  • Rank 85,166 (Top 2 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

forceFeed.js

Static mockups are liars. They only show the designer's content.

The forceFeed.js script is designed to help you test your design's tolerance for variable, dynamic content. A tiny script that "force feeds" HTML elements with random text content within specified parameters. Set up, keep refreshing your browser until something breaks, then fix the design.

Get started

Installation

ForceFeed is available via npm install forcefeed or bower install forcefeed

Include the script

First include the script after the page content and before the closing body tag:

  <script src="path/to/forceFeed.js"></script>
</body>

Attribute elements

forceFeed.js uses a special attribute, data-forcefeed, to feed randomized content into individual elements. Consider the following example:

<div class="person">
  <h3 class="name" data-forcefeed="words|2"></h3>
  <p class="description" data-forcefeed="sentences|3|6">This will be overridden</p>
</div>

Here, I have created a dummy person/bio module. Note the "parameters" of the data-forcefeed attribute: The first refers to a named array of content from which the random content is sampled. The second and third parameters determine what quantity of content should be sampled. If only one parameter is provided, exactly this many items from the array is included. So, in data-forcefeed="words|2", two random words from a "words" array will be provided. If two numbers are present, as in data-forcefeed="sentences|3|6, between 3 and 6 items ("sentences") will make up that sample.

Executing forceFeed.js

Of course, for the above to work, you need to execute the script, providing an object that defines the arrays from which you aim to generate the sample content. In this case, I need to link up a "words" and a "sentences" array.

Here are my arrays:

window.words = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'adipsing', 'consectetur', 'elit', 'sed', 'commodo', 'eu', 'ligula', 'vitae', 'mollis'];

window.sentences = ['Curabitur tempus lobortis faucibus.', 'Nulla sed consequat libero.', 'Phasellus bibendum neque eros, vel malesuada ligula fermentum et.', 'Vivamus pretium vulputate imperdiet.', 'Morbi eleifend urna ac purus auctor, non porttitor massa semper.', 'Ut tempor ante et mauris sagittis, sed vestibulum urna rhoncus.', 'Mauris quis augue fermentum, auctor metus quis, imperdiet lectus.', 'Morbi nec rhoncus lectus.',  'Nulla cursus venenatis urna maximus bibendum.', 'Cras at ornare tortor.', 'Nulla nulla justo, posuere id ultricies non, feugiat et nisi.', 'Duis porttitor aliquet viverra.', 'Integer vehicula fringilla velit, at iaculis dolor imperdiet vel.'];

And here's how I execute the script:

forceFeed({words: window.words, sentences: window.sentences});

Note: If an array is not defined or an unrecognized array name is used as a parameter, the script will throw an error and cease execution:

if (!buffet) {
  throw new Error('A forceFeed.js parameter, ' + split[0] + ', for the element ' + el.outerHTML + ' is not recognized.');
}

COMMAND + R UNTIL IT BREAKS!

The notion that inspired forceFeed.js is that static mockups don't tell the whole story: Content will vary in length and quantity as a design is put to use. You need to test the design's tolerance for dynamic content!

So, load up the script and keep hitting COMMAND + R (or CTRL + F5), adjusting the design each time you need to until it's nice and robust.

FUCK LOREM, LET'S CANNIBALIZE!

In the previous example, I hand coded some arrays using lorem ipsum text. But, if the page already has static content, why not use that? In the following recipe, I take all words from paragraphs on the page to reuse in forceFeed.js:

// get all the paragraph elements as an array
window.paragraphs = [].slice.call(document.querySelectorAll('p'));

// init allWords array
window.allWords = [];

// iterate over paragraphs
paragraphs.forEach(function(paragraph) { 
  
  // remove punctuation
  var paragraphContent = paragraph.textContent
                        .replace(/[^\w\s]|_/g, "")
                        .replace(/\s+/g, " ");
  
  // make into an array
  var wordsArray = paragraphContent.split(' ');
  
  // remove bogus, empty last item
  wordsArray.pop();
  
  // push each word to our array
  wordsArray.forEach(function(word) {
    allWords.push(word);
  });
  
});

forceFeed({words: allWords});

In this implementation, the randomized, force fed content is made up of the original content. This is somewhat of an improvement because it uses the language of the page, not Latin dummy text.

License

WTFPL

More Repositories

1

inclusive-design-checklist

Aims to be the biggest checklist of inclusive design considerations ever
JavaScript
2,713
star
2

fukol-grids

CSS
1,468
star
3

REVENGE.CSS

A CSS bookmarklet that puts pink error boxes (with messages in comic sans) everywhere you write bad HTML.
CSS
828
star
4

bruck

A prototyping system built with web components and the Houdini Paint API
JavaScript
511
star
5

watched-box

JavaScript
327
star
6

Community-Icon-Font

To create a collaborative font using SVG
196
star
7

inclusive-menu-button

A keyboard and screen reader accessible ARIA menu button implementation.
JavaScript
191
star
8

design-tokens-cli

Set of design tokens and a custom properties parser for prototyping
JavaScript
173
star
9

cel-animation

A Sass @mixin for creating traditional frame-based animations, especially with SVG
CSS
155
star
10

beadz-drum-machine

A quantum, polymetric drum machine.
Vue
141
star
11

on-demand-live-region

JavaScript
128
star
12

ga11ery

Eleventy theme for showcasing photography and web comics
HTML
97
star
13

cress

JavaScript
83
star
14

readabilityCheckerCLI

A node CLI for checking how readable content is. Accepts a URL or HTML file.
JavaScript
70
star
15

xiao

A tiny, accessible, browser-driven single-page routing system.
JavaScript
56
star
16

react-sortable-table-demo

See the article here: https://inclusive-components.design/data-tables
JavaScript
40
star
17

css-scopulation-enterprise-max-ai

JavaScript
29
star
18

react-theme-switch

JavaScript
27
star
19

Inclusive-Components

Resources for the inclusive components blog (inclusive-components.design)
26
star
20

css-error-property-style

18
star
21

wai-aria-web-component

A "disclosure" (show/hide) web component using ARIA and built with Polymer
CSS
13
star
22

inclusive-inline-editable

JavaScript
9
star
23

buttonlike

A jQuery plugin for making clickable elements more accessible
JavaScript
8
star
24

typical-theme-wordpress

A responsive, resolution independent Wordpress theme with microdata support
CSS
8
star
25

AMA

Ask me anything
6
star
26

Squib-Font

A free font licensed under the Open Font License
6
star
27

heydonworks

HeydonWorks Wordpress theme
CSS
3
star
28

Accessible-Designer-Examples

Examples of creative, accessible design concepts.
HTML
3
star
29

ga11ery-michael

HTML
2
star
30

ga11ery-example

HTML
2
star
31

niace-stories-app

The alpha application for NIACE.
JavaScript
1
star
32

Redfoir

Freedom of Information Timeline Project
JavaScript
1
star