Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #62 from Shopify/ajax-cart-image-load
Browse files Browse the repository at this point in the history
Wait for images to load before resizing cart drawer and fix quantity/remove animations in ajax cart
  • Loading branch information
cshold committed May 5, 2014
2 parents 7c73120 + bb5770d commit dab87e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
32 changes: 17 additions & 15 deletions assets/ajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ var ajaxifyShopify = (function(module, $) {
var $formContainer, $btnClass, $wrapperClass, $addToCart, $flipClose, $flipCart, $flipContainer, $cartCountSelector, $cartCostSelector, $toggleCartButton, $modal, $cartContainer, $drawerCaret, $modalContainer, $modalOverlay, $closeCart, $drawerContainer;

// Private functions
var updateCountPrice, flipSetup, revertFlipButton, modalSetup, showModal, hideModal, closeModalButton, drawerSetup, showDrawer, hideDrawer, sizeDrawer, formOverride, itemAddedCallback, itemErrorCallback, cartUpdateCallback, setToggleButtons, flipCartUpdateCallback, buildCart, cartTemplate, adjustCart, adjustCartCallback, createQtySelectors, qtySelectors, scrollTop, isEmpty, log;
var updateCountPrice, flipSetup, revertFlipButton, modalSetup, showModal, hideModal, closeModalButton, drawerSetup, showDrawer, hideDrawer, sizeDrawer, loadDrawerImages, formOverride, itemAddedCallback, itemErrorCallback, cartUpdateCallback, setToggleButtons, flipCartUpdateCallback, buildCart, cartTemplate, adjustCart, adjustCartCallback, createQtySelectors, qtySelectors, scrollTop, isEmpty, log;

/**
* Initialise the plugin and define global options
Expand Down Expand Up @@ -539,6 +539,20 @@ var ajaxifyShopify = (function(module, $) {
}
};

loadDrawerImages = function () {
// Size drawer once all images are loaded
var drawerImages = $('img', $cartContainer),
count = drawerImages.length,
index = 0;

drawerImages.on('load', function() {
index++;
if (index==count) {
sizeDrawer();
}
});
};

formOverride = function () {
$formContainer.submit(function(e) {
e.preventDefault();
Expand Down Expand Up @@ -723,13 +737,7 @@ var ajaxifyShopify = (function(module, $) {
case 'flip':
case 'drawer':
if (cart.item_count > 0) {
sizeDrawer();

// Since the template might use larger images, resize again.
// ** Will work on a better solution to image loading here soon. **
setTimeout(function() {
sizeDrawer();
}, 1000);
loadDrawerImages();
} else {
sizeDrawer(true);
}
Expand Down Expand Up @@ -757,13 +765,7 @@ var ajaxifyShopify = (function(module, $) {
case 'flip':
case 'drawer':
if (cart.item_count > 0) {
sizeDrawer();

// Since your /cart template might use larger images, resize again.
// ** Will work on a better solution to image loading here soon. **
setTimeout(function() {
sizeDrawer();
}, 1000);
loadDrawerImages();
} else {
sizeDrawer(true);
}
Expand Down
12 changes: 8 additions & 4 deletions assets/ajaxify.scss.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,19 @@ form[action^="/cart/add"] {

.ajaxifyCart--product {
position: relative;
@include transform-origin(top);
@include transition(all 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95));
@include rotateX(0deg);
max-height: 200px;
padding: 10px 0;

&:first-child {
padding-top: 0;
}
}

.ajaxifyCart--product,
.cart-row {
@include transform-origin(top);
@include transition(all 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95));
@include rotateX(0deg);
max-height: 500px;

&.is-removed {
overflow: hidden;
Expand Down
2 changes: 1 addition & 1 deletion templates/cart.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
Loop through products in the cart
{% endcomment %}
{% for item in cart.items %}
<div class="cart-row" data-id="{{ item.product.id }}">
<div class="cart-row" data-id="{{ item.id }}">
<div class="grid">

{% comment %}
Expand Down

0 comments on commit dab87e7

Please sign in to comment.