header.coffee 275 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
ENTER_KEY = 13

window.HeaderViewModel = (todos) ->
	@title = ko.observable('')

	@onAddTodo = (view_model, event) =>
		return true if not $.trim(@title()) or (event.keyCode != ENTER_KEY)

		# Create task and reset UI
		todos.create({title: $.trim(@title())})
		@title('')
	@