Fixes filter problems.

This commit is contained in:
Lars Jung 2013-07-08 20:25:05 +02:00
parent 48522d8e68
commit 6d3438cb1c
3 changed files with 19 additions and 24 deletions

View file

@ -71,6 +71,7 @@ It profits from these great projects:
* updates jQuery to 1.10.2 * updates jQuery to 1.10.2
* adds `uk` translation by Viktor Matveenko * adds `uk` translation by Viktor Matveenko
### v0.22.1 - *2012-10-16* ### v0.22.1 - *2012-10-16*
* bug fix concerning API requests in PHP mode * bug fix concerning API requests in PHP mode

View file

@ -3,17 +3,16 @@
.topbar-right; .topbar-right;
input { input {
display: none;
border: none; border: none;
font-family: @font-family; font-family: @font-family;
color: @col; color: @col;
background-color: rgba(0,0,0,0); background-color: rgba(0,0,0,0);
width: 100px; width: 30px;
} }
&.current { &.current {
input { input {
display: inline; width: 150px;
} }
} }
} }

View file

@ -1,5 +1,5 @@
modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource'], function (_, $, allsettings, resource) { modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource', 'core/event'], function (_, $, allsettings, resource, event) {
var settings = _.extend({ var settings = _.extend({
enabled: false enabled: false
@ -58,20 +58,24 @@ modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource'], func
sequence = $.map($.trim(sequence).split(/\s+/), function (part) { sequence = $.map($.trim(sequence).split(/\s+/), function (part) {
return _.map(part.split(''), function (char) { return _.map(part.split(''), function (character) {
return escapeRegExp(char); return escapeRegExp(character);
}).join('.*?'); }).join('.*?');
}).join('|'); }).join('|');
return new RegExp(sequence, 'i'); return new RegExp(sequence, 'i');
}, },
update = function () { update = function (focus) {
var val = $input.val(); var val = $input.val();
if (val) { if (focus) {
$input.focus();
}
if (val || focus) {
filter(parseFilterSequence(val)); filter(parseFilterSequence(val));
$filter.addClass('current'); $filter.addClass('current');
} else { } else {
@ -79,6 +83,8 @@ modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource'], func
$filter.removeClass('current'); $filter.removeClass('current');
} }
}, },
updt = function () { update(true); },
updf = function () { update(false); },
init = function () { init = function () {
@ -90,30 +96,19 @@ modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource'], func
$input = $filter.find('input'); $input = $filter.find('input');
$noMatch = $(noMatchTemplate).appendTo('#view'); $noMatch = $(noMatchTemplate).appendTo('#view');
$filter $filter.on('click', updt);
.on('click', function () { $input.on('focus blur keyup', updf);
$input.focus();
});
$input
.on('focus', function () {
$filter.addClass('current');
})
.on('blur keyup', update);
$(document) $(document)
.on('keydown', function (event) { .on('keydown', function (event) {
if (event.which === 27) { if (event.which === 27) {
$input.attr('value','').blur(); $input.val('').blur();
} }
}) })
.on('keypress', function (event) { .on('keypress', updt);
$input.focus(); event.sub('location.changed', updf)
});
}; };
init(); init();