A "Choose Your Own Adventure" plugin for interactive storytelling, from the apps team at Mother Jones.
- Uses jQuery for easy placement.
- Uses TableTop
- Uses Google Spreadsheets like this one
- Responsive, for displaying nicely on mobile screens.
The internets loved our first use of this container (trigger warning: cute kittens within).
Here's an example where the user walks through what it would take to overturn the landmark Citizen United campaign finance decision.
Mother Jones' reporters made this story all by themselves, with almost zero help from our interactives team: it's a little game showing Mitt Romney's stance on immigration over time.
A Texas Tribune reporter used this to make this story on Medicaid expansion.
Download the production version or the development version.
In your web page:
<script src="jquery.js"></script>
<script src="dist/cyoa.min.js"></script>
<link href="../css/cyoa.css" rel="stylesheet" />
<script>
jQuery(function($) {
$.cyoa({
start : { // default start page, if you want to call it something different, you have to set it in the options
img: 'http://www.url/img.png',
connects: [
{ 'link' : 'page_2',
'html' : 'Some text here'
}, {
'link' : 'death_by_water',
'html' : 'The hanged man'
}, {
'link' : 'foobarbaz',
'html' : 'variables'
}
]
},
page_2 : {
html: '<h1>Arbitrary html goes here !!! WhoooO!!!',
connects: [
{ 'link' : 'death_by_water',
'html' : 'I hate fortune tellers'
}
]
},
death_by_water : {
img: 'http://wasteland.org/fear.jpg',
select_img: 'http://placekitten.com/100/100' //optional
}
},
{
container: 'id of html element which holds the story',
start_page : 'optional, the key of the story page you start on, defaults to "start"'
}
); // makes a wasteland story
});
</script>
Alternately, you can use tabletop to connect to google spreadsheet and automatically write the JSON needed to power the CYOA.
<script src="jquery.js"></script>
<script src="dist/cyoa.min.js"></script>
<script src="tabletop.js"></script>
<script>
jQuery(function($) {
$.cyoa(
'the key to your published google spreadsheet',
{ separator: '|' }
);
});
</script>
Column headers for your google spreadsheet must be slug, text, connects to, connects text, title, background image, The connects to should be a | separated list of slugs which you want the page to connect to. The connects text should be a | separated list of what you want the connectors to read. If you like, you can designate a different character as the separator. Note that the order of the connects to and connects text must match.
Wow. That's a bit to take in, isn't it. Why not look at an example of a spreadsheet that feeds a cyoa.
When you make the function, you can also feed in your options; in addition to how you want to separate your info, you can choose how the controls appear the controls are 'left', 'right', 'centered', and 'split' like so:
<script>
jQuery(function($) {
$.cyoa(
'the key to your published google spreadsheet',
{ separator: '|',
control_position: 'centered'
);
});
</script>
Hoping to sneak around Google's arbitrary rate limits? CYOA now supports a tabletop_proxy
setting, which gets pased on to the Tabletop.init() call.
##Hey! This thing is responsive now! Yup. Huge thanks to our lovely friends over at the Texas Tribune.
###How It Works Inspired by Chris Coyier's Flexslider, it uses an absolutely positioned paragraph over an image element, rather than a background image. That's it. Two elements, in a box. You could generate more elements in the JS, if you wanted, and position them absolutely as well.
###NOTE Because you're using images and not background images, and because they're now responsive, you need to make sure all of them are of a minimum height - the overflow:hidden on the viewport will hide oversized images but if an image is short, it will make the entire container short.
This is the first release!
Copyright (c) 2012 MotherJones Licensed under the MIT, GPL licenses.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Please don't edit files in the dist
subdirectory as they are generated via grunt. You'll find source code in the src
subdirectory!
While grunt can run the included unit tests via PhantomJS, this shouldn't be considered a substitute for the real thing. Please be sure to test the test/*.html
unit test file(s) in actual browsers.
This assumes you have node.js and npm installed already.
- Test that grunt is installed globally by running
grunt --version
at the command-line. - If grunt isn't installed globally, run
npm install -g grunt
to install the latest version. You may need to runsudo npm install -g grunt
. - From the root directory of this project, run
npm install
to install the project's dependencies.
In order for the qunit task to work properly, PhantomJS must be installed and in the system PATH (if you can run "phantomjs" at the command line, this task should work).
Unfortunately, PhantomJS cannot be installed automatically via npm or grunt, so you need to install it yourself. There are a number of ways to install PhantomJS.
- PhantomJS and Mac OS X
- PhantomJS Installation (PhantomJS wiki)
Note that the phantomjs
executable needs to be in the system PATH
for grunt to see it.