From c0e6ca12e83e27b2ef86a58f9a44c0248e711a75 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 21 Mar 2015 00:50:52 +0100 Subject: implement clientside search code --- js/directive/NewsSearch.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 js/directive/NewsSearch.js (limited to 'js/directive') diff --git a/js/directive/NewsSearch.js b/js/directive/NewsSearch.js new file mode 100644 index 000000000..f09375c27 --- /dev/null +++ b/js/directive/NewsSearch.js @@ -0,0 +1,35 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsSearch', function ($timeout) { + 'use strict'; + + var timer; + + return { + restrict: 'E', + scope: { + 'onSearch': '=' + }, + link: function (scope) { + $('#searchbox').on('search keyup', function () { + var value = $(this).val(); + if (timer) { + $timeout.cancel(timer); + } + + timer = $timeout(function () { + scope.$apply(function () { + scope.onSearch(value); + }); + }, 500); + }); + } + }; +}); \ No newline at end of file -- cgit v1.2.3