diff options
Diffstat (limited to 'js/directive/NewsSearch.js')
-rw-r--r-- | js/directive/NewsSearch.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/js/directive/NewsSearch.js b/js/directive/NewsSearch.js index f09375c27..4005c2db7 100644 --- a/js/directive/NewsSearch.js +++ b/js/directive/NewsSearch.js @@ -7,7 +7,7 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.directive('newsSearch', function ($timeout) { +app.directive('newsSearch', function ($document, $timeout, $location) { 'use strict'; var timer; @@ -18,7 +18,10 @@ app.directive('newsSearch', function ($timeout) { 'onSearch': '=' }, link: function (scope) { - $('#searchbox').on('search keyup', function () { + var box = $('#searchbox'); + box.val($location.search().search); + + box.on('search keyup', function () { var value = $(this).val(); if (timer) { $timeout.cancel(timer); @@ -30,6 +33,17 @@ app.directive('newsSearch', function ($timeout) { }); }, 500); }); + + // carry over search on route change + scope.$watch(function () { + return $location.search(); + }, function (search) { + if (search && search.search) { + box.val(search.search); + } else { + box.val(''); + } + }); } }; });
\ No newline at end of file |