Commit 85ff8a62 by alisan617 Committed by GitHub

Merge pull request #14476 from edx/alisan/post-add-response-focus-TNL-6170

Discussion thread bring focus to response list after submitting a response or comment
parents 31ec5621 813e8604
...@@ -62,9 +62,7 @@ ...@@ -62,9 +62,7 @@
DiscussionThreadView.prototype.events = { DiscussionThreadView.prototype.events = {
'click .discussion-submit-post': 'submitComment', 'click .discussion-submit-post': 'submitComment',
'click .add-response-btn': 'scrollToAddResponse', 'click .add-response-btn': 'scrollToAddResponse'
'click .forum-thread-expand': 'expand',
'click .forum-thread-collapse': 'collapse'
}; };
DiscussionThreadView.prototype.$ = function(selector) { DiscussionThreadView.prototype.$ = function(selector) {
...@@ -165,45 +163,6 @@ ...@@ -165,45 +163,6 @@
} }
}); });
DiscussionThreadView.prototype.expand = function(event) {
if (event) {
event.preventDefault();
}
this.$el.addClass('expanded');
this.$el.find('.post-body').text(this.model.get('body'));
this.showView.convertMath();
this.$el.find('.forum-thread-expand').hide();
this.$el.find('.forum-thread-collapse').show();
this.$el.find('.post-extended-content').show();
if (!this.loadedResponses) {
return this.loadInitialResponses();
}
};
DiscussionThreadView.prototype.collapse = function(event) {
if (event) {
event.preventDefault();
}
this.$el.removeClass('expanded');
this.$el.find('.post-body').text(this.getAbbreviatedBody());
this.showView.convertMath();
this.$el.find('.forum-thread-expand').show();
this.$el.find('.forum-thread-collapse').hide();
return this.$el.find('.post-extended-content').hide();
};
DiscussionThreadView.prototype.getAbbreviatedBody = function() {
var abbreviated, cached;
cached = this.model.get('abbreviatedBody');
if (cached) {
return cached;
} else {
abbreviated = DiscussionUtil.abbreviateString(this.model.get('body'), 140);
this.model.set('abbreviatedBody', abbreviated);
return abbreviated;
}
};
DiscussionThreadView.prototype.cleanup = function() { DiscussionThreadView.prototype.cleanup = function() {
// jQuery.ajax after 1.5 returns a jqXHR which doesn't implement .abort // jQuery.ajax after 1.5 returns a jqXHR which doesn't implement .abort
// but I don't feel confident enough about what's going on here to remove this code // but I don't feel confident enough about what's going on here to remove this code
...@@ -346,7 +305,10 @@ ...@@ -346,7 +305,10 @@
view.on('comment:endorse', this.endorseThread); view.on('comment:endorse', this.endorseThread);
view.render(); view.render();
this.$el.find(listSelector).append(view.el); this.$el.find(listSelector).append(view.el);
return view.afterInsert(); view.afterInsert();
if (options.focusAddedResponse) {
this.focusToTheAddedResponse(view.el);
}
}; };
DiscussionThreadView.prototype.renderAddResponseButton = function() { DiscussionThreadView.prototype.renderAddResponseButton = function() {
...@@ -394,7 +356,9 @@ ...@@ -394,7 +356,9 @@
user_id: window.user.get('id') user_id: window.user.get('id')
}); });
comment.set('thread', this.model.get('thread')); comment.set('thread', this.model.get('thread'));
this.renderResponseToList(comment, '.js-response-list'); this.renderResponseToList(comment, '.js-response-list', {
focusAddedResponse: true
});
this.model.addComment(); this.model.addComment();
this.renderAddResponseButton(); this.renderAddResponseButton();
return DiscussionUtil.safeAjax({ return DiscussionUtil.safeAjax({
...@@ -412,6 +376,10 @@ ...@@ -412,6 +376,10 @@
}); });
}; };
DiscussionThreadView.prototype.focusToTheAddedResponse = function(list) {
return $(list).attr('tabindex', '-1').focus();
};
DiscussionThreadView.prototype.edit = function() { DiscussionThreadView.prototype.edit = function() {
this.createEditView(); this.createEditView();
return this.renderEditView(); return this.renderEditView();
......
...@@ -174,6 +174,7 @@ ...@@ -174,6 +174,7 @@
return self.showCommentForm(); return self.showCommentForm();
}); });
this.commentViews.push(view); this.commentViews.push(view);
this.focusToTheCommentResponse(view.$el.closest('.forum-response'));
return view; return view;
}; };
...@@ -213,6 +214,10 @@ ...@@ -213,6 +214,10 @@
}); });
}; };
ThreadResponseView.prototype.focusToTheCommentResponse = function(list) {
return $(list).attr('tabindex', '-1').focus();
};
ThreadResponseView.prototype._delete = function(event) { ThreadResponseView.prototype._delete = function(event) {
var $elem, url; var $elem, url;
event.preventDefault(); event.preventDefault();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
$.ajax.calls.reset(); $.ajax.calls.reset();
return jasmine.clock().uninstall(); return jasmine.clock().uninstall();
}); });
renderWithContent = function(view, content) { renderWithContent = function(view, content) {
$.ajax.and.callFake(function(params) { $.ajax.and.callFake(function(params) {
params.success(createAjaxResponseJson(content, false), 'success'); params.success(createAjaxResponseJson(content, false), 'success');
...@@ -182,6 +183,7 @@ ...@@ -182,6 +183,7 @@
el: $('#fixture-element'), el: $('#fixture-element'),
course_settings: DiscussionSpecHelper.createTestCourseSettings() course_settings: DiscussionSpecHelper.createTestCourseSettings()
}); });
spyOn($.fn, 'focus');
}); });
describe('responses', function() { describe('responses', function() {
it('can post a first response', function() { it('can post a first response', function() {
...@@ -189,8 +191,9 @@ ...@@ -189,8 +191,9 @@
postResponse(this.view, 1); postResponse(this.view, 1);
expect(this.view.$('.forum-response').length).toBe(1); expect(this.view.$('.forum-response').length).toBe(1);
expect(this.view.$('.post-actions-list').find('.action-edit').parent('.is-hidden').length).toBe(1); expect(this.view.$('.post-actions-list').find('.action-edit').parent('.is-hidden').length).toBe(1);
return expect(this.view.$('.response-actions-list').find('.action-edit') expect(this.view.$('.response-actions-list').find('.action-edit')
.parent().not('.is-hidden').length).toBe(1); .parent().not('.is-hidden').length).toBe(1);
expect(document.activeElement === this.view.$('.forum-response')[0]);
}); });
it('can post a second response', function() { it('can post a second response', function() {
renderWithTestResponses(this.view, 1); renderWithTestResponses(this.view, 1);
...@@ -201,8 +204,9 @@ ...@@ -201,8 +204,9 @@
postResponse(this.view, 2); postResponse(this.view, 2);
expect(this.view.$('.forum-response').length).toBe(2); expect(this.view.$('.forum-response').length).toBe(2);
expect(this.view.$('.post-actions-list').find('.action-edit').parent('.is-hidden').length).toBe(1); expect(this.view.$('.post-actions-list').find('.action-edit').parent('.is-hidden').length).toBe(1);
return expect(this.view.$('.response-actions-list').find('.action-edit').parent() expect(this.view.$('.response-actions-list').find('.action-edit').parent()
.not('.is-hidden').length).toBe(2); .not('.is-hidden').length).toBe(2);
expect(document.activeElement === this.view.$('.forum-response')[0]);
}); });
}); });
describe('response count and pagination', function() { describe('response count and pagination', function() {
......
...@@ -53,6 +53,13 @@ ...@@ -53,6 +53,13 @@
return checkCommentForm(false); return checkCommentForm(false);
}); });
}); });
describe('submitComment', function() {
it('focus should be in response container after a new comment is posted', function() {
this.view.render();
expect(this.view.$('.comments')).toBeVisible();
expect(document.activeElement === this.view.$('.forum-response')[0]);
});
});
describe('renderComments', function() { describe('renderComments', function() {
it('hides "show comments" link if collapseComments is not set', function() { it('hides "show comments" link if collapseComments is not set', function() {
this.view.render(); this.view.render();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<label class="field-label"> <label class="field-label">
<span class="field-label-text"><%- gettext("Title") %></span> <span class="field-label-text"><%- gettext("Title") %></span>
<div class="field-help" id="field_help_title"> <div class="field-help" id="field_help_title">
<%- gettext("Add a clear and descriptive title to encourage participation.") %> <%- gettext("Add a clear and descriptive title to encourage participation. (Required)") %>
</div> </div>
<input aria-describedby="field_help_title" type="text" class="edit-post-title field-input" name="title" value="<%- title %>"> <input aria-describedby="field_help_title" type="text" class="edit-post-title field-input" name="title" value="<%- title %>">
</label> </label>
......
...@@ -44,16 +44,13 @@ ...@@ -44,16 +44,13 @@
@include border-radius(0, 0, $forum-border-radius, $forum-border-radius); @include border-radius(0, 0, $forum-border-radius, $forum-border-radius);
box-sizing: border-box; box-sizing: border-box;
border: 1px solid $forum-color-border; border: 1px solid $forum-color-border;
border-top: none;
width: 100%; width: 100%;
background: $forum-color-background-light; background: $forum-color-background-light;
box-shadow: 0 1px 3px $shadow-l1 inset;
} }
@mixin discussion-new-post-wmd-preview-container { @mixin discussion-new-post-wmd-preview-container {
@include discussion-wmd-preview-container; @include discussion-wmd-preview-container;
border-color: $forum-color-border; border-color: $forum-color-border;
box-shadow: 0 1px 3px $shadow-d1 inset;
} }
@mixin discussion-wmd-preview-label { @mixin discussion-wmd-preview-label {
......
...@@ -22,6 +22,11 @@ ...@@ -22,6 +22,11 @@
.wmd-preview-container { .wmd-preview-container {
@include discussion-new-post-wmd-preview-container; @include discussion-new-post-wmd-preview-container;
.discussion-board &,
.discussion-user-profile-board & {
margin-top: -($baseline / 4);
}
} }
.wmd-preview-label { .wmd-preview-label {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment