From 4ed3c1c6eb19087ce1c98ba8f6ebf21062f84ec2 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Mon, 11 May 2015 20:10:42 -0700 Subject: [PATCH] Make inserting work correctly visually --- dist/flowy.js | 10 ++++------ dist/flowy.unwrapped.js | 10 ++++------ src/views/app.js | 2 +- src/views/todo.js | 8 +++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/dist/flowy.js b/dist/flowy.js index 35b3122..99d7cf9 100644 --- a/dist/flowy.js +++ b/dist/flowy.js @@ -109,13 +109,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; }, @@ -252,7 +250,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/dist/flowy.unwrapped.js b/dist/flowy.unwrapped.js index a4d114f..e956425 100644 --- a/dist/flowy.unwrapped.js +++ b/dist/flowy.unwrapped.js @@ -108,13 +108,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; }, @@ -251,7 +249,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/src/views/app.js b/src/views/app.js index 636cb22..202c746 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -8,7 +8,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/src/views/todo.js b/src/views/todo.js index 48a4501..145ab7b 100644 --- a/src/views/todo.js +++ b/src/views/todo.js @@ -108,13 +108,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; }, -- 2.47.3