| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- var Seed = require('seed')
- var todos = [
- { text: 'make nesting controllers work', done: true },
- { text: 'complete ArrayWatcher', done: true },
- { text: 'computed properties', done: true },
- { text: 'parse textnodes', done: false }
- ]
- Seed.controller('Todos', function (scope) {
- // regular properties -----------------------------------------------------
- scope.todos = todos
- scope.filter = window.location.hash.slice(2) || 'all'
- scope.remaining = todos.reduce(function (count, todo) {
- return count + (todo.done ? 0 : 1)
- }, 0)
- scope.allDone = scope.remaining === 0
- // computed properties ----------------------------------------------------
- scope.total = {get: function () {
- return scope.todos.length
- }}
- scope.completed = {get: function () {
- return scope.total - scope.remaining
- }}
- scope.itemLabel = {get: function () {
- return scope.remaining > 1 ? 'items' : 'item'
- }}
- // event handlers ---------------------------------------------------------
- scope.addTodo = function (e) {
- var val = e.el.value
- if (val) {
- e.el.value = ''
- scope.todos.unshift({ text: val, done: false })
- }
- scope.remaining++
- }
- scope.removeTodo = function (e) {
- scope.todos.remove(e.scope)
- scope.remaining -= e.scope.done ? 0 : 1
- }
- scope.updateCount = function (e) {
- scope.remaining += e.scope.done ? -1 : 1
- scope.allDone = scope.remaining === 0
- }
- scope.edit = function (e) {
- e.scope.editing = true
- }
- scope.stopEdit = function (e) {
- e.scope.editing = false
- }
- scope.setFilter = function (e) {
- scope.filter = e.el.dataset.filter
- }
- scope.toggleAll = function (e) {
- scope.todos.forEach(function (todo) {
- todo.done = e.el.checked
- })
- scope.remaining = e.el.checked ? 0 : scope.total
- }
- scope.removeCompleted = function () {
- scope.todos = scope.todos.filter(function (todo) {
- return !todo.done
- })
- }
- })
- var app = Seed.bootstrap()
|