Skip to content

Commit

Permalink
collection now supports multiple elements from being duplicated on sh…
Browse files Browse the repository at this point in the history
…ow and whitespace
  • Loading branch information
databyte committed Jun 14, 2010
1 parent 5374b63 commit 007c45f
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions jquery.quicksand.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ Github site: http://github.com/razorjack/quicksand
} else if (typeof(arguments[2] == 'function')) {
var callbackFunction = arguments[2];
}


return this.each(function (i) {
var val;
var animationQueue = []; // used to store all the animation params before starting the animation; solves initial animation slowdowns
var $collection = $(collection).clone(); // destination (target) collection
var $collection = $(collection).filter('[' + options.attribute + ']').clone(); // destination (target) collection
var $sourceParent = $(this); // source, the visible container of source collection
var sourceHeight = $(this).css('height'); // used to keep height and document flow during the animation

Expand All @@ -64,7 +63,7 @@ Github site: http://github.com/razorjack/quicksand
$sourceParent.html('').append($collection);
return;
}

// Gets called when any animation is finished
var postCallbackPerformed = 0; // prevents the function from being called more than one time
var postCallback = function () {
Expand All @@ -86,7 +85,7 @@ Github site: http://github.com/razorjack/quicksand
var correctionOffset = $correctionParent.offset();
if ($correctionParent.css('position') == 'relative') {
if ($correctionParent.get(0).nodeName.toLowerCase() == 'body') {

} else {
correctionOffset.top += parseFloat($correctionParent.css('border-top-width'));
correctionOffset.left += parseFloat($correctionParent.css('border-left-width'));
Expand All @@ -108,7 +107,7 @@ Github site: http://github.com/razorjack/quicksand

correctionOffset.left -= options.dx;
correctionOffset.top -= options.dy;

// keeps nodes after source container, holding their position
$sourceParent.css('height', $(this).height());

Expand All @@ -130,14 +129,14 @@ Github site: http://github.com/razorjack/quicksand
dx = options.dx;
dy = options.dy;
}

rawObj.style.position = 'absolute';
rawObj.style.margin = '0';

rawObj.style.top = (offsets[i].top - parseFloat(rawObj.style.marginTop) - correctionOffset.top + dy) + 'px';
rawObj.style.left = (offsets[i].left - parseFloat(rawObj.style.marginLeft) - correctionOffset.left + dx) + 'px';
});

// create temporary container with destination collection
var $dest = $($sourceParent).clone();
var rawDest = $dest.get(0);
Expand All @@ -160,10 +159,6 @@ Github site: http://github.com/razorjack/quicksand
rawDest.style.top = offset.top - correctionOffset.top + 'px';
rawDest.style.left = offset.left - correctionOffset.left + 'px';





if (options.adjustHeight === 'dynamic') {
// If destination container has different height than source container
// the height can be animated, adjusting it to destination height
Expand All @@ -178,7 +173,7 @@ Github site: http://github.com/razorjack/quicksand
adjustHeightOnCallback = true;
}
}

// Now it's time to do shuffling animation
// First of all, we need to identify same elements within source and destination collections
$source.each(function (i) {
Expand Down Expand Up @@ -208,7 +203,6 @@ Github site: http://github.com/razorjack/quicksand
opacity: 1.0
}
});

} else {
animationQueue.push({
element: $(this),
Expand All @@ -218,7 +212,6 @@ Github site: http://github.com/razorjack/quicksand
scale: '1.0'
}
});

}
} else {
// The item from source collection is not present in destination collections
Expand All @@ -245,8 +238,8 @@ Github site: http://github.com/razorjack/quicksand
sourceElement = $(this);
return false;
}
});

});
$collection.each(function() {
if (options.attribute(this) == val) {
destElement = $(this);
Expand All @@ -259,7 +252,7 @@ Github site: http://github.com/razorjack/quicksand
}

var animationOptions;
if (sourceElement.length === 0) {
if (sourceElement.length === 0 && destElement.length > 0) {
// No such element in source collection...
if (!options.useScaling) {
animationOptions = {
Expand Down Expand Up @@ -296,4 +289,4 @@ Github site: http://github.com/razorjack/quicksand
}
});
};
})(jQuery);
})(jQuery);

0 comments on commit 007c45f

Please sign in to comment.