Hide article category if no article matches the search

This commit is contained in:
Julius 2013-09-24 21:21:08 +02:00
parent 9f083dd4d0
commit a87ced2646
3 changed files with 30 additions and 5 deletions

View file

@ -45,21 +45,21 @@ var CustomizedList = function(id, options, values) {
var resetSearchButton = h.getByClass(options.resetSearchClass, self.list.listContainer);
$(resetSearchButton).removeClass(options.highlightClass);
}
};
this.searchDelayEnd = function(searchString, columns) {
self.list.search(searchString, columns);
}
};
this.highlightResetButton = function() {
var resetSearchButton = h.getByClass(options.resetSearchClass, self.list.listContainer);
$(resetSearchButton).toggleClass(options.highlightClass, self.list.searched);
}
};
this.resetSearch = function() {
$('.' + options.delayedSearchClass + ', .' + options.searchClass, self.list.listContainer).val('');
self.list.search('');
}
};
init.start(id, options, values);
}

View file

@ -62,6 +62,19 @@ List.prototype.templateEngines.unlist = function(list, settings) {
itemSource = getItemSource(settings.item),
templater = this;
var init = {
start: function(options) {
this.defaults(options);
this.callbacks(options);
},
defaults: function(options) {
options.listHeadingsClass = options.listHeadingsClass || 'list-heading';
},
callbacks: function(options) {
list.on('updated', templater.updateListHeadings);
}
};
function getItemSource(item) {
if (item === undefined) {
var nodes = listSource.childNodes,
@ -143,6 +156,18 @@ List.prototype.templateEngines.unlist = function(list, settings) {
this.clear = function() {
$(listSource.childNodes).addClass('unlisted');
};
this.updateListHeadings = function() {
var headSel = '.' + settings.listHeadingsClass;
$(headSel, listSource).each(function() {
if( $(this).nextUntil(headSel, ':not(.unlisted)').length ) {
$(this).removeClass('unlisted');
}
});
};
init.start(settings);
};
/*******************************************************************************

View file

@ -73,7 +73,7 @@
%th{style: "width:15px;"}= t '.sum'
%tbody.list
- @order.articles_grouped_by_category.each do |category, order_articles|
%tr.no-unlist.article-category
%tr.list-heading.article-category
%td
= category
%i.icon-tag