Skip to content

Instantly share code, notes, and snippets.

@kyledurand
Last active August 29, 2015 14:14
Show Gist options
  • Save kyledurand/89a29a129f075326ffa4 to your computer and use it in GitHub Desktop.
Save kyledurand/89a29a129f075326ffa4 to your computer and use it in GitHub Desktop.
Getting scripts to work on ajaxified cart drawers etc...

Getting scripts to work on ajaxified cart drawers etc...

  1. Move your script from wherever it is into theme.liquid
  2. Wrap it in a function
  3. Call the function
  4. Call the function again whenever ajax has loaded something.
  5. See example below. I've used the agree to terms of service snippet.
<script>
var agree = function(){
$('[name="checkout"], input[name="goto_pp"], input[name="goto_gc"]').click(function() {
if($('#agree').is(':checked')){
$(this).submit();
}
else{
alert("You must agree with the terms and conditions of sales to check out.");
return false;
}
});
}
$( document ).ajaxComplete(function() {
agree();
});
agree();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment