Skip to content

Commit cdcba28

Browse files
tannerdolbyAdam Argyle
andauthored
Add new plugin 'placeholdifier' (#575)
* Add the 'placeholdifier' plugin * Use consistent single quotes * Register the plugin * Updates the loading of placeholdifier styles Co-authored-by: Adam Argyle <argyle@google.com> * Update app/plugins/placeholdifier.js * Remove optional chaining * Add optional chaining back as test runner was updated * Remove optional chaining and unused loadStyles * Add defensive check to mimic optional chaining Co-authored-by: Adam Argyle <argyle@google.com>
1 parent aa66c0b commit cdcba28

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

app/plugins/_registry.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { commands as no_mouse_days_commands, description as no_mouse_days_descri
1616
import { commands as remove_css_commands, description as remove_css_description, default as RemoveCSSPlugin } from './remove-css'
1717
import { commands as detect_overflows_commands, description as detect_overflows_description, default as DetectOverflows } from './detect-overflows'
1818
import { commands as loop_thru_widths_commands, description as loop_thru_widths_description, default as LoopThruWidths } from './loop-through-widths'
19+
import { commands as placeholdifier_commands, description as placeholdifier_description, default as PlaceholdifierPlugin } from './placeholdifier'
1920

2021
const commandsToHash = (plugin_commands, plugin_fn) =>
2122
plugin_commands.reduce((commands, command) =>
@@ -41,6 +42,7 @@ export const PluginRegistry = new Map(Object.entries({
4142
...commandsToHash(remove_css_commands, RemoveCSSPlugin),
4243
...commandsToHash(detect_overflows_commands, DetectOverflows),
4344
...commandsToHash(loop_thru_widths_commands, LoopThruWidths),
45+
...commandsToHash(placeholdifier_commands, PlaceholdifierPlugin),
4446
}))
4547

4648
export const PluginHints = [
@@ -61,6 +63,7 @@ export const PluginHints = [
6163
{command: remove_css_commands[0], description: remove_css_description},
6264
{command: detect_overflows_commands[0], description: detect_overflows_description},
6365
{command: loop_thru_widths_commands[0], description: loop_thru_widths_description},
66+
{command: placeholdifier_commands[0], description: placeholdifier_description},
6467
...colorblind_commands.map(cbc => {
6568
return {
6669
command: cbc, description: `simulate ${cbc}`

app/plugins/placeholdifier.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const commands = [
2+
'placeholdifier',
3+
]
4+
5+
export const description = 'turn the page into a live wireframe'
6+
7+
export default async function() {
8+
const stylesheet = document.createElement('link')
9+
stylesheet.setAttribute('rel', 'stylesheet')
10+
stylesheet.setAttribute('href', 'https://unpkg.com/placeholdifier/placeholdifier.css')
11+
document.head.appendChild(stylesheet)
12+
13+
const ignored = ['script', 'link']
14+
const body = document.querySelector('body')
15+
const elements = Array.from(body.querySelectorAll('*'))
16+
.filter(el => {
17+
if (!el || !el.tagName) return
18+
return !ignored.includes(el.tagName.toLowerCase())
19+
})
20+
21+
elements.forEach(el => {
22+
if (Array.from(el.classList).includes('placeholdify')) return;
23+
el.classList.add('placeholdify');
24+
})
25+
}

0 commit comments

Comments
 (0)