Commit e280987d authored by Sindre Sorhus's avatar Sindre Sorhus

Batman app: Cleanup

parent e1843aab
# Batman TodoMVC # Batman • [TodoMVC](http://todomvc.com)
A todo app built using [Batman](http://batmanjs.org), inspired by [TodoMVC](https://github.com/addyosmani/todomvc). A todo app built using [Batman](http://batmanjs.org)
## Running it
Spin up an HTTP server and visit http://localhost/labs/architecture-examples/batman/index.html ## Run
Spin up an HTTP server and visit http://localhost/labs/architecture-examples/batman/
## Persistence ## Persistence
A quick note: This app uses `Batman.LocalStorage` to persist the Todo records across page reloads. Batman's `localStorage` engine sticks each record under it's own key in `localStorage`, which is a departure from the TodoMVC application specification, which asks that all the records are stored under one key as a big blob. Batman stores records this way so that the whole set doesn't need to be parsed just to find one record or check if that record exists. A quick note: This app uses `Batman.LocalStorage` to persist the Todo records across page reloads. Batman's `localStorage` engine sticks each record under it's own key in `localStorage`, which is a departure from the TodoMVC application specification, which asks that all the records are stored under one key as a big blob. Batman stores records this way so that the whole set doesn't need to be parsed just to find one record or check if that record exists.
## Building it
This app is written in CoffeeScript, so to make changes, please edit `js/app.coffee` and rebuild the JavaScript with the `coffee` compiler.
## Build
This app is written in CoffeeScript, so to make changes, please edit `js/app.coffee` and rebuild the JavaScript with the `coffee` compiler.
\ No newline at end of file
...@@ -23,27 +23,23 @@ ...@@ -23,27 +23,23 @@
<li data-foreach-todo="currentTodos" <li data-foreach-todo="currentTodos"
data-addclass-completed="todo.completed" data-addclass-completed="todo.completed"
data-addclass-editing="todo.editing" > data-addclass-editing="todo.editing" >
<div class="view" data-hideif="todo.editing" data-event-doubleclick="toggleEditing"> <div class="view" data-hideif="todo.editing" data-event-doubleclick="toggleEditing">
<input class="toggle" type="checkbox" data-bind="todo.completed" data-event-change="todoDoneChanged"> <input class="toggle" type="checkbox" data-bind="todo.completed" data-event-change="todoDoneChanged">
<label data-bind="todo.title"></label> <label data-bind="todo.title"></label>
<button class="destroy" data-event-click="destroyTodo"></button> <button class="destroy" data-event-click="destroyTodo"></button>
</div> </div>
<input class="edit" type="text" <input class="edit" type="text"
data-bind="todo.title" data-bind="todo.title"
data-bind-id="'todo-input-' | append todo.id" data-bind-id="'todo-input-' | append todo.id"
data-event-blur="toggleEditing" data-event-blur="toggleEditing"
data-event-keypress="disableEditingUponSubmit" > data-event-keypress="disableEditingUponSubmit">
</li> </li>
</ul> </ul>
</section> </section>
<footer id="footer" data-showif="Todo.all.length"> <footer id="footer" data-showif="Todo.all.length">
<span id="todo-count"> <span id="todo-count">
<strong data-bind="Todo.active.length"></strong> <strong data-bind="Todo.active.length"></strong>
<span data-bind="'item' | pluralize Todo.active.length, false"></span> <span data-bind="'item' | pluralize Todo.active.length, false"></span> left
left
</span> </span>
<ul id="filters"> <ul id="filters">
<li> <li>
...@@ -56,7 +52,9 @@ ...@@ -56,7 +52,9 @@
<a data-addclass-selected="currentRoute.action | equals 'completed'" data-route="'/completed'">Completed</a> <a data-addclass-selected="currentRoute.action | equals 'completed'" data-route="'/completed'">Completed</a>
</li> </li>
</ul> </ul>
<button id="clear-completed" data-event-click="clearCompleted" data-showif="Todo.completed.length">Clear completed (<span data-bind="Todo.completed.length"></span>)</button> <button id="clear-completed" data-event-click="clearCompleted" data-showif="Todo.completed.length">
Clear completed (<span data-bind="Todo.completed.length"></span>)
</button>
</footer> </footer>
</section> </section>
<footer id="info"> <footer id="info">
...@@ -68,7 +66,7 @@ ...@@ -68,7 +66,7 @@
</div> </div>
<script src="../../../assets/base.js"></script> <script src="../../../assets/base.js"></script>
<script src="js/es5-shim.js"></script> <script src="js/es5-shim.js"></script>
<script src="js/batman.js"></script> <script src="js/lib/batman.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
class Alfred extends Batman.App class Alfred extends Batman.App
@root 'todos#all' @root 'todos#all'
@route "/completed", "todos#completed" @route '/completed', 'todos#completed'
@route "/active", "todos#active" @route '/active', 'todos#active'
class Alfred.TodosController extends Batman.Controller class Alfred.TodosController extends Batman.Controller
constructor: -> constructor: ->
...@@ -50,7 +50,6 @@ class Alfred.TodosController extends Batman.Controller ...@@ -50,7 +50,6 @@ class Alfred.TodosController extends Batman.Controller
editing = todo.set('editing', !todo.get('editing')) editing = todo.set('editing', !todo.get('editing'))
if editing if editing
input = document.getElementById("todo-input-#{todo.get('id')}") input = document.getElementById("todo-input-#{todo.get('id')}")
input.focus()
input.select() input.select()
else else
if todo.get('title')?.length > 0 if todo.get('title')?.length > 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment