Skip to content

Instantly share code, notes, and snippets.

@thiamsantos
Created January 27, 2017 16:28
Show Gist options
  • Save thiamsantos/c608b5848f8f688a66abd63650722df0 to your computer and use it in GitHub Desktop.
Save thiamsantos/c608b5848f8f688a66abd63650722df0 to your computer and use it in GitHub Desktop.
Shortway usage example.
<!DOCTYPE html>
<html>
<head>
<style>
#app {
padding-left: 20px;
}
#quote {
box-sizing: border-box;
border-left: 5px solid #e0e0e0;
font-family: 'Roboto', Helvetica, sans-serif;
line-height: 2;
font-size: 20px;
padding-left: 10px;
}
</style>
</head>
<body>
<div id="app">
<h1>Shortcuts</h1>
<p>Press the shortcuts below to see a Star Trek quote.</p>
<ul>
<li>Ctrl + Space</li>
<li>Shift + Arrow Left</li>
<li>Alt + Backspace</li>
<li>Ctrl + b</li>
<li>Shift + 1</li>
<li>Alt + F7</li>
<li>e</li>
<li>Arrow Top</li>
</ul>
<div id="quote"></div>
</div>
</body>
const shortway = require('shortway')
const quoteNode = document.getElementById('quote')
const quotes = [{
shortcut: 'ctrl+space',
quote: 'Set phasers to stun'
}, {
shortcut: 'shift+left',
quote: 'We are the borg, resistance is futile'
}, {
shortcut: 'alt+backspace',
quote: 'It\'s where they keep the nuclear wessels.'
}, {
shortcut: 'ctrl+b',
quote: 'To boldly go where no one has gone before'
}, {
shortcut: 'shift+1',
quote: 'I\'m giving her all she\'s got, captain'
}, {
shortcut: 'alt+f7',
quote: 'Live longer and prosper'
}, {
shortcut: 'e',
quote: 'Beam me up scotty'
}, {
shortcut: 'top',
quote: 'Damn it Spock! God damn it!'
}]
const commands = quotes.map(item => shortway(item.shortcut, () => {
quoteNode.textContent = item.quote
}))
commands.forEach(command => {
document.addEventListener('keyup', command)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment