Merge pull request #4096 from RoonyH/3897-submit_a_comment_by_shift+enter
3897 submit a comment by shift+enter
This commit is contained in:
commit
7a0d1c647a
5 changed files with 63 additions and 2 deletions
|
|
@ -131,6 +131,7 @@ by them self.
|
|||
* Add hotkeys to navigate in stream [#4089](https://github.com/diaspora/diaspora/pull/4089)
|
||||
* Add a brief explanatory text about external services connections to services index page [#3064](https://github.com/diaspora/diaspora/issues/3064)
|
||||
* Add a preview for posts in the stream [#4099](https://github.com/diaspora/diaspora/issues/4099)
|
||||
* Add shortcut key Shift to submit comments and publish posts. [#4096](github.com/diaspora/diaspora/pull/4096)
|
||||
|
||||
# 0.0.3.4
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ app.views.CommentStream = app.views.Base.extend({
|
|||
className : "comment_stream",
|
||||
|
||||
events: {
|
||||
"keydown .comment_box": "keyDownOnCommentBox",
|
||||
"submit form": "createComment",
|
||||
"focus .comment_box": "commentTextareaFocused",
|
||||
"click .toggle_post_comments": "expandComments"
|
||||
|
|
@ -51,6 +52,13 @@ app.views.CommentStream = app.views.Base.extend({
|
|||
}
|
||||
},
|
||||
|
||||
keyDownOnCommentBox: function(evt) {
|
||||
if(evt.keyCode == 13 && evt.shiftKey) {
|
||||
this.$("form").submit()
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
appendComment: function(comment) {
|
||||
// Set the post as the comment's parent, so we can check
|
||||
// on post ownership in the Comment view.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
el : "#publisher",
|
||||
|
||||
events : {
|
||||
"keydown #status_message_fake_text" : "keyDown",
|
||||
"focus textarea" : "open",
|
||||
"click #hide_publisher" : "clear",
|
||||
"submit form" : "createStatusMessage",
|
||||
|
|
@ -89,7 +90,7 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
// clear state
|
||||
this.clear();
|
||||
},
|
||||
|
||||
|
||||
createPostPreview : function(evt) {
|
||||
if(evt){ evt.preventDefault(); }
|
||||
|
||||
|
|
@ -167,6 +168,14 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
}
|
||||
},
|
||||
|
||||
keyDown : function(evt) {
|
||||
if( evt.keyCode == 13 && evt.shiftKey ) {
|
||||
this.$("form").submit();
|
||||
this.open();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
clear : function() {
|
||||
// clear text(s)
|
||||
this.el_input.val('');
|
||||
|
|
@ -206,7 +215,6 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
|
||||
// fetch contacts for mentioning
|
||||
Mentions.fetchContacts();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -80,4 +80,32 @@ describe("app.views.CommentStream", function(){
|
|||
expect(this.view.$("textarea").val()).toEqual("great post!");
|
||||
})
|
||||
})
|
||||
|
||||
describe("pressing a key when typing on the new comment box", function(){
|
||||
it("should not submit the form when enter key is pressed", function(){
|
||||
this.view.render();
|
||||
var form = this.view.$("form")
|
||||
var submitCallback = jasmine.createSpy().andReturn(false);form.submit(submitCallback);
|
||||
|
||||
var e = $.Event("keydown", { keyCode: 13 });
|
||||
e.shiftKey = false;
|
||||
this.view.keyDownOnCommentBox(e);
|
||||
|
||||
expect(submitCallback).not.toHaveBeenCalled();
|
||||
})
|
||||
|
||||
it("should submit the form when enter is pressed with shift", function(){
|
||||
this.view.render();
|
||||
var form = this.view.$("form")
|
||||
var submitCallback = jasmine.createSpy().andReturn(false);
|
||||
form.submit(submitCallback);
|
||||
|
||||
var e = $.Event("keydown", { keyCode: 13 });
|
||||
e.shiftKey = true;
|
||||
this.view.keyDownOnCommentBox(e);
|
||||
|
||||
expect(submitCallback).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -106,6 +106,22 @@ describe("app.views.Publisher", function() {
|
|||
expect(this.view.$("input[name='photos[]']").length).toBe(0);
|
||||
})
|
||||
});
|
||||
|
||||
describe("publishing a post with keyboard", function(){
|
||||
it("should submit the form when shift+enter is pressed", function(){
|
||||
this.view.render();
|
||||
var form = this.view.$("form")
|
||||
var submitCallback = jasmine.createSpy().andReturn(false);
|
||||
form.submit(submitCallback);
|
||||
|
||||
var e = $.Event("keydown", { keyCode: 13 });
|
||||
e.shiftKey = true;
|
||||
this.view.keyDown(e);
|
||||
|
||||
expect(submitCallback).toHaveBeenCalled();
|
||||
expect($(this.view.el)).not.toHaveClass("closed");
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
context("#toggleService", function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue