Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created March 3, 2015 17:02
Show Gist options
  • Select an option

  • Save tonyfast/859de8541b54c598ec34 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/859de8541b54c598ec34 to your computer and use it in GitHub Desktop.
Riot Demo
<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/g/riot@2.0(riot.min.js+compiler.min.js)"></script>
<style>
@import "https://raw.githubusercontent.com/muut/riotjs/gh-pages/demo/todo.css";
</style>
</head>
<body>
<todo></todo>
<script src="todo.html" type="riot/tag"></script>
<script>
;(function(){
riot.mount('todo', {
title: 'I want to behave!',
items: [
{ title: 'Avoid excessive coffeine', done: true },
{ title: 'Hidden item', hidden: true },
{ title: 'Be less provocative' },
{ title: 'Be nice to people' }
]
}); //mount
})();
</script>
</body>
</html>
<todo>
<h3>{ this.opts.title }</h3>
<ul>
<li each={ items }>
<label class={ completed: done }>
<input type="checkbox" checked={ done } onclick={ parent.toggle }> { title }
</label>
</li>
</ul>
<form onsubmit={ add }>
<input name="input" onkeyup={ edit }>
<button disabled={ !text }>Add #{ items.length + 1 }</button>
</form>
this.disabled = true
this.items = opts.items
edit = function(e){
this.text = e.target.value
}
add = function(e){
if (this.text) {
this.items.push({ title: this.text })
this.text = this.input.value = ''
}
}
toggle = function(e){
var item = e.item
item.done = !item.done
return true
}
</todo>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment