forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix oppia#4936: The dropdown menus work similar to what the about and…
… profile dropdown behave with the keyboard. (oppia#5974) * oppia#4936 adds tab and shift-tab navigation feature * section now closes when opened with mouseclick * Removed unwanted functions * Fixed function issues - added necessary functions * Added Service * Added service to top-navigation-bar * Added NavigationService to aboutMenu * fixed linting errors * removed spaces * removed comments * made rootScope accessible in html * removed use of rootScope * resolved merge conflict * fixed pattern errors * changed fileoverview
- Loading branch information
1 parent
ff94f82
commit 618344f
Showing
6 changed files
with
172 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Factory for navigating the top navigation bar with | ||
* tab and shift-tab. | ||
*/ | ||
oppia.factory('NavigationService', [function(){ | ||
var navigation = {}; | ||
navigation.activeMenuName = ''; | ||
navigation.ACTION_OPEN = 'open'; | ||
navigation.ACTION_CLOSE = 'close'; | ||
navigation.KEYBOARD_EVENT_TO_KEY_CODES = { | ||
enter: { | ||
shiftKeyIsPressed: false, | ||
keyCode: 13 | ||
}, | ||
tab: { | ||
shiftKeyIsPressed: false, | ||
keyCode: 9 | ||
}, | ||
shiftTab: { | ||
shiftKeyIsPressed: true, | ||
keyCode: 9 | ||
} | ||
}; | ||
/** | ||
* Opens the submenu. | ||
* @param {object} evt | ||
* @param {String} menuName - name of menu, on which | ||
* open/close action to be performed (category,language). | ||
*/ | ||
navigation.openSubmenu = function(evt, menuName) { | ||
// Focus on the current target before opening its submenu. | ||
navigation.activeMenuName = menuName; | ||
angular.element(evt.currentTarget).focus(); | ||
}; | ||
navigation.closeSubmenu = function(evt) { | ||
navigation.activeMenuName = ''; | ||
angular.element(evt.currentTarget).closest('li') | ||
.find('a').blur(); | ||
}; | ||
/** | ||
* Handles keydown events on menus. | ||
* @param {object} evt | ||
* @param {String} menuName - name of menu to perform action | ||
* on(category/language) | ||
* @param {object} eventsTobeHandled - Map keyboard events('Enter') to | ||
* corresponding actions to be performed(open/close). | ||
* | ||
* @example | ||
* onMenuKeypress($event, 'category', {enter: 'open'}) | ||
*/ | ||
navigation.onMenuKeypress = function(evt, menuName, eventsTobeHandled) { | ||
var targetEvents = Object.keys(eventsTobeHandled); | ||
for (var i = 0; i < targetEvents.length; i++) { | ||
var keyCodeSpec = | ||
navigation.KEYBOARD_EVENT_TO_KEY_CODES[targetEvents[i]]; | ||
if (keyCodeSpec.keyCode === evt.keyCode && | ||
evt.shiftKey === keyCodeSpec.shiftKeyIsPressed) { | ||
if (eventsTobeHandled[targetEvents[i]] === navigation.ACTION_OPEN) { | ||
navigation.openSubmenu(evt, menuName); | ||
} else if (eventsTobeHandled[targetEvents[i]] === | ||
navigation.ACTION_CLOSE) { | ||
navigation.closeSubmenu(evt); | ||
} else { | ||
throw Error('Invalid action type.'); | ||
} | ||
} | ||
} | ||
}; | ||
return navigation; | ||
}]); |