Return to Snippet

Revision: 54439
at December 24, 2011 02:44 by inreflection7


Updated Code
(function () {
	var lis_bucket = [],
		lis_list = $('li.tab-list-item'),
		list_length = lis_list.length,
		ul = $('.events-content'),
		today = new Date(),
		i = 0;

	for (i = 0; i < list_length; i += 1) {
		lis_bucket[i] = [];
		lis_bucket[i][0] = new Date($(lis_list[i]).attr('data-date'));
		lis_bucket[i][1] = $(lis_list[i]).remove();
	}

	lis_bucket.sort(function (a, b) {
		return a[0] - b[0];
	});

	for (i = 0; i < list_length; i += 1) {
		if (today < lis_bucket[i][0]){
			ul.append(lis_bucket[i][1]);
		}
	}

}());

Revision: 54438
at December 24, 2011 01:56 by inreflection7


Initial Code
(function () {
	var lis_bucket = [],
		lis_list = $('li.tab-list-item'),
		list_length = lis_list.length,
		ul = $('.events-content'),
		i = 0;

	for (i = 0; i < list_length; i += 1) {
		lis_bucket[i] = [];
		lis_bucket[i][0] = $(lis_list[i]).attr('data-date');
		lis_bucket[i][1] = $(lis_list[i]).remove();
	}

	lis_bucket.sort(function (a, b) {
		a = new Date(a[0]);
		b = new Date(b[0]);
		return a - b;
	});

	for (i = 0; i < list_length; i += 1) {
		ul.append(lis_bucket[i][1]);
	}
}());

Initial URL

                                

Initial Description
Sorts a list by its 'data-' attribute. Customization is very easy.

Initial Title
Sort list by data- attribute

Initial Tags
sort, list

Initial Language
JavaScript