From 92f596e7f44987f645c73cf55efc0357e6fa2ffd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 27 May 2015 01:22:59 +0200 Subject: [PATCH] Added esc support of search box. --- .../app/controllers/navigation.js.coffee | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index d88ee233a..73221a1f7 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -197,7 +197,15 @@ class App.Navigation extends App.Controller @renderResult(result) ) + emptyAndClose = => + @$('#global-search').val('').blur() + @$('.search').removeClass('filled').removeClass('open') + # observer search box + @$('#global-search').bind( 'focusout', (e) => + @$('.search').removeClass('focused') + ) + @$('#global-search').bind( 'focusin', (e) => @$('.search').addClass('focused') @@ -233,6 +241,13 @@ class App.Navigation extends App.Controller # start search @$('#global-search').bind( 'keyup', (e) => + + # close on esc + if e.which == 27 + emptyAndClose() + return + + # on other keys, show result term = @$('#global-search').val().trim() return if !term return if term is @term @@ -245,8 +260,7 @@ class App.Navigation extends App.Controller @$('.empty-search').on( 'click' => - @$('#global-search').val('') - @$('.search').removeClass('filled') + emptyAndClose() ) new App.OnlineNotificationWidget(