Skip to content

Instantly share code, notes, and snippets.

@p-baleine
Created September 29, 2012 06:26
Show Gist options
  • Save p-baleine/3803356 to your computer and use it in GitHub Desktop.
Save p-baleine/3803356 to your computer and use it in GitHub Desktop.
editable on dblclick
#todo-list li.editing {
border-bottom: none;
padding: 0;
}
#todo-list li.editing .edit {
display: block;
width: 506px;
padding: 13px 17px 12px 17px;
margin: 0 0 0 43px;
}
#todo-list li.editing .view {
display: none;
}
#todo-list li .edit {
display: none;
}
<div class="view">
<input class="toggle" type="checkbox" />
<label><%- content %></label>
<button class="destroy"></button>
</div>
<input class="edit" value="<%- content %>" />
var _ = require('underscore')
, Backbone = require('backbone.js');
var TodoItem = module.exports = Backbone.View.extend({
tagName: 'li',
events: {
'dblclick label': 'edit',
'blur .edit': 'close'
},
render: function() {
this.$el.append(this.template(this.model.toJSON()));
return this;
},
edit: function() {
this.$el.addClass('editing');
this.$('.edit').focus();
},
close: function() {
this.model.save();
this.$el.removeClass('editing');
},
template: _.template(require('../templates/todo-item.js'))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment