Skip to content

Commit

Permalink
Update to match commit cfc98b0f on Backbone.js
Browse files Browse the repository at this point in the history
  • Loading branch information
zachwill committed Dec 30, 2011
1 parent 8afb6d0 commit 927c2b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -50,7 +50,7 @@ <h3>Instructions:</h3>
<div class="todo <%= done ? 'done' : '' %>">
<div class="display">
<input class="check" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
<div class="todo-content"></div>
<div class="todo-text"></div>
<span class="todo-destroy"></span>
</div>
<div class="edit">
Expand Down
32 changes: 12 additions & 20 deletions todos.coffee
@@ -1,13 +1,9 @@
$ ->

class Todo extends Backbone.Model
defaults:
content: "Empty todo..."
defaults: ->
done: false

initialize: ->
if not @get('content')
@set content: @defaults.content
order: Todos.nextOrder()

toggle: ->
done = @get('done')
Expand Down Expand Up @@ -48,7 +44,7 @@ $ ->
events:
'click .check': 'toggleDone'
'click .todo-destroy': 'clear'
'dblclick .todo-content': 'edit'
'dblclick .todo-text': 'edit'
'keypress .todo-input': 'updateOnEnter'

initialize: ->
Expand All @@ -57,15 +53,15 @@ $ ->

render: =>
$(@el).html @template(@model.toJSON())
@setContent()
@setText()
return this

setContent: ->
content = @model.get('content')
@$('.todo-content').text(content)
setText: ->
text = @model.get('text')
@$('.todo-text').text(text)
@input = @$('.todo-input')
@input.bind('blur', @close)
.val(content)
.val(text)

toggleDone: ->
@model.toggle()
Expand All @@ -75,7 +71,7 @@ $ ->
@input.focus()

close: =>
@model.save content: @input.val()
@model.save text: @input.val()
$(@el).removeClass('editing')

updateOnEnter: (event) ->
Expand Down Expand Up @@ -120,14 +116,10 @@ $ ->
addAll: =>
Todos.each(@addOne)

newAttributes: ->
content: @input.val()
order: Todos.nextOrder()
done: false

createOnEnter: (event) ->
if event.keyCode is 13
Todos.create @newAttributes()
text = @input.val()
if text and event.keyCode is 13
Todos.create(text: text)
@input.val('')

clearCompleted: ->
Expand Down
2 changes: 1 addition & 1 deletion todos.css
Expand Up @@ -149,7 +149,7 @@ html {
margin: 0 10px 0 7px;
float: left;
}
#todo-list .done .todo-content {
#todo-list .done .todo-text {
text-decoration: line-through;
color: #777777;
}
Expand Down

0 comments on commit 927c2b0

Please sign in to comment.