Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(ngdocs): add forward slash shortcut key for search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed Oct 23, 2013
1 parent 6c20ec1 commit 7491280
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@
autocomplete="off" />
</form>
<div ng-show="hasResults" class="search-results">
<a href="" ng-click="hideResults()" class="search-close">
<span class="icon-remove-sign"></span>
</a>
<div ng-repeat="(key, value) in results" class="search-group" ng-class="colClassName">
<h4>{{ key }}</h4>
<div ng-repeat="item in value" class="search-result">
<a ng-click="hideResults()" href="{{ item.url }}">{{ item.shortName }}</a>
</div>
</div>
<a href="" ng-click="hideResults()" class="search-close">
<span class="icon-remove-sign"></span>
</a>
</div>
</div>
</div>
Expand Down
16 changes: 13 additions & 3 deletions docs/src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,19 @@ docsApp.directive.focused = function($timeout) {
};
};

docsApp.directive.docsSearchInput = function() {
docsApp.directive.docsSearchInput = ['$document',function($document) {
return function(scope, element, attrs) {
var ESCAPE_KEY_KEYCODE = 27;
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) {

This comment has been minimized.

Copy link
@gmarketer

gmarketer Nov 11, 2013

Here, you should check that the cursor is not on the active input field. Otherwise, you will not be able to enter the forward slash in any input field on that page.

event.stopPropagation();
event.preventDefault();
input.focus();
}
});

element.bind('keydown', function(event) {
if(event.keyCode == ESCAPE_KEY_KEYCODE) {
event.stopPropagation();
Expand All @@ -145,7 +155,7 @@ docsApp.directive.docsSearchInput = function() {
}
});
};
};
}];


docsApp.directive.code = function() {
Expand Down

0 comments on commit 7491280

Please sign in to comment.