-
Notifications
You must be signed in to change notification settings - Fork 492
Add events to notify of drawer opening / closing #481
Conversation
I agree this is a great approach. Are you able to update the docs to include these as well? |
Yes, would be happy to do it. |
I added more triggers and fixed the namespace. I've implemented this in a few projects and it's been working great. Let me know what we can do to push this forward, I'm happy to help with anything needed. Have a beautiful weekend. Peace ;) |
Awesome. This is exactly what I was talking about a little while back. Thanks heaps @humancopy 😃 |
@@ -72,18 +78,23 @@ ShopifyAPI.onError = function(XMLHttpRequest, textStatus) { | |||
- Allow custom error callback | |||
==============================================================================*/ | |||
ShopifyAPI.addItemFromForm = function(form, callback, errorCallback) { | |||
var params = { | |||
var $body = $('body'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a nitpick, but can you change this to $(document.body)
- it's slightly faster (source).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, changed it in a couple of other places also ;)
@@ -325,7 +357,7 @@ var ajaxCart = (function(module, $) { | |||
|
|||
cartCallback = function(cart) { | |||
$body.removeClass('drawer--is-loading'); | |||
$body.trigger('ajaxCart.afterCartLoad', cart); | |||
$body.trigger('afterCartLoad.ajaxCart', cart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert this name. It's the only breaking change I can see in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that. I'll update the version number differently instead. All good
jQuery.getJSON('/cart.js', function (cart, textStatus) { | ||
if ((typeof callback) === 'function') { | ||
callback(cart); | ||
} | ||
else { | ||
ShopifyAPI.onCartUpdate(cart); | ||
} | ||
$(document.body).trigger('afterGotCart.ajaxCart', cart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last change, switch this to afterGetCart
. Realizing the naming issues as I'm writing up some new docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, done... Let me know if need any help with docs. :)
@@ -354,6 +386,7 @@ var ajaxCart = (function(module, $) { | |||
|
|||
// If it has a data-line, update the cart. | |||
// Otherwise, just update the input's number | |||
$body.trigger('adjustCart.ajaxCart', [this, line, qty]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove this. updateQuantity
(the function right after this) calls ShopifyAPI.changeItem
, which already has triggers fired (before/after/error/complete ChangeItem
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateQuantity is not always getting triggered which is why I put this one here
Alright, we're almost there. Let's remove:
|
Removed redundant events. Docs look really good, well done! :) |
Thanks for the updates. Did a bunch of testing and it looks in order. The only duplicate events triggered are Will give the docs a quick review the merge both. Cheers to putting this together. |
Last ask, could you squash the commits down to one. Here are the steps. |
Unfortunately I can't squash because I merged stuff from the Shopify/Timber as I needed to keep it up to date cause I was using it for some projects, sorry. If you have an idea how to resolve this I'm happy to follow... ;) |
No worries, more of a nice to have than anything. |
Hey :)
I think it's a good idea to start using events in Timber instead of callbacks to make it easy to tap into interface changes. I also want to add events to the ajax_cart.js file, what you think?