Skip to content

Commit

Permalink
state management changes, no touch events when editing
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 18, 2012
1 parent 274bd69 commit 9f6aa5e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions js/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ C.Collection = (function (raf) {
this.upperBound = 0;
this.initiated = false;

// the data object points directly to the data inside the DB module.
this.data = data || C.db.data;

this.items = [];
this.render();
this.initDummyItems();
Expand Down
12 changes: 5 additions & 7 deletions js/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ C.Item = (function (raf) {

onTap: function (e) {

if (C.state === C.states.EDITING) return;

// check to see if tap is on the text or the item itself

if (this.open) {
Expand All @@ -123,8 +121,6 @@ C.Item = (function (raf) {

onDragMove: function (dx) {

if (C.state === C.states.EDITING) return;

// the desired x position
var tx = this.x + dx;

Expand Down Expand Up @@ -318,10 +314,11 @@ C.Item = (function (raf) {

},

// noRemember: tell collection don't remember starting position
// noRemember:
// tells parent collection to ignore starting position and always move to 0 when edit is done.
onEditStart: function (noRemember) {

C.state = C.states.EDITING;
C.isEditing = true;

this.title.hide();
this.field.show().focus();
Expand All @@ -338,8 +335,9 @@ C.Item = (function (raf) {

t.collection.onEditDone(function () {

C.isEditing = false;

t.el.removeClass('edit');
C.state = C.states.TODOS;

if (!val) {
t.del();
Expand Down
20 changes: 8 additions & 12 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ var C = {
$wrapper: $('#wrapper'),
$log: $('#log'),

// states
// view states
states: {
LISTS: 0,
TODOS: 1,
EDITING: 2
LISTS: 'lists',
TODOS: 'todos'
},

isEditing: false,

ITEM_HEIGHT: 62,

init: function () {
Expand All @@ -33,18 +34,13 @@ var C = {

switch (state.view) {

case C.states.MENU:
C.log('App: init at menu.');
C.currentCollection = C.menu;
break;

case C.states.LISTS:
C.log('App: init at lists.');
C.log('App: init at ListCollection.');
C.currentCollection = C.listCollection;
break;

case C.states.TODOS:
C.log('App: init at list with order: ' + state.order);
C.log('App: init at TodoCollection with order: ' + state.order);
while (i--) {
if (lists[i].order === state.order) {
C.currentCollection = new C.TodoCollection(lists[i]);
Expand All @@ -54,7 +50,7 @@ var C = {
break;

default:
C.log('App: init at lists.');
C.log('App: init at ListCollection.');
C.currentCollection = C.listCollection;
break;

Expand Down
15 changes: 11 additions & 4 deletions js/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ C.touch = (function () {
C.$wrapper
.on(start, function (e) {

// no touch events during editng.
if (C.isEditing) return;

// only record two fingers
// and ignore additional fingers if already in action
if (touches.length >= 2 || currentAction) return;
Expand All @@ -95,7 +98,7 @@ C.touch = (function () {
var touch = new TouchData(e);
touches.push(touch);

// process actions
// process actions ======================================================

if (touches.length > 1) {
actions.pinch.start();
Expand All @@ -108,6 +111,8 @@ C.touch = (function () {
})
.on(move, function (e) {

if (C.isEditing) return;

// for mousemove
if (!touches.length) return;

Expand All @@ -121,7 +126,7 @@ C.touch = (function () {
return; // ignore touches not in list
}

//process actions
// process actions ======================================================

actions.itemSort.cancelTimeout();

Expand All @@ -136,6 +141,8 @@ C.touch = (function () {
})
.on(end, function (e) {

if (C.isEditing) return;

e = t ? e.changedTouches[0] : e;
var id = e.identifier || 'mouse';
var i = getTouchIndex(id);
Expand All @@ -148,7 +155,7 @@ C.touch = (function () {
pub.isDown = false;
}

// process actions
// process actions ======================================================

actions.itemSort.cancelTimeout();

Expand All @@ -161,7 +168,7 @@ C.touch = (function () {
currentAction = null;
}

// delete afterwards
// delete afterwards.
touches.splice(i, 1);

});
Expand Down

0 comments on commit 9f6aa5e

Please sign in to comment.