Clean up sort functionality; Remove title attributes due to hard I18n
This commit is contained in:
parent
b5acd9b116
commit
a9938df443
1 changed files with 13 additions and 25 deletions
|
@ -143,36 +143,24 @@ $(function() {
|
||||||
$('.datepicker').datepicker({format: 'yyyy-mm-dd', weekStart: 1, language: 'de'});
|
$('.datepicker').datepicker({format: 'yyyy-mm-dd', weekStart: 1, language: 'de'});
|
||||||
|
|
||||||
// Init table sorting
|
// Init table sorting
|
||||||
var myBars = $('span.sorter-bar');
|
var myBars = $('.sorter-bar');
|
||||||
myBars.html('<button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-up"></i></button><button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-down"></i></button>');
|
myBars.html('<button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-up"></i></button><button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-down"></i></button>');
|
||||||
$('button:nth-child(1)', myBars).click(function(e) {sortTable(e, false);}).attr('title', 'Sortiere aufsteigend');
|
$('button:nth-child(1)', myBars).click(function(e) {sortTable(e, false);});
|
||||||
$('button:nth-child(2)', myBars).click(function(e) {sortTable(e, true);}).attr('title', 'Sortiere absteigend (umgekehrt)');
|
$('button:nth-child(2)', myBars).click(function(e) {sortTable(e, true);});
|
||||||
|
// A title attribute ('sort ascending order') would be nice here.
|
||||||
|
// However, for a tiny detail like that it is not worth to translate everything:
|
||||||
|
// http://foodsoft.51229.x6.nabble.com/How-to-I18n-content-which-is-dynamically-loaded-via-javascript-assets-td75.html#a76
|
||||||
|
|
||||||
$('span.sorter-bar.default-sort-asc button:nth-child(1)').trigger('click');
|
// Sort tables with a default sort
|
||||||
$('span.sorter-bar.default-sort-desc button:nth-child(2)').trigger('click');
|
$('.sorter-bar.default-sort-asc button:nth-child(1)').trigger('click');
|
||||||
|
$('.sorter-bar.default-sort-desc button:nth-child(2)').trigger('click');
|
||||||
});
|
});
|
||||||
|
|
||||||
// parse a string to a float
|
|
||||||
function myFloatParse(input) {
|
|
||||||
var number = input.trim();
|
|
||||||
number = number.split(' ')[0];
|
|
||||||
number = number.replace(',', '.');
|
|
||||||
number = parseFloat(number, 10);
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compare two elements interpreted as text
|
// compare two elements interpreted as text
|
||||||
function compareText(a, b) {
|
function compareText(a, b) {
|
||||||
return $.trim(a.textContent).toLowerCase() < $.trim(b.textContent).toLowerCase() ? -1 : 1;
|
return $.trim(a.textContent).toLowerCase() < $.trim(b.textContent).toLowerCase() ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare two elements interpreted as float
|
|
||||||
function compareFloat(a, b) {
|
|
||||||
a = myFloatParse( $(a).text() );
|
|
||||||
b = myFloatParse( $(b).text() );
|
|
||||||
return ( a<b ) ? ( -1 ) : ( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// wrapper for $.fn.sorter (see above) for sorting tables
|
// wrapper for $.fn.sorter (see above) for sorting tables
|
||||||
function sortTable(e, inverted) {
|
function sortTable(e, inverted) {
|
||||||
var sign = ( inverted ) ? ( -1 ) : ( 1 );
|
var sign = ( inverted ) ? ( -1 ) : ( 1 );
|
||||||
|
@ -196,9 +184,9 @@ function sortTable(e, inverted) {
|
||||||
$(e.currentTarget).addClass('btn-primary active');
|
$(e.currentTarget).addClass('btn-primary active');
|
||||||
}
|
}
|
||||||
|
|
||||||
// resort a certain table (e.g. after DOM update)
|
// retrigger last sort function for elements in a context (e.g. after DOM update)
|
||||||
function updateSort(whichTable) {
|
function updateSort(context) {
|
||||||
$('.sorter-bar button.active.btn-primary', whichTable).trigger('click');
|
$('.sorter-bar button.active.btn-primary', context).trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
// gives the row an yellow background
|
// gives the row an yellow background
|
||||||
|
|
Loading…
Reference in a new issue