Created
February 3, 2015 17:28
-
-
Save tonyfast/a5347e82532de901002c to your computer and use it in GitHub Desktop.
d3 + riotjs wrapped in reveal.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <head> | |
| <link rel="stylesheet" href="//cdn.jsdelivr.net/g/reveal.js(css/reveal.min.css)"> | |
| <script src="//cdn.jsdelivr.net/g/d3js,reveal.js,zepto,riot@2.0(riot.min.js+compiler.min.js)"></script> | |
| </head> | |
| <body> | |
| <div class="reveal"> | |
| <div class="slides"> | |
| <section>Single Horizontal Slide</section> | |
| <section id="blank"></section><!-- Blank slug --> | |
| </div> | |
| </div> | |
| <script type="riot/tag"> | |
| <test> | |
| <h1>{ opts.name }</h1> | |
| </test> | |
| </script> | |
| <script> | |
| ;(function(){ | |
| // Demo data | |
| names = ['tony','lee','dog', 'dirty' ]; | |
| // Initialize reveal | |
| Reveal.initialize(); | |
| //slide deck wrapper | |
| deck = $('#blank').parent(); | |
| // a blank is initialized and stored as a variable | |
| wrap = $('#blank').clone() | |
| .attr('id',null) | |
| .prop('outerHTML'); | |
| // remove the blank | |
| $('#blank').remove(); | |
| // tag to append | |
| tag = 'test'; | |
| // Dynamically add slides | |
| d3_riot_mount(tag); | |
| function d3_riot_mount(tag){ | |
| // append riot templates using d3 with reveal.js context | |
| d3.selectAll(tag) | |
| .data(names) | |
| .enter() | |
| .append(tag) | |
| .each( function(d){ | |
| // append custom riot tag and wrap it in the reveal js context | |
| $(this).appendTo( deck) | |
| .wrap( wrap ); | |
| // mount the content | |
| riot.mountTo( d3.select(this).node(), tag, { name: d } ); | |
| }); | |
| } | |
| })(); | |
| </script> | |
| </body> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment