mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
docs(search): make sure the forward slash doesn't focus on search while on another input element
Closes #5969
This commit is contained in:
parent
ca6b7d0fa2
commit
131410b61b
1 changed files with 13 additions and 5 deletions
|
|
@ -145,11 +145,19 @@ docsApp.directive.docsSearchInput = ['$document',function($document) {
|
|||
var ESCAPE_KEY_KEYCODE = 27,
|
||||
FORWARD_SLASH_KEYCODE = 191;
|
||||
angular.element($document[0].body).bind('keydown', function(event) {
|
||||
var input = element[0];
|
||||
if(event.keyCode == FORWARD_SLASH_KEYCODE && document.activeElement != input) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
input.focus();
|
||||
if(event.keyCode == FORWARD_SLASH_KEYCODE && document.activeElement) {
|
||||
var activeElement = document.activeElement;
|
||||
var activeTagName = activeElement.nodeName.toLowerCase();
|
||||
var hasInputFocus = activeTagName == 'input' || activeTagName == 'select' ||
|
||||
activeTagName == 'option' || activeTagName == 'textarea' ||
|
||||
activeElement.hasAttribute('contenteditable');
|
||||
if(!hasInputFocus) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
var input = element[0];
|
||||
input.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue