JSFiddle - React, Tailwind, and code Playground
by rich_harris
HTML
<script src="http://cdn.ractivejs.org/edge/ractive.js"></script>
<p>click 'toggle step' - it shouldn't move</p>
<main></main>
<script id='template' type='text/ractive'>
{{ >partial}}
<!-- this is needed! -->
</script>
<script id='partial' type='text/ractive'>
{{# steps[currentStep] }}
{{#if bool}}
some text
<!-- this is needed! -->
{{/if}}
{{/}}
{{#if currentStep < steps.length - 1 }}
<a on-click='toggleStep'>toggle step: 1</a>
{{else}}
<a on-click='toggleStep'>toggle step: 0</a>
{{/if}}
</script>
CSS
body {
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 200;
color: #353535;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 200;
}
a {
color: blue;
cursor: pointer;
}
JavaScript
var ractive = new Ractive({
el: 'main',
template: '#template',
data: {
currentStep: 0,
stepsQuantity: 2,
steps: [{}, {}],
bool: true
}
});
ractive.on( 'toggleStep', function () {
var step = this.get( 'currentStep' ) === 1 ? 0 : 1;
this.set( 'currentStep', null );
this.set( 'currentStep', step );
});