diff --git a/ckan/public/base/javascript/modules/dashboard.js b/ckan/public/base/javascript/modules/dashboard.js index 4a7b216a20a..27d54700860 100644 --- a/ckan/public/base/javascript/modules/dashboard.js +++ b/ckan/public/base/javascript/modules/dashboard.js @@ -1,33 +1,54 @@ this.ckan.module('dashboard', function ($, _) { - return { + button: null, + popover: null, + searchTimeout: null, initialize: function () { $.proxyAll(this, /_on/); - - var popover = $('#followee-filter .btn') - .on('click', function() { - var $this = $(this); - $this.toggleClass('active'); - if ($this.hasClass('active')) { - setTimeout(function() { - $('input', $this.data('popover').tip()).focus(); - }, 100); - } - return false; - }). + this.button = $('#followee-filter .btn'). + on('click', this._onShowFolloweeDropdown). popover({ placement: 'bottom', title: 'Filter', html: true, content: $('#followee-popover').html() - }). - data('popover').tip().addClass('popover-followee'); - + }); + this.popover = this.button.data('popover').tip().addClass('popover-followee'); if ($('.new', this.el)) { setTimeout(function() { $('.masthead .notifications').removeClass('notifications-important').html('0'); }, 1000); } + }, + _onInitSearch: function() { + var input = $('input', this.popover); + if (!input.hasClass('inited')) { + input. + on('keyup', this._onSearchKeyUp). + addClass('inited'); + } + input.focus(); + }, + _onSearchKeyUp: function() { + clearTimeout(this.searchTimeout); + this.searchTimeout = setTimeout(this._onSearchKeyUpTimeout, 300); + }, + _onSearchKeyUpTimeout: function(e) { + var input = $('input', this.popover); + var q = input.val().toLowerCase(); + if (q) { + $('li', this.popover).hide(); + $('li.everything, [data-search^="' + q + '"]', this.popover).show(); + } else { + $('li', this.popover).show(); + } + }, + _onShowFolloweeDropdown: function() { + this.button.toggleClass('active'); + if (this.button.hasClass('active')) { + setTimeout(this._onInitSearch, 100); + } + return false; } }; }); diff --git a/ckan/templates/user/snippets/followee_dropdown.html b/ckan/templates/user/snippets/followee_dropdown.html index bd359615963..afcb8f896f3 100644 --- a/ckan/templates/user/snippets/followee_dropdown.html +++ b/ckan/templates/user/snippets/followee_dropdown.html @@ -23,14 +23,14 @@ {% if followees %}