Commit a1f0679f by Sofiya Semenova

Educator 1552 - Implement roving tabindex for WYSIWYG editor for discussions

parent f9623fc9
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
DiscussionUtil.wmdEditors = {}; DiscussionUtil.wmdEditors = {};
DiscussionUtil.leftKey = 37;
DiscussionUtil.rightKey = 39;
DiscussionUtil.getTemplate = function(id) { DiscussionUtil.getTemplate = function(id) {
return $('script#' + id).html(); return $('script#' + id).html();
}; };
...@@ -539,6 +542,38 @@ ...@@ -539,6 +542,38 @@
}; };
}; };
DiscussionUtil.handleKeypressInToolbar = function(event) {
var $currentButton, $nextButton, $toolbar, $allButtons,
keyPressed, nextIndex, currentButtonIndex,
validKeyPress, toolbarHasButtons;
$currentButton = $(event.target);
keyPressed = event.which || event.keyCode;
$toolbar = $currentButton.parent();
$allButtons = $toolbar.children('.wmd-button');
validKeyPress = keyPressed === this.leftKey || keyPressed === this.rightKey;
toolbarHasButtons = $allButtons.length > 0;
if (validKeyPress && toolbarHasButtons) {
currentButtonIndex = $allButtons.index($currentButton);
nextIndex = keyPressed === this.leftKey ? currentButtonIndex - 1 : currentButtonIndex + 1;
nextIndex = Math.max(Math.min(nextIndex, $allButtons.length - 1), 0);
$nextButton = $($allButtons[nextIndex]);
this.moveSelectionToNextItem($currentButton, $nextButton);
}
};
DiscussionUtil.moveSelectionToNextItem = function(prevItem, nextItem) {
prevItem.attr('aria-selected', 'false');
prevItem.attr('tabindex', '-1');
nextItem.attr('aria-selected', 'true');
nextItem.attr('tabindex', '0');
nextItem.focus();
};
return DiscussionUtil; return DiscussionUtil;
}).call(this); }).call(this);
}).call(window); }).call(window);
...@@ -62,7 +62,10 @@ ...@@ -62,7 +62,10 @@
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',
'keydown .wmd-button': function(event) {
return DiscussionUtil.handleKeypressInToolbar(event);
}
}; };
DiscussionThreadView.prototype.$ = function(selector) { DiscussionThreadView.prototype.$ = function(selector) {
......
...@@ -137,7 +137,10 @@ ...@@ -137,7 +137,10 @@
'change .post-option-input': 'postOptionChange', 'change .post-option-input': 'postOptionChange',
'click .cancel': 'cancel', 'click .cancel': 'cancel',
'click .add-post-cancel': 'cancel', 'click .add-post-cancel': 'cancel',
'reset .forum-new-post-form': 'updateStyles' 'reset .forum-new-post-form': 'updateStyles',
'keydown .wmd-button': function(event) {
return DiscussionUtil.handleKeypressInToolbar(event);
}
}; };
NewPostView.prototype.toggleGroupDropdown = function($target) { NewPostView.prototype.toggleGroupDropdown = function($target) {
......
...@@ -13,7 +13,7 @@ set -e ...@@ -13,7 +13,7 @@ set -e
# Violations thresholds for failing the build # Violations thresholds for failing the build
export LOWER_PYLINT_THRESHOLD=1000 export LOWER_PYLINT_THRESHOLD=1000
export UPPER_PYLINT_THRESHOLD=5900 export UPPER_PYLINT_THRESHOLD=5900
export ESLINT_THRESHOLD=9134 export ESLINT_THRESHOLD=9543
export STYLELINT_THRESHOLD=973 export STYLELINT_THRESHOLD=973
XSSLINT_THRESHOLDS=`cat scripts/xsslint_thresholds.json` XSSLINT_THRESHOLDS=`cat scripts/xsslint_thresholds.json`
......
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