Pflanzen Versandtermine
'); }; }); (function($) { $.sortByDate = function( elements, order ) { var arr = []; elements.each(function() { var obj = {}, $el = $( this ), time = $el.find( ".shippingDate" ).data('date'), date = new Date( $.trim( time ) ), timestamp = date.getTime(); obj.html = $el[0].outerHTML; obj.time = timestamp; arr.push( obj ); }); var sorted = arr.sort(function( a, b ) { if( order == "ASC" ) { return a.time > b.time; } else { return b.time > a.time; } }); return sorted; }; $(function() { var $content = $( ".product-list" ), $elements = $( ".product-list>li"); var filters = "#filters"; $(filters).change(function (e) { if ($(this).val() == 'newer') { var elements = $.sortByDate( $elements, "DESC" ); var html = ""; for( var i = 0; i < elements.length; ++i ) { html += elements[i].html; } $content[0].innerHTML = html; //$( this ).addClass( "selected" ).siblings().removeClass( "selected" ); return false; }; if ($(this).val() == 'older') { var elements = $.sortByDate( $elements, "ASC" ); var html = ""; for( var i = 0; i < elements.length; ++i ) { html += elements[i].html; } $content[0].innerHTML = html; //$( this ).addClass( "selected" ).siblings().removeClass( "selected" ); return false; }; }); }); })( jQuery ); });