Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cec4ce2

Browse files
matskomhevery
authored andcommitted
chore(ngdocs): allow user to press escape key to close docs search
1 parent 0cac872 commit cec4ce2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

docs/src/templates/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@
173173
<li class="divider-vertical"></li>
174174
</ul>
175175
<form class="navbar-search pull-right" ng-submit="submit()">
176-
<input type="text" name="as_q" class="search-query" placeholder="Search" ng-change="search(q)" ng-model="q" autocomplete="off">
177-
<input type="hidden" name="as_sitesearch" value="angularjs.org">
176+
<input type="text"
177+
name="as_q"
178+
class="search-query"
179+
placeholder="Search"
180+
ng-change="search(q)"
181+
ng-model="q"
182+
docs-search-input
183+
autocomplete="off" />
178184
</form>
179185
<div ng-show="hasResults" class="search-results">
180186
<a href="" ng-click="hideResults()" class="search-close">

docs/src/templates/js/docs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ docsApp.directive.focused = function($timeout) {
138138
};
139139
};
140140

141+
docsApp.directive.docsSearchInput = function() {
142+
return function(scope, element, attrs) {
143+
var ESCAPE_KEY_KEYCODE = 27;
144+
element.bind('keydown', function(event) {
145+
if(event.keyCode == ESCAPE_KEY_KEYCODE) {
146+
event.stopPropagation();
147+
event.preventDefault();
148+
scope.$apply(function() {
149+
scope.hideResults();
150+
});
151+
}
152+
});
153+
};
154+
};
155+
141156

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

0 commit comments

Comments
 (0)