Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

collection now supports multiple elements from being duplicated on sh…

…ow and whitespace
  • Loading branch information...
commit dade1aeee80b007d04826226ce78f4253dea5a73 1 parent 84df2d5
@databyte databyte authored
Showing with 12 additions and 19 deletions.
  1. +12 −19 jquery.quicksand.js
View
31 jquery.quicksand.js
@@ -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
@@ -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 () {
@@ -94,7 +93,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')) || 0);
correctionOffset.left +=( parseFloat($correctionParent.css('border-left-width')) || 0);
@@ -116,7 +115,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());
@@ -138,14 +137,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);
@@ -168,10 +167,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
@@ -186,7 +181,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) {
@@ -216,7 +211,6 @@ Github site: http://github.com/razorjack/quicksand
opacity: 1.0
}
});
-
} else {
animationQueue.push({
element: $(this),
@@ -226,7 +220,6 @@ Github site: http://github.com/razorjack/quicksand
scale: '1.0'
}
});
-
}
} else {
// The item from source collection is not present in destination collections
@@ -253,8 +246,8 @@ Github site: http://github.com/razorjack/quicksand
sourceElement = $(this);
return false;
}
- });
-
+ });
+
$collection.each(function() {
if (options.attribute(this) == val) {
destElement = $(this);
@@ -267,7 +260,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 = {
@@ -304,4 +297,4 @@ Github site: http://github.com/razorjack/quicksand
}
});
};
-})(jQuery);
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.