Skip to content

Commit 9765381

Browse files
author
Matt Swanson
committed
allow wraparound. fix multiple rendering backbone issues.
1 parent cbb49e7 commit 9765381

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎app/public/js/app.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,33 @@ var StoryView = Backbone.View.extend({
7878

7979
initialize: function() {
8080
this.template = _.template($(this.template).html());
81-
this.listenTo(this.model, 'change', this.render);
81+
this.listenTo(this.model, 'add', this.render);
82+
this.listenTo(this.model, 'change:selected', this.itemSelected);
83+
this.listenTo(this.model, 'change:open', this.itemOpened);
84+
this.listenTo(this.model, 'change:is_read', this.itemRead);
8285
},
8386

8487
render: function() {
8588
this.$el.html(this.template(this.model.toJSON()));
89+
return this;
90+
},
8691

92+
itemRead: function() {
8793
this.$el.toggleClass("read", this.model.get("is_read"));
94+
},
8895

96+
itemOpened: function() {
8997
if (this.model.get("open")) {
9098
this.$el.addClass("open");
9199
$(".story-lead", this.$el).fadeOut(1000);
92100
} else {
93101
this.$el.removeClass("open");
94102
$(".story-lead", this.$el).show();
95103
}
104+
},
96105

106+
itemSelected: function() {
97107
this.$el.toggleClass("cursor", this.model.get("selected"));
98-
99-
return this;
100108
},
101109

102110
storyClicked: function() {
@@ -153,6 +161,8 @@ var StoryList = Backbone.Collection.extend({
153161
moveCursorDown: function() {
154162
if (this.cursorPosition < this.max_position()) {
155163
this.cursorPosition++;
164+
} else {
165+
this.cursorPosition = 0;
156166
}
157167

158168
this.at(this.cursorPosition).select();

0 commit comments

Comments
 (0)