diff --git a/static/directives/new-header-bar.html b/static/directives/new-header-bar.html
index 1b9c88460..f0f11f5f6 100644
--- a/static/directives/new-header-bar.html
+++ b/static/directives/new-header-bar.html
@@ -140,6 +140,7 @@
diff --git a/static/js/app.js b/static/js/app.js
index 92df787a5..1d4486876 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -36,7 +36,7 @@ quayPages.constant('pages', {
});
quayDependencies = ['ngRoute', 'chieffancypants.loadingBar', 'cfp.hotkeys', 'angular-tour', 'restangular', 'angularMoment',
- 'mgcrea.ngStrap', 'ngCookies', 'ngSanitize', 'angular-md5', 'pasvaz.bindonce', 'ansiToHtml',
+ 'mgcrea.ngStrap', 'ngCookies', 'ngSanitize', 'angular-md5', 'pasvaz.bindonce', 'ansiToHtml', 'debounce',
'core-ui', 'core-config-setup', 'quayPages'];
if (window.__config && window.__config.MIXPANEL_KEY) {
diff --git a/static/js/directives/ui/header-bar.js b/static/js/directives/ui/header-bar.js
index b940c7233..e54cc476f 100644
--- a/static/js/directives/ui/header-bar.js
+++ b/static/js/directives/ui/header-bar.js
@@ -47,7 +47,6 @@ angular.module('quay').directive('headerBar', function () {
// Monitor any user changes and place the current user into the scope.
UserService.updateUserIn($scope);
-
$scope.currentPageContext = {};
$rootScope.$watch('currentPage.scope.viewuser', function(u) {
@@ -74,7 +73,7 @@ angular.module('quay').directive('headerBar', function () {
};
ApiService.conductSearch(null, params).then(function(resp) {
- if (!$scope.searchVisible) { return; }
+ if (!$scope.searchVisible || query != $scope.currentSearchQuery) { return; }
$scope.searchResultState = {
'state': resp.results.length ? 'results' : 'no-results',
diff --git a/static/lib/LICENSES b/static/lib/LICENSES
index 35b9bb015..498a26df9 100644
--- a/static/lib/LICENSES
+++ b/static/lib/LICENSES
@@ -21,6 +21,7 @@ pagedown - Permissive
jquery.overscroll - MIT (https://github.com/azoff/overscroll/blob/master/mit.license)
URI.js - MIT (https://github.com/medialize/URI.js)
angular-hotkeys - MIT (https://github.com/chieffancypants/angular-hotkeys/blob/master/LICENSE)
+angular-debounce - MIT (https://github.com/shahata/angular-debounce/blob/master/LICENSE)
Issues:
>>>>> jquery.spotlight - GPLv3 (https://github.com/jameshalsall/jQuery-Spotlight)
\ No newline at end of file
diff --git a/static/lib/angular-debounce.js b/static/lib/angular-debounce.js
new file mode 100644
index 000000000..9a0dfe99e
--- /dev/null
+++ b/static/lib/angular-debounce.js
@@ -0,0 +1,66 @@
+'use strict';
+
+angular.module('debounce', [])
+ .service('debounce', ['$timeout', function ($timeout) {
+ return function (func, wait, immediate) {
+ var timeout, args, context, result;
+ function debounce() {
+ /* jshint validthis:true */
+ context = this;
+ args = arguments;
+ var later = function () {
+ timeout = null;
+ if (!immediate) {
+ result = func.apply(context, args);
+ }
+ };
+ var callNow = immediate && !timeout;
+ if (timeout) {
+ $timeout.cancel(timeout);
+ }
+ timeout = $timeout(later, wait);
+ if (callNow) {
+ result = func.apply(context, args);
+ }
+ return result;
+ }
+ debounce.cancel = function () {
+ $timeout.cancel(timeout);
+ timeout = null;
+ };
+ return debounce;
+ };
+ }])
+ .directive('debounce', ['debounce', '$parse', function (debounce, $parse) {
+ return {
+ require: 'ngModel',
+ priority: 999,
+ link: function ($scope, $element, $attrs, ngModelController) {
+ var debounceDuration = $parse($attrs.debounce)($scope);
+ var immediate = !!$parse($attrs.immediate)($scope);
+ var debouncedValue, pass;
+ var prevRender = ngModelController.$render.bind(ngModelController);
+ var commitSoon = debounce(function (viewValue) {
+ pass = true;
+ ngModelController.$setViewValue(viewValue);
+ pass = false;
+ }, parseInt(debounceDuration, 10), immediate);
+ ngModelController.$render = function () {
+ prevRender();
+ commitSoon.cancel();
+ //we must be first parser for this to work properly,
+ //so we have priority 999 so that we unshift into parsers last
+ debouncedValue = this.$viewValue;
+ };
+ ngModelController.$parsers.unshift(function (value) {
+ if (pass) {
+ debouncedValue = value;
+ return value;
+ } else {
+ commitSoon(ngModelController.$viewValue);
+ return debouncedValue;
+ }
+ });
+ }
+ };
+ }]);