aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatias Niemelä2014-01-24 12:29:20 -0500
committerMatias Niemelä2014-01-24 13:02:50 -0500
commit131410b61bfca0c21714c1a9e1b3fdc514e21d3a (patch)
tree40f2ccf56c09a9f7c686dc12776f9d26ea3a85c7
parentca6b7d0fa2e355ebd764230260758cee9a4ebe1e (diff)
downloadangular.js-131410b61bfca0c21714c1a9e1b3fdc514e21d3a.tar.bz2
docs(search): make sure the forward slash doesn't focus on search while on another input element
Closes #5969
-rw-r--r--docs/src/templates/js/docs.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/docs/src/templates/js/docs.js b/docs/src/templates/js/docs.js
index 15041774..587e1565 100644
--- a/docs/src/templates/js/docs.js
+++ b/docs/src/templates/js/docs.js
@@ -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();
+ }
}
});