summaryrefslogtreecommitdiffstats
path: root/js/directive
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-03-21 12:17:35 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-03-21 13:36:50 +0100
commit7b7b0fd5eefddf03a94274f99b8e117c9651166b (patch)
tree27f272bf22cb70a536ca6b6b81764b80aaa19308 /js/directive
parentf6bf8ce402ed43c6a42354e64dda7b3cc081196f (diff)
clear search on route change and fix nav/content
Diffstat (limited to 'js/directive')
-rw-r--r--js/directive/NewsSearch.js18
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