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

Commit

Permalink
chore(ngdocs): allow user to press escape key to close docs search
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko authored and mhevery committed Jun 18, 2013
1 parent 0cac872 commit cec4ce2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,14 @@
<li class="divider-vertical"></li>
</ul>
<form class="navbar-search pull-right" ng-submit="submit()">
<input type="text" name="as_q" class="search-query" placeholder="Search" ng-change="search(q)" ng-model="q" autocomplete="off">
<input type="hidden" name="as_sitesearch" value="angularjs.org">
<input type="text"
name="as_q"
class="search-query"
placeholder="Search"
ng-change="search(q)"
ng-model="q"
docs-search-input
autocomplete="off" />
</form>
<div ng-show="hasResults" class="search-results">
<a href="" ng-click="hideResults()" class="search-close">
Expand Down
15 changes: 15 additions & 0 deletions docs/src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ docsApp.directive.focused = function($timeout) {
};
};

docsApp.directive.docsSearchInput = function() {
return function(scope, element, attrs) {
var ESCAPE_KEY_KEYCODE = 27;
element.bind('keydown', function(event) {
if(event.keyCode == ESCAPE_KEY_KEYCODE) {
event.stopPropagation();
event.preventDefault();
scope.$apply(function() {
scope.hideResults();
});
}
});
};
};


docsApp.directive.code = function() {
return { restrict:'E', terminal: true };
Expand Down

0 comments on commit cec4ce2

Please sign in to comment.