Created
June 5, 2014 12:55
-
-
Save msmithstubbs/06797ebb3062d410b0a1 to your computer and use it in GitHub Desktop.
Back In Stock form for Shopify React theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <style> | |
| #BIS_form { margin-top: 20px; } | |
| #BIS_form .btn { height: 34px; line-height: 34px; } | |
| .BIS_response { min-height: 1em; } | |
| </style> | |
| <form id="BIS_form" class="clearfix" data-first-variant="{{product.variants.first.id}}" id="BIS_form" onsubmit="return BISCreateNotification{{product.id}}(this); return false;" {% if product.available %}style="display:none"{% endif %}> | |
| <p><strong>Notify me when this product is available</strong></p> | |
| <p> | |
| <input type="email" class="text" name="email"> | |
| <input type="submit" class="btn" value="Notify Me"> | |
| </p> | |
| <p class="BIS_response"></p> | |
| </form> | |
| <script> | |
| $(function() { | |
| var BISNotificationCallback = function(data) { | |
| var msg = ''; | |
| if (data.status == 'OK') { | |
| msg = data.message; // just show the success message | |
| } else { // it was an error | |
| for (var k in data.errors) { // collect all the error messages into a string | |
| msg += data.errors[k].join(); | |
| } | |
| } | |
| $('#BIS_form .BIS_response').text(msg); | |
| }; | |
| var BISCreateNotification{{product.id}} = function(form) { | |
| var email = $(form).find("[name=email]").val(), | |
| variantId = $('[name=id]').val() || $(form).attr('data-first-variant'); | |
| BISPopover.create(email, variantId).then(BISNotificationCallback); | |
| return false; | |
| }; | |
| var clearBISResponse = function() { | |
| $('#BIS_form .BIS_response').html(' '); | |
| }; | |
| $(function() { | |
| $('#BIS_form input').bind('focus change', clearBISResponse); | |
| $('.product_form select').bind('change', clearBISResponse); | |
| }); | |
| var _originalSelectCallback = selectCallback; | |
| window.selectCallback = function(variant) { | |
| BISPopover.variantIsUnavailable(variant) ? $('#BIS_form').show() : $('#BIS_form').hide(); | |
| _originalSelectCallback.apply(null, arguments); | |
| }; | |
| window.BISCreateNotification{{product.id}} = BISCreateNotification{{product.id}}; | |
| }); | |
| </script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation instructions
{% include 'back-in-stock' %}after the closing</form>around line 100