Reputation: 33
Namaste!
My simple issue is that $sortedData becomes undefined in the following code upon execution:
(function($) {
$.fn.shuffle = function (){
var i = this.length, j, temp;
if ( i == 0 ) { return; }
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
};
})(jQuery);
// DOMContentLoaded
$(function() {
// get the first collection
var $cards = $('#cards');
// clone cards to get a second collection
var $data = $cards.clone();
// call Quicksand when button clicked
$('#shuffle').click(function(e) {
// get all the list items
var $filteredData = $data.find('li');
// random sort (shuffling)
var $sortedData = $filteredData.shuffle();
// finally, call quicksand
$cards.quicksand($sortedData, {
duration: 600,
easing: 'easeInOutQuad'
});
});
});
How this is called: I have a button that, when clicked, executes the above code.
I've checked the values in the shuffle function, and prior to the call to the shuffle function, but, when the shuffle function returns, $sortedData is undefined.
The error is probably a noobish one, but, I can't see it.
Thank you for your input!
Upvotes: 2
Views: 207
Reputation: 413702
Your "shuffle" function does not return anything, but you're treating it as if it does. It appears to shuffle in-place.
Upvotes: 3