Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,17 @@ var StoryView = Backbone.View.extend({
this.$(".story-starred > i").attr("class", icon);
},

storyClicked: function() {
this.model.toggle();
window.scrollTo(0, this.$el.offset().top);
storyClicked: function(e) {
if (e.metaKey || e.ctrlKey || e.which == 2) {
var background_tab = window.open(this.model.get("permalink"));
background_tab.blur();
window.focus();
if (!this.model.get("keep_unread")) this.model.set("is_read", true);
if (this.model.shouldSave()) this.model.save();
} else {
this.model.toggle();
window.scrollTo(0, this.$el.offset().top);
}
},

toggleKeepUnread: function() {
Expand Down Expand Up @@ -253,7 +261,7 @@ var AppView = Backbone.View.extend({

render: function() {
var unreadCount = this.stories.unreadCount();

if (unreadCount === 0) {
document.title = window.i18n.titleName;
} else {
Expand Down
38 changes: 35 additions & 3 deletions spec/javascript/spec/views/story_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("Storyiew", function(){
this.story.set("keep_unread", true);
this.view.render();

assertTagExists(this.view.$el, ".story-keep-unread .icon-check");
assertTagExists(this.view.$el, ".story-keep-unread .icon-check");
});

it("should render two instances of the star button", function(){
Expand All @@ -101,7 +101,39 @@ describe("Storyiew", function(){
this.story.set("is_starred", true);
this.view.render();

assertTagExists(this.view.$el, ".story-starred .icon-star", 2);
assertTagExists(this.view.$el, ".story-starred .icon-star", 2);
});

describe("Handling click on story", function(){
beforeEach(function() {
this.toggle_stub = sinon.stub(this.story, "toggle");
});

afterEach(function() {
this.toggle_stub.restore();
});

it("should open story when clicked on it", function(){
this.view.$('.story-preview').click();
this.toggle_stub.should.have.been.calledOnce;
});

it("should not open story when clicked on it with metaKey pressed", function(){
var e = jQuery.Event("click");
e.metaKey = true;
this.view.$('.story-preview').trigger(e);

this.toggle_stub.should.not.have.been.calledOnce;
});

it("should not open story when clicked on it with ctrlKey pressed", function(){
var e = jQuery.Event("click");
e.ctrlKey = true;
this.view.$('.story-preview').trigger(e);

this.toggle_stub.should.not.have.been.calledOnce;
});
});

});
});
});