razorjack/quicksand — Issue #73: Newbie Issu
Author: deflan
Created: 2011-11-20 12:06:27+00:00
State: open

Hello,

I'm tring since few days to implement quicksand but i've got a javascript error:

Uncaught TypeError: Cannot read property 'style' of undefined (jquery.quicksand.js:285)

Here is my code:

Sort by

Name
Year

Le Marquis
2011

De l'huile sur le feu
1232

Javascript Side:
// Custom sorting plugin
(function($) {
$.fn.sorted = function(customOptions) {
var options = {
reversed: false,
by: function(a) { return a.text(); }
};
$.extend(options, customOptions);
$data = $(this);
arr = $data.get();
arr.sort(function(a, b) {
var valA = options.by($(a));
var valB = options.by($(b));
if (options.reversed) {
return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;
} else {
return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;
}
});
return $(arr);
};
})(jQuery);

// DOMContentLoaded
$(function() {
var $filterSort = $('#filter input[name="sort"]');

// get the first collection
var $elms = $('.elm_wrapper');

var $data = $elms.clone();
var $filtereddata = $data.find('li');

// if sorted by year
if ($('.filter input[name="sort"]:checked').val() == "year") {
var $sortedData = $filtereddata.sorted({
by: function(v) {
return parseFloat($(v).find('span[data-type="year"]').text());
}
});
} else {
// if sorted by name
var $sortedData = $filtereddata.sorted({
by: function(v) {
return $(v).find('span[data-type="name"]').text().toLowerCase();
}
});
}
$elms.quicksand($sortedData, {
duration: 800,
easing: 'easeInOutQuad'
});
});

Thank you for your help!