Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add whitespace preservation for display:inline-block compatibility

  • Loading branch information...
commit fcb668a4eee929b79fbaeb24c4b31db4530c44ea 1 parent 84df2d5
Cameron authored
Showing with 15 additions and 4 deletions.
  1. +15 −4 jquery.quicksand.js
19 jquery.quicksand.js
View
@@ -75,8 +75,10 @@ Github site: http://github.com/razorjack/quicksand
// hack:
// used to be: $sourceParent.html($dest.html()); // put target HTML into visible source container
// but new webkit builds cause flickering when replacing the collections
- $toDelete = $sourceParent.find('> *');
- $sourceParent.prepend($dest.find('> *'));
+ // Switch from .find('> *') to .contents() to conserve whitespace nodes if they are present, for
+ // inline-block whitespace continuity and to clean up previous whitespace
+ $toDelete = $sourceParent.contents();
+ $sourceParent.prepend($dest.contents());
$toDelete.remove();
if (adjustHeightOnCallback) {
@@ -153,7 +155,16 @@ Github site: http://github.com/razorjack/quicksand
rawDest.setAttribute('id', '');
rawDest.style.height = 'auto';
rawDest.style.width = $sourceParent.width() + 'px';
- $dest.append($collection);
+ $dest.append($collection);
+ // Detect whitespace nodes in sourceParent.contents(), if present add whitespace to $dest (display: inline-block compatibility)
+ var whitespacecount = 0;
+ jQuery.each($sourceParent.contents(), function(i, value) {
+ if (value && value.nodeType == 3) whitespacecount += 1;
+ });
+ console.log(whitespacecount);
+ if (whitespacecount > 0) {
+ $dest.children().after(' ');
+ }
// insert node into HTML
// Note that the node is under visible source container in the exactly same position
// The browser render all the items without showing them (opacity: 0.0)
@@ -304,4 +315,4 @@ Github site: http://github.com/razorjack/quicksand
}
});
};
-})(jQuery);
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.