Commit f11f1ace authored by Sindre Sorhus's avatar Sindre Sorhus

Convert almost all apps to trigger editing mode on `<label>` instead of `.view`

The rest will get individual tickets.

Puh… 😓

Followup to #227
parent 30585ce6
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
this.view.$().toggleClass( 'completed', this.model.get('completed') ); this.view.$().toggleClass( 'completed', this.model.get('completed') );
app.updateStatus(); app.updateStatus();
}, },
'dblclick .view': function() { 'dblclick label': function() {
this.view.$().addClass('editing'); this.view.$().addClass('editing');
this.view.$('.edit').focus(); this.view.$('.edit').focus();
}, },
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
<input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)"> <input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)">
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list"> <ul id="todo-list">
<li ng-repeat="todo in todos | filter:statusFilter" ng-dblclick="editTodo(todo)" ng-class="{completed: todo.completed, editing: todo == editedTodo}"> <li ng-repeat="todo in todos | filter:statusFilter" ng-class="{completed: todo.completed, editing: todo == editedTodo}">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed" ng-change="todoCompleted(todo)"> <input class="toggle" type="checkbox" ng-model="todo.completed" ng-change="todoCompleted(todo)">
<label>{{todo.title}}</label> <label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(todo)"></button> <button class="destroy" ng-click="removeTodo(todo)"></button>
</div> </div>
<form ng-submit="doneEditing(todo)"> <form ng-submit="doneEditing(todo)">
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
<input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)"> <input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)">
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list"> <ul id="todo-list">
<li ng-repeat="todo in todos | filter:statusFilter" ng-dblclick="editTodo(todo)" ng-class="{completed: todo.completed, editing: todo == editedTodo}"> <li ng-repeat="todo in todos | filter:statusFilter" ng-class="{completed: todo.completed, editing: todo == editedTodo}">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed"> <input class="toggle" type="checkbox" ng-model="todo.completed">
<label>{{todo.title}}</label> <label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(todo)"></button> <button class="destroy" ng-click="removeTodo(todo)"></button>
</div> </div>
<form ng-submit="doneEditing(todo)"> <form ng-submit="doneEditing(todo)">
......
...@@ -18,7 +18,7 @@ $(function() { ...@@ -18,7 +18,7 @@ $(function() {
// The DOM events specific to an item. // The DOM events specific to an item.
events: { events: {
'click .toggle': 'togglecompleted', 'click .toggle': 'togglecompleted',
'dblclick .view': 'edit', 'dblclick label': 'edit',
'click .destroy': 'clear', 'click .destroy': 'clear',
'keypress .edit': 'updateOnEnter', 'keypress .edit': 'updateOnEnter',
'blur .edit': 'close' 'blur .edit': 'close'
......
...@@ -44,7 +44,7 @@ jQuery(function( $ ) { ...@@ -44,7 +44,7 @@ jQuery(function( $ ) {
this.$toggleAll.on( 'change', this.toggleAll ); this.$toggleAll.on( 'change', this.toggleAll );
this.$footer.on( 'click', '#clear-completed', this.destroyCompleted ); this.$footer.on( 'click', '#clear-completed', this.destroyCompleted );
list.on( 'change', '.toggle', this.toggle ); list.on( 'change', '.toggle', this.toggle );
list.on( 'dblclick', '.view', this.edit ); list.on( 'dblclick', 'label', this.edit );
list.on( 'keypress', '.edit', this.blurOnEnter ); list.on( 'keypress', '.edit', this.blurOnEnter );
list.on( 'blur', '.edit', this.update ); list.on( 'blur', '.edit', this.update );
list.on( 'click', '.destroy', this.destroy ); list.on( 'click', '.destroy', this.destroy );
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list" data-bind="foreach: todos.todos"> <ul id="todo-list" data-bind="foreach: todos.todos">
<li data-bind="css: {completed: completed, editing: editing}, visible: visible"> <li data-bind="css: {completed: completed, editing: editing}, visible: visible">
<div class="view" data-bind="event: {dblclick: onCheckEditBegin}"> <div class="view">
<input class="toggle" type="checkbox" data-bind="checked: completed" checked> <input class="toggle" type="checkbox" data-bind="checked: completed" checked>
<label data-bind="text: title"></label> <label data-bind="text: title, event: {dblclick: onCheckEditBegin}"></label>
<button class="destroy" data-bind="click: onDestroyTodo"></button> <button class="destroy" data-bind="click: onDestroyTodo"></button>
</div> </div>
<input class="edit" type="text" data-bind="value: title, selectAndFocus: editing, event: {blur: onCheckEditEnd, keyup: onCheckEditEnd}"> <input class="edit" type="text" data-bind="value: title, selectAndFocus: editing, event: {blur: onCheckEditEnd, keyup: onCheckEditEnd}">
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
$(function() { $(function() {
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var __hasProp = {}.hasOwnProperty, var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.Todo = (function(_super) { window.Todo = (function(_super) {
__extends(Todo, _super); __extends(Todo, _super);
Todo.name = 'Todo';
function Todo() { function Todo() {
return Todo.__super__.constructor.apply(this, arguments); return Todo.__super__.constructor.apply(this, arguments);
} }
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var __hasProp = {}.hasOwnProperty, var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.TodoCollection = (function(_super) { window.TodoCollection = (function(_super) {
__extends(TodoCollection, _super); __extends(TodoCollection, _super);
TodoCollection.name = 'TodoCollection';
function TodoCollection() { function TodoCollection() {
return TodoCollection.__super__.constructor.apply(this, arguments); return TodoCollection.__super__.constructor.apply(this, arguments);
} }
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var __hasProp = {}.hasOwnProperty, var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.AppRouter = (function(_super) { window.AppRouter = (function(_super) {
__extends(AppRouter, _super); __extends(AppRouter, _super);
AppRouter.name = 'AppRouter';
function AppRouter() { function AppRouter() {
return AppRouter.__super__.constructor.apply(this, arguments); return AppRouter.__super__.constructor.apply(this, arguments);
} }
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
window.FooterViewModel = function(todos) { window.FooterViewModel = function(todos) {
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var ENTER_KEY; var ENTER_KEY;
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
window.SettingsViewModel = function() { window.SettingsViewModel = function() {
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var TodoViewModel; var TodoViewModel;
...@@ -44,8 +44,7 @@ ...@@ -44,8 +44,7 @@
}; };
this.onCheckEditBegin = function() { this.onCheckEditBegin = function() {
if (!_this.editing() && !_this.completed()) { if (!_this.editing() && !_this.completed()) {
_this.editing(true); return _this.editing(true);
return;
} }
}; };
this.onCheckEditEnd = function(view_model, event) { this.onCheckEditEnd = function(view_model, event) {
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list" data-bind="foreach: filteredTodos"> <ul id="todo-list" data-bind="foreach: filteredTodos">
<li data-bind="css: { completed: completed, editing: editing }"> <li data-bind="css: { completed: completed, editing: editing }">
<div class="view" data-bind="event: { dblclick: $root.editItem }"> <div class="view">
<input class="toggle" data-bind="checked: completed" type="checkbox"> <input class="toggle" data-bind="checked: completed" type="checkbox">
<label data-bind="text: title"></label> <label data-bind="text: title, event: { dblclick: $root.editItem }"></label>
<button class="destroy" data-bind="click: $root.remove"></button> <button class="destroy" data-bind="click: $root.remove"></button>
</div> </div>
<input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }"> <input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }">
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var TodoApp, var TodoApp,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
TodoApp = (function(_super) { TodoApp = (function(_super) {
var ENTER_KEY; var ENTER_KEY;
__extends(TodoApp, _super); __extends(TodoApp, _super);
TodoApp.name = 'TodoApp';
ENTER_KEY = 13; ENTER_KEY = 13;
TodoApp.prototype.elements = { TodoApp.prototype.elements = {
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.Todos = (function(_super) { window.Todos = (function(_super) {
var ENTER_KEY, TPL; var ENTER_KEY, TPL;
__extends(Todos, _super); __extends(Todos, _super);
Todos.name = 'Todos';
ENTER_KEY = 13; ENTER_KEY = 13;
TPL = Handlebars.compile($('#todo-template').html()); TPL = Handlebars.compile($('#todo-template').html());
...@@ -22,7 +20,7 @@ ...@@ -22,7 +20,7 @@
Todos.prototype.events = { Todos.prototype.events = {
'click .destroy': 'remove', 'click .destroy': 'remove',
'click .toggle': 'toggleStatus', 'click .toggle': 'toggleStatus',
'dblclick .view': 'edit', 'dblclick label': 'edit',
'keyup .edit': 'finishEditOnEnter', 'keyup .edit': 'finishEditOnEnter',
'blur .edit': 'finishEdit' 'blur .edit': 'finishEdit'
}; };
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var __hasProp = {}.hasOwnProperty, var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.Todo = (function(_super) { window.Todo = (function(_super) {
__extends(Todo, _super); __extends(Todo, _super);
Todo.name = 'Todo';
function Todo() { function Todo() {
return Todo.__super__.constructor.apply(this, arguments); return Todo.__super__.constructor.apply(this, arguments);
} }
......
...@@ -8,7 +8,7 @@ class window.Todos extends Spine.Controller ...@@ -8,7 +8,7 @@ class window.Todos extends Spine.Controller
events: events:
'click .destroy': 'remove' 'click .destroy': 'remove'
'click .toggle': 'toggleStatus' 'click .toggle': 'toggleStatus'
'dblclick .view': 'edit' 'dblclick label': 'edit'
'keyup .edit': 'finishEditOnEnter' 'keyup .edit': 'finishEditOnEnter'
'blur .edit': 'finishEdit' 'blur .edit': 'finishEdit'
......
...@@ -16,7 +16,7 @@ YUI.add('todo-view', function (Y) { ...@@ -16,7 +16,7 @@ YUI.add('todo-view', function (Y) {
'.toggle': { '.toggle': {
click: 'toggleComplete' click: 'toggleComplete'
}, },
'.view': { 'label': {
dblclick: 'edit' dblclick: 'edit'
}, },
'.edit': { '.edit': {
......
...@@ -15,7 +15,7 @@ define([ ...@@ -15,7 +15,7 @@ define([
// The DOM events specific to an item. // The DOM events specific to an item.
events: { events: {
'click .toggle': 'togglecompleted', 'click .toggle': 'togglecompleted',
'dblclick .view': 'edit', 'dblclick label': 'edit',
'click .destroy': 'clear', 'click .destroy': 'clear',
'keypress .edit': 'updateOnEnter', 'keypress .edit': 'updateOnEnter',
'blur .edit': 'close' 'blur .edit': 'close'
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
<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">
<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" data-event-doubleclick="toggleEditing"></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"
......
...@@ -122,7 +122,7 @@ define({ ...@@ -122,7 +122,7 @@ define({
'click:.destroy': 'removeTodo', 'click:.destroy': 'removeTodo',
'change:.toggle': 'updateTodo', 'change:.toggle': 'updateTodo',
'click:#toggle-all': 'toggleAll', 'click:#toggle-all': 'toggleAll',
'dblclick:.view': 'todos.edit', 'dblclick:label': 'todos.edit',
'change,focusout:.edit': 'todos.submit' // also need way to submit on [enter] 'change,focusout:.edit': 'todos.submit' // also need way to submit on [enter]
}, },
controlsView: { controlsView: {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
var id = $( this ).closest('li').data('id'); var id = $( this ).closest('li').data('id');
self.system.notify( 'TodoListView:toggleDoneOfTodo', id ); self.system.notify( 'TodoListView:toggleDoneOfTodo', id );
}); });
$todoList.on( 'dblclick', '.view', function() { $todoList.on( 'dblclick', 'label', function() {
$( this ).closest('li').addClass('editing').find('.edit').focus(); $( this ).closest('li').addClass('editing').find('.edit').focus();
} ); } );
$todoList.on( 'keypress', '.edit', function( e ) { $todoList.on( 'keypress', '.edit', function( e ) {
......
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
<%-- could have embedded in 'tasks' for-loop, but this allows us to add single tasks --%> <%-- could have embedded in 'tasks' for-loop, but this allows us to add single tasks --%>
<li class="<%= data.completed ? 'complete' : '' %>" <li class="<%= data.completed ? 'complete' : '' %>">
ondblclick="<%= todos.actions.content_dblclick(data.id) %>">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" checked="<%= data.completed %>" <input class="toggle" type="checkbox" checked="<%= data.completed %>"
onchange="<%= todos.actions.completed_change(data.id) %>"> onchange="<%= todos.actions.completed_change(data.id) %>">
<label><%= data.title %></label> <label ondblclick="<%= todos.actions.content_dblclick(data.id) %>"><%= data.title %></label>
<button class="destroy" onclick="<%= todos.actions.remove_click(data.id) %>"></button> <button class="destroy" onclick="<%= todos.actions.remove_click(data.id) %>"></button>
</div> </div>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
'click:relay(input.toggle)': 'statusChange', 'click:relay(input.toggle)': 'statusChange',
'keypress:relay(input.edit)': 'handleKeypress', 'keypress:relay(input.edit)': 'handleKeypress',
'click:relay(button.destroy)': 'removeItem', 'click:relay(button.destroy)': 'removeItem',
'dblclick:relay(li)': 'editing' 'dblclick:relay(label)': 'editing'
}, },
// define actual event handlers // define actual event handlers
...@@ -64,8 +64,9 @@ ...@@ -64,8 +64,9 @@
e.stop(); e.stop();
} }
el.addClass( this.options.editingClass ); var container = el.getParent('li');
el.getElement( this.options.input ).focus(); container.addClass( this.options.editingClass );
container.getElement( this.options.input ).focus();
}, },
// when enter pressed while editing // when enter pressed while editing
......
...@@ -76,7 +76,7 @@ if Meteor.is_client ...@@ -76,7 +76,7 @@ if Meteor.is_client
'click .destroy': (evt) -> 'click .destroy': (evt) ->
Template.item.updateTask this._id, null Template.item.updateTask this._id, null
'dblclick .view': (evt) -> 'dblclick label': (evt) ->
# do not response to double click on checkbox # do not response to double click on checkbox
return if $(evt.target).hasClass('toggle') return if $(evt.target).hasClass('toggle')
......
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
</div> </div>
<ul id="todo-list" data-bind="foreach: todos"> <ul id="todo-list" data-bind="foreach: todos">
<li data-bind="class: klass; visible; dblclick: startEditing"> <li data-bind="class: klass; visible">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" data-bind="value: completed"> <input class="toggle" type="checkbox" data-bind="value: completed">
<label data-bind="text: title"></label> <label data-bind="text: title; dblclick: startEditing"></label>
<button class="destroy" data-bind="click: remove"></button> <button class="destroy" data-bind="click: remove"></button>
</div> </div>
<input class="edit" data-bind="value: title; enterKey: stopEditing; blur: stopEditing"> <input class="edit" data-bind="value: title; enterKey: stopEditing; blur: stopEditing">
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list" data-model="foreach"> <ul id="todo-list" data-model="foreach">
<li data-model="bind:toggleClass,completed,completed;"> <li data-model="bind:toggleClass,completed,completed;">
<div class="view" data-event="listen:dblclick,startEdit"> <div class="view">
<input class="toggle" type="checkbox" data-model="bind:checked,completed"> <input class="toggle" type="checkbox" data-model="bind:checked,completed">
<label data-model="bind:innerHTML,title"></label> <label data-model="bind:innerHTML,title" data-event="listen:dblclick,startEdit"></label>
<button class="destroy" data-event="listen:click,remove"></button> <button class="destroy" data-event="listen:click,remove"></button>
</div> </div>
<input class="edit" data-model="bind:value,title" data-event="listen:keydown,stopEdit; listen:blur,stopEdit"> <input class="edit" data-model="bind:value,title" data-event="listen:keydown,stopEdit; listen:blur,stopEdit">
......
...@@ -72,10 +72,10 @@ ...@@ -72,10 +72,10 @@
]]> ]]>
</js:Script> </js:Script>
<js:Template name="layout"> <js:Template name="layout">
<div class="view" ondblclick="editTodo"> <div class="view">
<input class="toggle" type="checkbox" onclick="checkTodo" ondblclick="preventEditing" <input class="toggle" type="checkbox" onclick="checkTodo" ondblclick="preventEditing"
checked="{todo.completed}"/> checked="{todo.completed}"/>
<label>{todo.title}</label> <label ondblclick="editTodo">{todo.title}</label>
<button class="destroy" onclick="triggerOnRemove"/> <button class="destroy" onclick="triggerOnRemove"/>
</div> </div>
<input class="edit" cid="inputElement" type="text" value="{{todo.title|trim()}}" <input class="edit" cid="inputElement" type="text" value="{{todo.title|trim()}}"
......
...@@ -36,7 +36,7 @@ var App = { ...@@ -36,7 +36,7 @@ var App = {
this.$toggleAll.on( 'change', this.toggleAll ); this.$toggleAll.on( 'change', this.toggleAll );
this.$footer.on( 'click', '#clear-completed', this.destroyCompleted ); this.$footer.on( 'click', '#clear-completed', this.destroyCompleted );
list.on( 'change', '.toggle', this.toggle ); list.on( 'change', '.toggle', this.toggle );
list.on( 'dblclick', '.view', this.edit ); list.on( 'dblclick', 'label', this.edit );
list.on( 'keypress', '.edit', this.blurOnEnter ); list.on( 'keypress', '.edit', this.blurOnEnter );
list.on( 'blur', '.edit', this.update ); list.on( 'blur', '.edit', this.update );
list.on( 'click', '.destroy', this.destroy ); list.on( 'click', '.destroy', this.destroy );
......
...@@ -12,7 +12,7 @@ var todo = window.todo || {}; ...@@ -12,7 +12,7 @@ var todo = window.todo || {};
this.template = Handlebars.compile( $( '#' + this.domElement.id + '-template' ).html() ); this.template = Handlebars.compile( $( '#' + this.domElement.id + '-template' ).html() );
$( this.domElement ).on( 'click', '.destroy', this.destroy.bind( this ) ); $( this.domElement ).on( 'click', '.destroy', this.destroy.bind( this ) );
$( this.domElement ).on( 'click', '.toggle', this.toggle.bind( this ) ); $( this.domElement ).on( 'click', '.toggle', this.toggle.bind( this ) );
$( this.domElement ).on( 'dblclick', '.view', this.edit ); $( this.domElement ).on( 'dblclick', 'label', this.edit );
$( this.domElement ).on( 'blur', '.edit', this.update.bind( this ) ); $( this.domElement ).on( 'blur', '.edit', this.update.bind( this ) );
$( this.domElement ).on( 'keypress', '.edit', this.blurInput ); $( this.domElement ).on( 'keypress', '.edit', this.blurInput );
$('#toggle-all').click( this.toggleAll ); $('#toggle-all').click( this.toggleAll );
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
todoView.emit(event, $(this).parents('li').data('id')); todoView.emit(event, $(this).parents('li').data('id'));
}); });
$('#todo-list').on('dblclick', 'li', function(e) { $('#todo-list').on('dblclick', 'label', function(e) {
todoView.emit('edittodo', $(this).data('id')); todoView.emit('edittodo', $(this).closest('li').data('id'));
}); });
$('#todo-list').on('keyup focusout', 'input.edit', function(e) { $('#todo-list').on('keyup focusout', 'input.edit', function(e) {
......
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
<input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)"> <input id="toggle-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)">
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list"> <ul id="todo-list">
<li ng-repeat="todo in todos | filter:statusFilter" ng-dblclick="editTodo(todo)" ng-class="{completed: todo.completed, editing: todo == editedTodo}"> <li ng-repeat="todo in todos | filter:statusFilter" ng-class="{completed: todo.completed, editing: todo == editedTodo}">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed"> <input class="toggle" type="checkbox" ng-model="todo.completed">
<label>{{todo.title}}</label> <label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(todo)"></button> <button class="destroy" ng-click="removeTodo(todo)"></button>
</div> </div>
<form ng-submit="doneEditing(todo)"> <form ng-submit="doneEditing(todo)">
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
<label for="toggle-all">Mark all as complete</label> <label for="toggle-all">Mark all as complete</label>
<ul id="todo-list" data-bind="foreach: todos"> <ul id="todo-list" data-bind="foreach: todos">
<li data-bind="css: { completed: completed, editing: editing }"> <li data-bind="css: { completed: completed, editing: editing }">
<div class="view" data-bind="event: { dblclick: $root.editItem }"> <div class="view">
<input class="toggle" type="checkbox" data-bind="checked: completed"> <input class="toggle" type="checkbox" data-bind="checked: completed">
<label data-bind="text: title"></label> <label data-bind="text: title, event: { dblclick: $root.editItem }"></label>
<button class="destroy" data-bind="click: $root.remove"></button> <button class="destroy" data-bind="click: $root.remove"></button>
</div> </div>
<input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }" > <input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }" >
......
...@@ -23,8 +23,8 @@ define(['lib/stapes'], function(Stapes) { ...@@ -23,8 +23,8 @@ define(['lib/stapes'], function(Stapes) {
todoView.emit(event, $(this).parents('li').data('id')); todoView.emit(event, $(this).parents('li').data('id'));
}); });
$('#todo-list').on('dblclick', 'li', function(e) { $('#todo-list').on('dblclick', 'label', function(e) {
todoView.emit('edittodo', $(this).data('id')); todoView.emit('edittodo', $(this).closest('li').data('id'));
}); });
$('#todo-list').on('keyup focusout', 'input.edit', function(e) { $('#todo-list').on('keyup focusout', 'input.edit', function(e) {
......
...@@ -206,6 +206,7 @@ ...@@ -206,6 +206,7 @@
label = document.createElement('label'); label = document.createElement('label');
label.setAttribute( 'data-todo-id', todo.id ); label.setAttribute( 'data-todo-id', todo.id );
label.appendChild( document.createTextNode( todo.title ) ); label.appendChild( document.createTextNode( todo.title ) );
label.addEventListener( 'dblclick', todoContentHandler );
// create delete button // create delete button
...@@ -221,8 +222,6 @@ ...@@ -221,8 +222,6 @@
divDisplay.appendChild( checkbox ); divDisplay.appendChild( checkbox );
divDisplay.appendChild( label ); divDisplay.appendChild( label );
divDisplay.appendChild( deleteLink ); divDisplay.appendChild( deleteLink );
divDisplay.addEventListener( 'dblclick', todoContentHandler );
// create todo input // create todo input
inputEditTodo = document.createElement('input'); inputEditTodo = document.createElement('input');
......
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